influxdb: Use a flag file for the first init

This commit is contained in:
Daniel Frank 2022-01-25 20:58:35 +01:00
parent c8467650a0
commit 4b555b87ab
Signed by: tokudan
GPG key ID: 063CCCAD04182D32

View file

@ -44,10 +44,12 @@
IPAddressAllow = "localhost"; IPAddressAllow = "localhost";
UMask = "077"; UMask = "077";
RuntimeDirectory = "influxdb"; RuntimeDirectory = "influxdb";
ExecStartPre = [ (pkgs.writeShellScript "influxdb-first-run" ''
[ -d /var/lib/influxdb/meta ] || touch /var/lib/influxdb/need-init
'') ];
ExecStartPost = lib.mkForce [ (pkgs.writeShellScript "influxdb-first-run" '' ExecStartPost = lib.mkForce [ (pkgs.writeShellScript "influxdb-first-run" ''
set -euo pipefail set -euo pipefail
if [ ! -s /var/lib/influxdb/admin.pw ]; then if [ ! -s /var/lib/influxdb/admin.pw ]; then
INIT=1
( tr -dc _A-Z-a-z-0-9 </dev/urandom || : ) | head -c32 > /var/lib/influxdb/admin.pw ( tr -dc _A-Z-a-z-0-9 </dev/urandom || : ) | head -c32 > /var/lib/influxdb/admin.pw
chmod 400 /var/lib/influxdb/admin.pw chmod 400 /var/lib/influxdb/admin.pw
fi fi
@ -62,7 +64,8 @@
until ${pkgs.curl}/bin/curl --connect-timeout 1 http://127.0.0.1:8086/ping; do until ${pkgs.curl}/bin/curl --connect-timeout 1 http://127.0.0.1:8086/ping; do
sleep 1 sleep 1
done done
if [ -v INIT ]; then if [ -e /var/lib/influxdb/need-init ]; then
rm -f /var/lib/influxdb/need-init
read -N 32 -r adminpw < /var/lib/influxdb/admin.pw read -N 32 -r adminpw < /var/lib/influxdb/admin.pw
read -N 32 -r knotendatenpw < /var/lib/influxdb/knotendaten.pw read -N 32 -r knotendatenpw < /var/lib/influxdb/knotendaten.pw
read -N 32 -r grafanapw < /var/lib/influxdb/grafana.pw read -N 32 -r grafanapw < /var/lib/influxdb/grafana.pw