2022-12-25 13:40:38 +01:00
|
|
|
#!/bin/sh
|
2023-03-28 11:46:05 +02:00
|
|
|
docker_ps_grep_unhealthy="$(docker ps --filter health=unhealthy --format '{{.Names}}')"
|
2023-12-24 19:19:07 +01:00
|
|
|
docker_ps_grep_exited="$(docker ps --filter status=exited --format '{{.ID}}')"
|
|
|
|
|
2023-01-09 16:51:19 +01:00
|
|
|
exitcode=0
|
2023-12-24 19:19:07 +01:00
|
|
|
|
|
|
|
if [ -n "$docker_ps_grep_unhealthy" ]; then
|
2022-12-25 13:40:38 +01:00
|
|
|
echo "Some docker containers are unhealthy: $docker_ps_grep_unhealthy"
|
2023-01-09 16:51:19 +01:00
|
|
|
exitcode=1
|
|
|
|
fi
|
2023-12-24 19:19:07 +01:00
|
|
|
|
|
|
|
if [ -n "$docker_ps_grep_exited" ]; then
|
|
|
|
for container_id in $docker_ps_grep_exited
|
|
|
|
do
|
|
|
|
container_exit_code="$(docker inspect "$container_id" --format='{{.State.ExitCode}}')"
|
|
|
|
container_name="$(docker inspect "$container_id" --format='{{.Name}}')"
|
|
|
|
container_name="${container_name#/}" # Entfernt das führende '/'
|
|
|
|
if [ "$container_exit_code" -ne "0" ]; then
|
|
|
|
echo "Container $container_name exited with code $container_exit_code"
|
|
|
|
exitcode=2
|
|
|
|
fi
|
|
|
|
done
|
2023-01-09 16:51:19 +01:00
|
|
|
fi
|
2023-12-24 19:19:07 +01:00
|
|
|
|
|
|
|
if [ "$exitcode" -ne "0" ]; then
|
2023-01-09 16:51:19 +01:00
|
|
|
exit $exitcode
|
|
|
|
fi
|
2023-12-24 19:19:07 +01:00
|
|
|
|
2023-01-09 16:51:19 +01:00
|
|
|
echo "All docker containers are healthy."
|
2023-12-24 19:19:07 +01:00
|
|
|
exit
|