Skip to content

Instantly share code, notes, and snippets.

@timrettop
Created November 29, 2025 16:07
Show Gist options
  • Select an option

  • Save timrettop/dbfe4a5cf3486be7de6766e199be4399 to your computer and use it in GitHub Desktop.

Select an option

Save timrettop/dbfe4a5cf3486be7de6766e199be4399 to your computer and use it in GitHub Desktop.
Unraid Container Healthcheck. Checks docker service for the status of all containers besides Blacklist array, attempts to start any down containers, and reports to Unraid if any fail. Also checks in to healthchecks.io unless any down containers don't start, so healthchecks.io will alert if a checkin hasn't occurred.
#!/bin/bash
# Checks docker service for the status of all containers besides Blacklist,
# attempts to start any down containers, and reports to Unraid if any fail.
# Also checks in to healthchecks.io unless any down containers don't start, so
# healthchecks.io will alert if a checkin hasn't occurred.
# Healthchecks.io API endpoint
url="https://hc-ping.com/<your_healthcheck_endpoint>"
max_attempts=2
attempt=1
Blacklist=(
container-name
)
Containers=$(docker ps -a --format "{{.Names}}")
Checkin=true
for val in $Containers; do
Skip=false
for check in ${Blacklist[@]}; do
if [ $val == $check ]; then
Skip=true
fi
done
if [ $(docker container inspect -f '{{.State.Running}}' $val) == "false" ] && [ $Skip == "false" ]; then
docker container start $val
sleep 5
if [ $(docker container inspect -f '{{.State.Running}}' $val) == "false" ] && [ $Skip == "false" ]; then
Checkin=false
/usr/local/emhttp/plugins/dynamix/scripts/notify -s Docker -i warning -d "$val service is down, restart failed"
else
/usr/local/emhttp/plugins/dynamix/scripts/notify -s Docker -d "$val service is down, restart succeeded"
fi
fi
done
if [ $Checkin == "true" ]; then
while true; do
if curl -s $url > /dev/null; then
echo "Successful healthcheck update"
exit 0
else if (( attempt >= max_attempts )); then
echo "Failed healthcheck update"
exit 1
fi
attempt=$((attempt+1))
sleep 2
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment