Skip to content

Commit 24d4e53

Browse files
committed
wip
1 parent 9d6ffc3 commit 24d4e53

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

modules/healthcheck/default.nix

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
serviceConfig.TimeoutStartSec = lib.mkForce "infinity";
112112

113113
# We add a ExecStartPost with a script that runs the readiness probe
114-
serviceConfig.ExecStartPost =
114+
serviceConfig.ExecStartPre =
115115
let
116116
scriptPath = lib.makeBinPath (
117117
[
@@ -126,29 +126,34 @@
126126
pkgs.writeShellScript "${mainServiceName}-readiness-check" ''
127127
#!${pkgs.runtimeShell}
128128
set -o nounset
129-
export PATH="${scriptPath}:$PATH"
130-
131-
echo "Health check: starting background readiness probe for ${mainServiceName}."
132-
sleep ${toString probeCfg.initialDelay}
133-
retryCount=${toString probeCfg.retryCount}
134-
while true; do
135-
if (timeout ${toString probeCfg.timeout}s ${probeCfg.command} &> /dev/null); then
136-
echo "Health check: probe successful. Notifying systemd that the service is ready."
137-
systemd-notify --ready --status="${probeCfg.statusReadyMessage}"
138-
exit 0
139-
else
140-
echo "Health check: probe not successful. Notifying systemd that the service is still waiting. Retrying in ${toString probeCfg.interval} seconds..."
141-
systemd-notify --status="${probeCfg.statusWaitingMessage}"
142-
if [[ ''${retryCount} -ne -1 ]]; then
143-
retryCount=$((retryCount - 1))
144-
if [[ ''${retryCount} -le 0 ]]; then
145-
echo "Health check: probe failed after maximum retries. Exiting."
146-
exit 1
129+
130+
monitor() {
131+
export PATH="${scriptPath}:$PATH"
132+
133+
echo "Health check: starting background readiness probe for ${mainServiceName}." 1>>/tmp/banica1 2>>/tmp/banica2
134+
sleep ${toString probeCfg.initialDelay}
135+
retryCount=${toString probeCfg.retryCount}
136+
while true; do
137+
if (timeout ${toString probeCfg.timeout}s ${probeCfg.command} &> /dev/null); then
138+
echo "Health check: probe successful. Notifying systemd that the service is ready." 1>>/tmp/banica1 2>>/tmp/banica2
139+
systemd-notify --ready --status="${probeCfg.statusReadyMessage}" 1>>/tmp/banica1 2>>/tmp/banica2
140+
exit 0
141+
else
142+
echo "Health check: probe not successful. Notifying systemd that the service is still waiting. Retrying in ${toString probeCfg.interval} seconds..." 1>>/tmp/banica1 2>>/tmp/banica2
143+
systemd-notify --status="${probeCfg.statusWaitingMessage}" 1>>/tmp/banica1 2>>/tmp/banica2
144+
if [[ ''${retryCount} -ne -1 ]]; then
145+
retryCount=$((retryCount - 1))
146+
if [[ ''${retryCount} -le 0 ]]; then
147+
echo "Health check: probe failed after maximum retries. Exiting." 1>>/tmp/banica1 2>>/tmp/banica2
148+
exit 1
149+
fi
147150
fi
148151
fi
149-
fi
150-
sleep ${toString probeCfg.interval}
151-
done
152+
sleep ${toString probeCfg.interval}
153+
done
154+
}
155+
156+
monitor & disown
152157
'';
153158
}
154159
))

0 commit comments

Comments
 (0)