Add local watchdog (HTTP-200 probe + per-minute cron auto-restart)
This commit is contained in:
28
9router-watchdog.sh
Normal file
28
9router-watchdog.sh
Normal 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
|
||||
Reference in New Issue
Block a user