computer-playbook/roles/sys-ctl-hlth-docker-container/files/sys-ctl-hlth-docker-container.sh
Kevin Veen-Birkenbach 3a839cfe37
Refactor systemctl services and categories due to alarm bugs
This commit restructures systemctl service definitions and category mappings.

Motivation: Alarm-related bugs revealed inconsistencies in service and role handling.

Preparation step: lays the groundwork for fixing the alarm issues by aligning categories, roles, and service templates.
2025-08-18 13:35:43 +02:00

31 lines
947 B
Bash

#!/bin/sh
docker_ps_grep_unhealthy="$(docker ps --filter health=unhealthy --format '{{.Names}}')"
docker_ps_grep_exited="$(docker ps --filter status=exited --format '{{.ID}}')"
exitcode=0
if [ -n "$docker_ps_grep_unhealthy" ]; then
echo "Some docker containers are unhealthy: $docker_ps_grep_unhealthy"
exitcode=1
fi
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
fi
if [ "$exitcode" -ne "0" ]; then
exit $exitcode
fi
echo "All docker containers are healthy."
exit