watchclaw
OpenClaw gateway watchdog — auto-recovery from bad config changes.
What It Does
watchclaw monitors your OpenClaw gateway and automatically recovers from bad configurations:
- - Health polling — checks gateway HTTP endpoint every N seconds
- Config change detection — detects uncommitted or new commits in your config repo
- Auto-recovery — stashes uncommitted changes (U1) or reverts bad commits (U2) via git
- Probation — validates stability after config changes before promoting to known-good
- Pluggable alerts — iMessage, webhook, or custom command on failure/recovery
Usage
CODEBLOCK0
Config
Create a .conf file (see watchclaw.conf.example):
CODEBLOCK1
Recovery Modes
| Scenario | Detection | Recovery |
|---|
| Uncommitted config change breaks gateway | Health check fails + dirty openclaw.json | INLINECODE2 → restart |
| Bad commit breaks gateway |
Health check fails + new commit |
git revert → restart |
| Config change during healthy operation | HEAD ≠ known-good in HEALTHY state | Enter probation, monitor |
Docker Mode
For containerized OpenClaw (e.g., 飞书/Feishu bot):
CODEBLOCK2
Requirements
- -
bash 4+, git, INLINECODE6 - OpenClaw gateway config must be in a git repo
- INLINECODE7 or
node for JSON validation
watchclaw
OpenClaw网关看门狗——从错误配置变更中自动恢复。
功能说明
watchclaw监控您的OpenClaw网关,并自动从错误配置中恢复:
- - 健康轮询 — 每隔N秒检查网关HTTP端点
- 配置变更检测 — 检测配置仓库中未提交或新提交的变更
- 自动恢复 — 通过git暂存未提交的变更(U1)或回滚错误的提交(U2)
- 观察期 — 配置变更后验证稳定性,确认无误后再提升为已知良好状态
- 可插拔告警 — 在故障/恢复时通过iMessage、webhook或自定义命令发送通知
使用方法
bash
启动监控(后台守护进程)
watchclaw --config /path/to/watchclaw.conf start
前台启动(用于调试)
watchclaw --config /path/to/watchclaw.conf start --foreground
查看状态
watchclaw --config /path/to/watchclaw.conf status
跟踪日志
watchclaw --config /path/to/watchclaw.conf logs -f
停止
watchclaw --config /path/to/watchclaw.conf stop
配置
创建.conf文件(参考watchclaw.conf.example):
bash
GATEWAY_PORT=18790
GATEWAYCONFIGDIR=$HOME/.openclaw
POLLINTERVALSEC=10
HEALTHTIMEOUTSEC=5
GATEWAY_TLS=0 # 使用https进行健康检查
MAX_RETRIES=3
ALERT_HOOK=imsg # imsg | webhook | command | none
ALERTIMSGTO=user@me.com
RESTART_MODE=native # native | docker
恢复模式
| 场景 | 检测方式 | 恢复方式 |
|---|
| 未提交的配置变更导致网关故障 | 健康检查失败 + openclaw.json存在未提交修改 | git stash → 重启 |
| 错误的提交导致网关故障 |
健康检查失败 + 存在新提交 | git revert → 重启 |
| 正常运行期间发生配置变更 | HEAD ≠ 健康状态下的已知良好版本 | 进入观察期,持续监控 |
Docker模式
适用于容器化运行的OpenClaw(例如飞书机器人):
bash
RESTART_MODE=docker
DOCKER_CONTAINER=openclaw-feishu
环境要求
- - bash 4+、git、curl
- OpenClaw网关配置必须位于git仓库中
- python3 或 node 用于JSON验证