computer-playbook/roles/native-docker-health-check/files/docker-health-check.sh

20 lines
493 B
Bash
Raw Normal View History

2022-12-25 13:40:38 +01:00
#!/bin/sh
docker_ps_grep_unhealthy="$(docker ps | grep unhealthy)"
2023-01-09 16:51:19 +01:00
docker_ps_grep_exited="$(docker ps -a | grep Exited)"
exitcode=0
if [ ! -z "$docker_ps_grep_unhealthy" ]
2022-12-25 13:40:38 +01:00
then
echo "Some docker containers are unhealthy: $docker_ps_grep_unhealthy"
2023-01-09 16:51:19 +01:00
exitcode=1
fi
if [ ! -z "$docker_ps_grep_exited" ]
then
echo "Some docker containers exited: $docker_ps_grep_exited"
exitcode=2
fi
if [ "$exitcode" -ne "0" ]
then
exit $exitcode
fi
echo "All docker containers are healthy."
exit