48 lines
1.5 KiB
Bash
48 lines
1.5 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# kiosk-watchdog.sh — Monitors Archipelago backend health.
|
||
|
|
# Restarts the backend if it's unresponsive for 60 seconds.
|
||
|
|
# Shows server IP on text console if X is not running.
|
||
|
|
#
|
||
|
|
# Designed to run as a systemd service or standalone.
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
HEALTH_URL="http://localhost/health"
|
||
|
|
CHECK_INTERVAL=5 # seconds between checks
|
||
|
|
MAX_FAILS=12 # 12 x 5s = 60s before restart
|
||
|
|
|
||
|
|
FAIL_COUNT=0
|
||
|
|
|
||
|
|
echo "Archipelago kiosk watchdog started"
|
||
|
|
|
||
|
|
while true; do
|
||
|
|
# Check backend health
|
||
|
|
if curl -sf "$HEALTH_URL" > /dev/null 2>&1; then
|
||
|
|
if [ "$FAIL_COUNT" -gt 0 ]; then
|
||
|
|
echo "Backend recovered after $FAIL_COUNT failed checks"
|
||
|
|
fi
|
||
|
|
FAIL_COUNT=0
|
||
|
|
else
|
||
|
|
FAIL_COUNT=$((FAIL_COUNT + 1))
|
||
|
|
echo "Health check failed ($FAIL_COUNT/$MAX_FAILS)"
|
||
|
|
|
||
|
|
if [ "$FAIL_COUNT" -ge "$MAX_FAILS" ]; then
|
||
|
|
echo "Backend unresponsive for 60s, restarting archipelago service..."
|
||
|
|
systemctl restart archipelago || true
|
||
|
|
FAIL_COUNT=0
|
||
|
|
sleep 10
|
||
|
|
continue
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
# If X is not running, display IP on text console as fallback
|
||
|
|
if ! pgrep -x Xorg > /dev/null 2>&1 && ! pgrep -x chromium > /dev/null 2>&1; then
|
||
|
|
IP=$(hostname -I 2>/dev/null | awk '{print $1}')
|
||
|
|
if [ -n "$IP" ]; then
|
||
|
|
printf '\n\n Archipelago Server\n IP: %s\n Web UI: http://%s\n\n' "$IP" "$IP" > /dev/tty1 2>/dev/null || true
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
sleep "$CHECK_INTERVAL"
|
||
|
|
done
|