Skip to content

Commit f1f19b9

Browse files
committed
victoriametrics: improve migration to conf.d
1 parent e74d0f3 commit f1f19b9

2 files changed

Lines changed: 26 additions & 17 deletions

File tree

packages/omd/omd.pre-update

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,17 @@ fi
152152
if [ $OLD_VERSION -le 512 ]; then
153153
grep "do not edit manually" etc/apache/conf.d/victoriametrics.conf >/dev/null 2>&1 && rm -f etc/apache/conf.d/victoriametrics.conf
154154
if [ -e etc/victoriametrics/victoriametrics.conf -a -f $OLD_SKEL/etc/victoriametrics/victoriametrics.conf_template ]; then
155+
mkdir -p etc/victoriametrics/conf.d
155156
rm -f etc/victoriametrics/conf.d/zzz_migrated.conf
156157
echo "migrating etc/victoriametrics/victoriametrics.conf to etc/victoriametrics/conf.d/zzz_migrated.conf"
157158
grep ^vm_ etc/victoriametrics/victoriametrics.conf | grep -v httpAuth | grep -v snapshotAuth | grep -v metricsAuth | \
158159
while read LINE; do
159160
# migrate only if its not the default
160-
if ! grep "$LINE" $OLD_SKEL/etc/victoriametrics/victoriametrics.conf_template > /dev/null 2>&1; then
161+
if ! grep "^$LINE" $OLD_SKEL/etc/victoriametrics/victoriametrics.conf_template > /dev/null 2>&1; then
161162
echo "$LINE" >> etc/victoriametrics/conf.d/zzz_migrated.conf
162163
fi
163164
done
164-
rm -f etc/victoriametrics/victoriametrics.conf
165+
mv etc/victoriametrics/victoriametrics.conf etc/victoriametrics/victoriametrics.conf.migrated.to.conf.d
165166
fi
166167
fi
167168

packages/victoriametrics/skel/etc/init.d/victoriametrics

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,35 @@ mkdir -p \
3030

3131
export LC_ALL=C
3232

33-
# generate random passwords
34-
if [ ! -f ${AUTH_CONF_FILE} ]; then
35-
httpAuth_password=$( tr -cd A-Za-z0-9 < /dev/urandom | head -c 16 )
36-
snapshotAuthKey=$( tr -cd A-Za-z0-9 < /dev/urandom | head -c 16 )
37-
cat << EOT > ${AUTH_CONF_FILE}
33+
case "$1" in start|restart|reload|checkconfig|check)
34+
# generate random passwords
35+
if [ ! -f ${AUTH_CONF_FILE} ]; then
36+
# use existing ones if available
37+
if [ -f etc/victoriametrics/victoriametrics.conf.migrated.to.conf.d ]; then
38+
. etc/victoriametrics/victoriametrics.conf.migrated.to.conf.d
39+
fi
40+
httpAuth_username=${vm_httpAuth_username:-prom}
41+
httpAuth_password=${vm_httpAuth_password:-$( tr -cd A-Za-z0-9 < /dev/urandom | head -c 16 )}
42+
snapshotAuthKey=${vm_snapshotAuthKey:-$( tr -cd A-Za-z0-9 < /dev/urandom | head -c 16 )}
43+
metricsAuthKey=${vm_metricsAuthKey:-metrics}
44+
cat << EOT > ${AUTH_CONF_FILE}
3845
# this file is generated automatically, do not change manually. Changes will be overwritten.
39-
vm_httpAuth_username=prom
46+
vm_httpAuth_username=${httpAuth_username}
4047
vm_httpAuth_password=${httpAuth_password}
41-
vm_metricsAuthKey=metrics
48+
vm_metricsAuthKey=${metricsAuthKey}
4249
vm_snapshotAuthKey=${snapshotAuthKey}
4350
EOT
44-
echo "created ${AUTH_CONF_FILE} with random passwords, for remote access check this file"
45-
46-
if [ -f ${OMD_ROOT}/etc/victoriametrics/grafana_datasources.yml ] ; then
47-
sed -e "s/basicAuthPassword: .*/basicAuthPassword: ${httpAuth_password}/; s/basicAuthUser: .*/basicAuthUser: prom/" -i ${OMD_ROOT}/etc/victoriametrics/grafana_datasources.yml
48-
if omd status grafana > /dev/null 2>&1 ; then
49-
omd restart grafana
51+
echo "created ${AUTH_CONF_FILE} with random passwords, for remote access check this file"
52+
53+
if [ -f ${OMD_ROOT}/etc/victoriametrics/grafana_datasources.yml ] ; then
54+
sed -e "s/basicAuthPassword: .*/basicAuthPassword: ${httpAuth_password}/; s/basicAuthUser: .*/basicAuthUser: prom/" -i ${OMD_ROOT}/etc/victoriametrics/grafana_datasources.yml
55+
if omd status grafana > /dev/null 2>&1 ; then
56+
omd restart grafana
57+
fi
58+
echo "patched password in grafana_datasources.yml"
5059
fi
51-
echo "patched password in grafana_datasources.yml"
5260
fi
53-
fi
61+
esac
5462

5563
# export every parameter that is set after this line
5664
set -a

0 commit comments

Comments
 (0)