Created
November 29, 2025 16:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original here: https://www.reddit.com/r/unRAID/comments/odo7yb/comment/id4sduy/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button