about summary refs log tree commit diff
path: root/bundles/svtree-containers/files/bin/podman-healthcheck
blob: ab3dcc779457dd8c5d377029bd6fd57b128d8b8c (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
#!/bin/sh
set -eu
[ -n "${DEBUG:-}" ] && set -x

healthcheck() {
	local container=${1:?}

	podman healthcheck run "$container" >/dev/null 2>&1 || true

	podman inspect --format '{{if .State.Health}}{{.Name}} {{.State.Health.Status}}{{end}}' "$container" | (
		read -r name status

		test -n "$name" || return

		printf '%s (%s) is %s\n' "$container" "$name" "$status"
		case "$status" in
		healthy) ;;
		*)
			# tgnotify "!!! service $container unhealthy"
			;;
		esac
	)
}

main() {
	case "${1:-}" in
	"") podman container ls --format '{{.ID}}' | xargs -n1 $0 ;;
	*) healthcheck "$1" ;;
	esac
}

main $@