Automatically restart unhealthy containers #3498
Vahor
started this conversation in
Feature Requests
Replies: 1 comment
-
A little bash script on your host should do the job (no tested). You need run it in background. #!/bin/bash
sleep 60
while true; do
# Get the list of unhealthy containers that have a healthcheck defined
unhealthy_containers=$(docker ps --filter "health=unhealthy" --format "{{.ID}} {{.Names}}" | while read container_id container_name; do
# Check if the container has a healthcheck defined by inspecting its health status
if [ "$(docker inspect --format='{{.State.Health.Status}}' "$container_id")" != "none" ]; then
echo "$container_id"
fi
done)
if [ -n "$unhealthy_containers" ]; then
echo "Restarting unhealthy containers: $unhealthy_containers"
docker restart $unhealthy_containers
fi
# Wait before checking again
sleep 60
done Basically put, every minute, the script check for container status (only those providing healthcheck will be processed for restart. You could add logic for notification inside this script of course. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Coolify already has a healthcheck feature. But currently it's only used to inform traefik whether to route requests to the app.
This feature would require:
The requirement is to use the healthcheck feature and not only check if the container is present or not . (it can be both, restart if the container is not present or unhealthy)
Beta Was this translation helpful? Give feedback.
All reactions