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

View File

@@ -23,12 +23,38 @@ This project solves all three with a tiny **wrapper script** + an **adaptive cro
---
## Optional: local watchdog (auto-restart if it dies)
`@reboot` starts the service at boot but does **not** restart it if the parent
`-t` process later dies. Add a local watchdog that probes the API every minute
and restarts 9router if it isn't healthy.
`9router-watchdog.sh` checks `http://127.0.0.1:20128/v1/models` — if it does **not**
return HTTP 200, it calls `start-9router.sh` again. Run it from root's crontab:
```bash
# root crontab — every minute
* * * * * /usr/local/bin/9router-watchdog.sh
```
Or just run `sudo ./install.sh` (it registers both the `@reboot` job and the
per-minute watchdog for you).
Notes:
- The check is a real HTTP 200 probe (not just "is the port open"), so a hung
Next.js process that still holds the port will also be detected and restarted.
- Max recovery delay is ~1 minute (the cron interval).
- The watchdog runs **locally** on the same machine — no external monitoring infra needed.
---
## Files
| File | Purpose |
|------|---------|
| `start-9router.sh` | Detached launcher. Drops to `ardhi` if run as root, runs directly if already `ardhi`. Uses absolute paths (cron `@reboot` has a minimal `PATH`). |
| `install.sh` | One-shot setup: installs the wrapper, fixes log ownership, and registers the `@reboot` cron as **root**. |
| `9router-watchdog.sh` | Local health monitor. Probes `/v1/models`; restarts via the wrapper if not HTTP 200. |
| `install.sh` | One-shot setup: installs both scripts, fixes log ownership, and registers the `@reboot` cron + per-minute watchdog as **root**. |
| `README.md` | This file. |
---