Add local watchdog (HTTP-200 probe + per-minute cron auto-restart)

This commit is contained in:
cania
2026-08-11 11:38:00 +02:00
parent 40ec0c8506
commit 05a297f054
3 changed files with 66 additions and 4 deletions

28
9router-watchdog.sh Normal file
View File

@@ -0,0 +1,28 @@
#!/bin/sh
# 9router-watchdog.sh — local health monitor + auto-restart.
#
# Runs from cron (e.g. every minute). Checks the 9router API endpoint;
# if it does NOT respond with HTTP 200, the service is (re)started via
# start-9router.sh.
#
# Uses absolute paths because cron has a minimal PATH.
# Run as root (so it can drop privileges via runuser inside start-9router.sh).
CURL=/usr/bin/curl
WRAPPER=/usr/local/bin/start-9router.sh
URL=http://127.0.0.1:20128/v1/models
LOG=/home/ardhi/9router.log
# If the wrapper is missing, nothing we can do.
[ -x "$WRAPPER" ] || exit 0
# Probe the API. -f makes curl exit non-zero on HTTP >= 400.
if "$CURL" -fs -m 5 -o /dev/null "$URL" 2>/dev/null; then
# Healthy — nothing to do.
exit 0
fi
# Unhealthy (no response / non-200) → restart.
echo "[$(date '+%Y-%m-%d %H:%M:%S')] watchdog: 9router not healthy, restarting" >> "$LOG" 2>/dev/null
"$WRAPPER"
exit 0