360 Secure SkillHub
360 安全技能中心

Gateway Watchdog

用于 OpenClaw 网关的 bash 守护脚本,经 launchd 每 5 分钟运行。依次做 HTTP 探测、启动宽限期判断、端口回退检查、渐进重试与冷却限制,避免误重启和重启循环,并写入日志文件。

bryantegomoh
bryantegomoh
热度 79.28
最近更新 2026-05-11 17:34:51
分类:自动化依赖:代码执行 / 读写文件应用场景:DevOps / 自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add gateway-watchdog-v2
Metadata
name
gateway-watchdog
description
Production-grade bash watchdog for the OpenClaw gateway. Runs via launchd every 5 minutes. Handles boot grace periods, progressive retry with backoff, port-level fallback checks, stale PID detection, and restart cooldowns — preventing restart loops while keeping the gateway reliably alive.

gateway-watchdog

Keeps the OpenClaw gateway alive without killing it during startup. Five defensive layers prevent false restarts and restart loops.

How It Works

  1. HTTP check — pings http://127.0.0.1:18789; exits immediately if the gateway responds
  2. Boot grace — if the process is <180s old, waits without acting (avoids killing a booting gateway)
  3. Port check — if the port is bound but HTTP is slow, waits up to 15s for recovery
  4. Progressive retry — 3 retries at 15s / 30s / 45s intervals
  5. Cooldown — enforces a 10-minute gap between restarts to prevent loops

Logs go to ~/.openclaw/logs/watchdog.log.

Setup (macOS launchd)

Create ~/Library/LaunchAgents/com.openclaw.gateway-watchdog.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.openclaw.gateway-watchdog</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>/path/to/skills/gateway-watchdog/scripts/gateway-watchdog.sh</string>
    </array>
    <key>StartInterval</key>
    <integer>300</integer>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Then load it:

launchctl load ~/Library/LaunchAgents/com.openclaw.gateway-watchdog.plist

Usage (manual)

bash scripts/gateway-watchdog.sh

Requirements

  • macOS (uses launchctl, lsof, date -j)
  • curl in PATH
  • OpenClaw gateway running under launchd as ai.openclaw.gateway