Add HA watchdog

This commit is contained in:
2026-03-27 19:44:00 -03:00
parent f0557a0a12
commit a0b67cf30b
3 changed files with 95 additions and 5 deletions

22
ha_watchdog.sh Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
HA_URL="http://localhost:8123"
STATE_FILE="/tmp/ha_watchdog_state"
if curl -s -m 10 "$HA_URL" > /dev/null; then
echo "0" > "$STATE_FILE"
else
STATE="0"
if [ -f "$STATE_FILE" ]; then
STATE=$(cat "$STATE_FILE")
fi
if [ "$STATE" -eq 1 ]; then
# Already tried restarting once, failed again -> Reboot
echo "0" > "$STATE_FILE"
sudo reboot
else
# Try returning the container to life
docker restart HomeAssistant
echo "1" > "$STATE_FILE"
fi
fi