diff --git a/healthcheck_containers.sh b/healthcheck_containers.sh new file mode 100644 index 0000000..f89469a --- /dev/null +++ b/healthcheck_containers.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# To check if container is running and if found stopped it will restart it and also renews the unix socket. +# Recommended to use with revive_pods.sh which is systemd service check certain containers hourly. + +for container in "$@"; do +status=$(podman inspect -f '{{.State.Status}}' $container) + if [ "$status" = "exited" ]; then + podman start $container && echo "Container $container started" || echo "failed to start container $container" + rm /srv/http/$container && echo "reloaded clean socket file" || echo "failed to remove old socket file for $container" + systemctl --user restart $container.service && echo "service restarted" || echo "failed to restart service" + + else + + echo "Container $container is $status" + fi +done