Install
openclaw skills install @yuestuday/scriptsWindows background watchdog for the OpenClaw Gateway: 5s health checks, auto-restart on crash, hidden no-window operation, tray status icon, and a maintenance lock that keeps repairs (doctor --fix) from racing the watchdog.
openclaw skills install @yuestuday/scriptsA Windows background watchdog for the OpenClaw Gateway. It health-checks the Gateway every 5 seconds, automatically restarts it when it goes down, and runs hidden in the background — no CMD window — with a system-tray status icon.
Its key feature is a maintenance lock: while a repair such as doctor --fix
is running, the watchdog suspends all health checks and restart attempts, so the
two never fight each other. Version-agnostic path resolution, HTTP-first health
probing, log rotation, and deadlock-safe lock expiry are all included.
!! Gateway OFFLINE even though the port is listeningdoctor --fix run keeps getting interrupted by the watchdog trying to restart| Piece | File | Role |
|---|---|---|
| Watchdog | scripts/watchdog.ps1 | Main loop, health check, restart, tray icon |
| Maintenance wrapper | scripts/watchdog-maintenance.ps1 | Run a repair while holding the lock |
| Hidden launcher | scripts/run_gateway_silent.vbs | Start Gateway with no window |
| Gateway script | scripts/gateway.cmd | Dynamic path resolution, no version pin |
| Installer | scripts/install_watchdog_admin.bat | One-shot admin setup for scheduled tasks |
The lock file is ~/.openclaw/watchdog-maintenance.lock (JSON: owner, pid, createdAt).
LOCK_STALE_SEC (default 300s) is treated as abandoned and
removed automatically (dead-lock protection).finally block, always.Get-Content "$env:USERPROFILE\.openclaw\watchdog-status.json" -Raw
Get-Content "$env:USERPROFILE\.openclaw\watchdog.log" -Tail 20
The status file holds: state (starting/ok/down/restarting/maintenance), cycle,
failCount, updatedAt, uptimeMin.
powershell -NoProfile -File "$env:USERPROFILE\.openclaw\workspace\watchdog-maintenance.ps1" doctor --fix --non-interactive
The wrapper takes the lock, runs the command, releases the lock. Never run a repair bare while the watchdog is live — it will fight you.
Right-click -> Run as administrator:
install_watchdog_admin.bat
This switches the Gateway task to the hidden VBS launcher, updates the Watchdog task to run hidden PowerShell, restarts the Gateway silently, and verifies the port.
$SHOW_TRAY = $false in watchdog.ps1 disables the tray (headless mode). Without
an interactive session the tray is skipped automatically — the status file is
still written.
watchdog.ps1 top block)| Var | Default | Meaning |
|---|---|---|
$CHECK_INTERVAL | 5 | seconds between checks |
$GATEWAY_PORT | 18789 | Gateway port |
$RESTART_THRESHOLD | 2 | consecutive failures before restart |
$LOCK_STALE_SEC | 300 | abandoned-lock timeout |
$DOCTOR_TIMEOUT_SEC | 90 | max doctor --fix runtime |
$DOCTOR_COOLDOWN_MIN | 10 | min gap between doctor runs |
$SELF_REFRESH_HOURS | 24 | relaunch self before shell limits |
!! Gateway OFFLINE while port is listening — usually a restart-timing race;
HTTP probe first. If persistent, check the maintenance lock is not stuck.schtasks Access denied — the
scheduled task needs Administrator. Run the installer as admin.Stop-Process.gateway.cmd;
re-run the installer to switch it to run_gateway_silent.vbs.MIT-0 — see LICENSE.