From 40bfbe3226e4a125d321837d7eb2e927159b29ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Wed, 2 Oct 2024 20:49:59 +0200 Subject: [PATCH] nixos/scrutiny: wait until ready Add postStart code that waits until Scrutiny has opened its port. This fixes a race condition against scrutiny-collector, which can start (and fail) before scrutiny is ready. --- nixos/modules/services/monitoring/scrutiny.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nixos/modules/services/monitoring/scrutiny.nix b/nixos/modules/services/monitoring/scrutiny.nix index c0ead07066ec..37a991674dae 100644 --- a/nixos/modules/services/monitoring/scrutiny.nix +++ b/nixos/modules/services/monitoring/scrutiny.nix @@ -177,6 +177,18 @@ in SCRUTINY_WEB_DATABASE_LOCATION = "/var/lib/scrutiny/scrutiny.db"; SCRUTINY_WEB_SRC_FRONTEND_PATH = "${cfg.package}/share/scrutiny"; }; + postStart = '' + for i in $(seq 300); do + if "${lib.getExe pkgs.curl}" --fail --silent --head "http://${cfg.settings.web.listen.host}:${toString cfg.settings.web.listen.port}" >/dev/null; then + echo "Scrutiny is ready (port is open)" + exit 0 + fi + echo "Waiting for Scrutiny to open port..." + sleep 0.2 + done + echo "Timeout waiting for Scrutiny to open port" >&2 + exit 1 + ''; serviceConfig = { DynamicUser = true; ExecStart = "${getExe cfg.package} start --config ${settingsFormat.generate "scrutiny.yaml" cfg.settings}";