diff options
| author | Bjørn Forsman <bjorn.forsman@gmail.com> | 2024-09-24 18:20:37 +0200 |
|---|---|---|
| committer | github-actions[bot] <github-actions[bot]@users.noreply.github.com> | 2024-09-26 04:55:37 +0000 |
| commit | ad23b68aa6e4df5e92fa8bb9adcfbcf453c65ab2 (patch) | |
| tree | 0390f4fe1d92c6ddb1a6739f4876b5c8ad923ed1 | |
| parent | [Backport release-24.05] lxc/incus LTS upgrades: 6.0.1 -> 6.0.2 (#344337) (diff) | |
| download | nixpkgs-origin/backport-344246-to-release-24.05.tar.gz | |
nixos/influxdb2: wait until service is readyorigin/backport-344246-to-release-24.05
Factor out part of the provisioning script into a
wait-until-service-is-ready script, and put it unconditionally in
front of ExecStartPost=, so that services that depend on influxdb2 are
not started until influxdb2 responds to requests.
Fixes https://github.com/NixOS/nixpkgs/issues/317017 ("Scrutiny tries to start before influxdb has started")
(cherry picked from commit 732d36522f4426e3f7e839e2694d28bbaead3f72)
| -rw-r--r-- | nixos/modules/services/databases/influxdb2.nix | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/nixos/modules/services/databases/influxdb2.nix b/nixos/modules/services/databases/influxdb2.nix index a534cdfbe165..19234fd82cab 100644 --- a/nixos/modules/services/databases/influxdb2.nix +++ b/nixos/modules/services/databases/influxdb2.nix @@ -67,16 +67,16 @@ let inherit (cfg.provision) organizations users; }); - provisioningScript = pkgs.writeShellScript "post-start-provision" '' - set -euo pipefail - export INFLUX_HOST="http://"${escapeShellArg ( + influxHost = "http://${escapeShellArg ( if ! hasAttr "http-bind-address" cfg.settings || hasInfix "0.0.0.0" cfg.settings.http-bind-address then "localhost:8086" else cfg.settings.http-bind-address - )} + )}"; - # Wait for the influxdb server to come online + waitUntilServiceIsReady = pkgs.writeShellScript "wait-until-service-is-ready" '' + set -euo pipefail + export INFLUX_HOST=${influxHost} count=0 while ! influx ping &>/dev/null; do if [ "$count" -eq 300 ]; then @@ -92,6 +92,11 @@ let sleep 0.1 count=$((count++)) done + ''; + + provisioningScript = pkgs.writeShellScript "post-start-provision" '' + set -euo pipefail + export INFLUX_HOST=${influxHost} # Do the initial database setup. Pass /dev/null as configs-path to # avoid saving the token as the active config. @@ -447,11 +452,13 @@ in "admin-token:${cfg.provision.initialSetup.tokenFile}" ]; - ExecStartPost = mkIf cfg.provision.enable ( + ExecStartPost = [ + waitUntilServiceIsReady + ] ++ (lib.optionals cfg.provision.enable ( [provisioningScript] ++ # Only the restarter runs with elevated privileges optional anyAuthDefined "+${restarterScript}" - ); + )); }; path = [ |
