about summary refs log tree commit diff
path: root/bundles/svtree-containers/files/bin/podman-healthcheckd
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/svtree-containers/files/bin/podman-healthcheckd')
-rwxr-xr-xbundles/svtree-containers/files/bin/podman-healthcheckd34
1 files changed, 34 insertions, 0 deletions
diff --git a/bundles/svtree-containers/files/bin/podman-healthcheckd b/bundles/svtree-containers/files/bin/podman-healthcheckd
new file mode 100755
index 0000000..cdbef0e
--- /dev/null
+++ b/bundles/svtree-containers/files/bin/podman-healthcheckd
@@ -0,0 +1,34 @@
+#!/bin/sh
+set -eu
+[ -n "${DEBUG:-}" ] && set -x
+
+healthcheck_with_retry() {
+	local container="${1:-}"
+
+	podman inspect --format '{{with .Config.Healthcheck}}{{.StartPeriod}} {{.Timeout}} {{.Retries}}{{end}}' "$container" |
+		(
+			read -r start_period timeout retries
+			test -n "$start_period$timeout$retries" || return
+
+			sleep "$start_period"
+
+			podman-healthcheck "$container" && return
+
+			count=0
+			while [ "$count" -lt "$retries" ]; do
+				sleep "$timeout"
+				podman-healthcheck "$container" && return
+				count=$((count + 1))
+			done
+		)
+
+}
+
+main() {
+	podman events --filter 'type=container' --filter 'event=start' --format '{{.ID}}' |
+		while read -r container; do
+			healthcheck_with_retry "$container" || true
+		done
+}
+
+main $@