about summary refs log tree commit diff
path: root/bundles/svtree-containers/files/bin/podman-healthcheckd
blob: cdbef0e66ff8baefaca0a0d7ddfb7bba0d7e6f2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 $@