@@ -30,27 +30,35 @@ mkdir -p \
3030
3131export 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}
4047vm_httpAuth_password=${httpAuth_password}
41- vm_metricsAuthKey=metrics
48+ vm_metricsAuthKey=${metricsAuthKey}
4249vm_snapshotAuthKey=${snapshotAuthKey}
4350EOT
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
5664set -a
0 commit comments