简介
Openclaw Rescue Kit
原始描述
OpenClaw 自救套件 - 网关启动包装(端口冲突防护)、看门狗监控、自动重启、配置回滚、安全加固、日志清理、Git版本管理。当用户提到 OpenClaw 网关崩溃、需要看门狗、配置回滚、安全扫描、日志清理、端口冲突、或部署自救脚本时使用此技能。包含 10 个独立脚本和完整部署指南。
通过你的 Agent 添加
安装目录:openclaw-rescue-kit/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
技能正文
name: openclaw-rescue-kit
description: OpenClaw 自救套件 - 网关监控、自动重启、配置回滚、安全加固、日志清理、Git版本管理。当用户提到 OpenClaw 网关崩溃、需要看门狗、配置回滚、安全扫描、日志清理、或部署自救脚本时使用此技能。包含 8 个独立脚本和完整部署指南。
OpenClaw 自救套件
一套完整的 Shell 脚本,用于保障 OpenClaw AI 助手 7x24 小时稳定运行。
快速安装
从 clawhub 安装(推荐)
clawhub install openclaw-rescue-kit
bash ~/.openclaw/skills/openclaw-rescue-kit/scripts/install-rescue-kit.sh
从 .skill 文件安装
clawhub install ./openclaw-rescue-kit.skill
bash ~/.openclaw/skills/openclaw-rescue-kit/scripts/install-rescue-kit.sh
手动安装
mkdir -p ~/.openclaw/scripts ~/.openclaw/logs ~/.openclaw/backups
cp ~/.openclaw/skills/openclaw-rescue-kit/scripts/*.sh ~/.openclaw/scripts/
chmod +x ~/.openclaw/scripts/*.sh
bash ~/.openclaw/scripts/install-rescue-kit.sh
clawhub install ./openclaw-rescue-kit.skill
bash ~/.openclaw/skills/openclaw-rescue-kit/scripts/install-rescue-kit.sh
mkdir -p ~/.openclaw/scripts ~/.openclaw/logs ~/.openclaw/backups
cp ~/.openclaw/skills/openclaw-rescue-kit/scripts/*.sh ~/.openclaw/scripts/
chmod +x ~/.openclaw/scripts/*.sh
bash ~/.openclaw/scripts/install-rescue-kit.sh
安装完成后:
# 1. 编辑告警配置(填入飞书/Telegram Webhook)
vim ~/.openclaw/notify.conf
# 2. 保存安全配置
bash ~/.openclaw/scripts/security-hardening.sh --save-safe
# 3. 保存 Git 安全版本
bash ~/.openclaw/scripts/git-tag.sh save-safe
# 4. 测试告警
bash ~/.openclaw/scripts/notify.sh -l INFO "自救套件部署完成"
脚本清单
脚本
功能
运行方式
core.sh
核心诊断(网关状态、配置验证)
被其他脚本调用
gateway-watchdog.sh
网关看门狗(配置验证+自动回滚+重启)
定时任务
health-check.sh
健康检查(资源、消息活动)
定时任务
config-rollback.sh
配置回滚(多级备份)
手动/看门狗触发
security-hardening.sh
安全加固扫描
手动
notify.sh
告警通知(飞书/Telegram/企微/钉钉)
被其他脚本调用
log-cleaner.sh
智能日志清理
定时任务
git-tag.sh
Git 配置版本管理
手动/定时任务
config-rollback.sh 使用
| 脚本 | 功能 | 运行方式 |
|---|---|---|
core.sh |
核心诊断(网关状态、配置验证) | 被其他脚本调用 |
gateway-watchdog.sh |
网关看门狗(配置验证+自动回滚+重启) | 定时任务 |
health-check.sh |
健康检查(资源、消息活动) | 定时任务 |
config-rollback.sh |
配置回滚(多级备份) | 手动/看门狗触发 |
security-hardening.sh |
安全加固扫描 | 手动 |
notify.sh |
告警通知(飞书/Telegram/企微/钉钉) | 被其他脚本调用 |
log-cleaner.sh |
智能日志清理 | 定时任务 |
git-tag.sh |
Git 配置版本管理 | 手动/定时任务 |
# 试运行(只看不执行)
bash ~/.openclaw/scripts/config-rollback.sh --dry-run
# 实际回滚
bash ~/.openclaw/scripts/config-rollback.sh
# 回滚到安全配置
bash ~/.openclaw/scripts/config-rollback.sh --safe
定时任务配置
macOS LaunchAgent(推荐)
macOS 上 crontab 受 SIP 限制,推荐使用 LaunchAgent。
安装脚本会自动生成 plist 到 ~/.openclaw/launchagents-ready/(路径已正确替换)。
如果安装脚本因沙箱权限无法自动复制,请手动执行:
# 复制已准备好的 plist(路径已替换,无需手动修改)
cp ~/.openclaw/launchagents-ready/*.plist ~/Library/LaunchAgents/
# 加载所有服务
launchctl load ~/Library/LaunchAgents/ai.openclaw.watchdog.plist
launchctl load ~/Library/LaunchAgents/ai.openclaw.healthcheck.plist
launchctl load ~/Library/LaunchAgents/ai.openclaw.logcleaner.plist
launchctl load ~/Library/LaunchAgents/ai.openclaw.gittag.plist
# 验证
launchctl list | grep openclaw
服务说明:
| 服务 | 频率 | 功能 |
|---|---|---|
ai.openclaw.gateway |
持续 (KeepAlive) | 网关进程守护(OpenClaw 自带) |
ai.openclaw.watchdog |
每分钟 | 配置验证 + 自动回滚 + 重启 |
ai.openclaw.healthcheck |
每小时 | 健康检查 + 告警 |
ai.openclaw.logcleaner |
每天 | 日志清理 + Session 瘦身 |
ai.openclaw.gittag |
每天 | Git 配置基线版本 |
管理命令:
# 停止服务
launchctl unload ~/Library/LaunchAgents/ai.openclaw.watchdog.plist
# 重启服务
launchctl unload ~/Library/LaunchAgents/ai.openclaw.watchdog.plist
launchctl load ~/Library/LaunchAgents/ai.openclaw.watchdog.plist
# 查看日志
tail -f ~/.openclaw/logs/watchdog.log
Linux crontab
Linux 上可以使用 crontab:
crontab -e
添加以下内容:
# OpenClaw 自救套件定时任务
SHELL=/bin/bash
PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
# 每分钟检查网关(看门狗)
* * * * * /bin/bash $HOME/.openclaw/scripts/gateway-watchdog.sh >> $HOME/.openclaw/logs/cron.log 2>&1
# 每小时健康检查
0 * * * * /bin/bash $HOME/.openclaw/scripts/health-check.sh >> $HOME/.openclaw/logs/cron.log 2>&1
# 每天凌晨3点日志清理
0 3 * * * /bin/bash $HOME/.openclaw/scripts/log-cleaner.sh >> $HOME/.openclaw/logs/cron.log 2>&1
# 每天凌晨2:30 Git 基线版本
30 2 * * * /bin/bash $HOME/.openclaw/scripts/git-tag.sh save-baseline >> $HOME/.openclaw/logs/cron.log 2>&1
配置修改公约(必须遵守)
修改 openclaw.json 前必须按以下流程操作:
1. 备份 → bash ~/.openclaw/scripts/git-tag.sh save-working
2. 检查 → bash ~/.openclaw/scripts/core.sh(确认网关正常)
3. 修改 → 编辑配置文件
4. 验证 → openclaw gateway status
5. 成功 → bash ~/.openclaw/scripts/git-tag.sh save-safe
6. 失败 → bash ~/.openclaw/scripts/git-tag.sh quick-rollback
告警通知配置
编辑 ~/.openclaw/notify.conf,填入至少一个 Webhook:
# 飞书机器人 Webhook
FEISHU_WEBHOOK_URL="https://open.feishu.cn/open-apis/bot/v2/hook/YOUR_HOOK_ID"
# Telegram(可选)
# TELEGRAM_BOT_TOKEN="your_bot_token"
# TELEGRAM_CHAT_ID="your_chat_id"
# 企业微信(可选)
# WECHAT_WEBHOOK_URL="your_webhook_url"
# 钉钉(可选)
# DINGTALK_WEBHOOK_URL="your_webhook_url"
关键经验
- 网关挂了 AI 诊断不了自己 → 使用独立脚本 + 端口检测
- Webhook 通知不依赖网关 → 网关挂了也能发告警
- macOS 上 LaunchAgent 比 crontab 更可靠
- KeepAlive 只管重启,不管配置验证 → 看门狗脚本仍有价值
- 必须有锁文件机制 → 防止看门狗重复执行
- 必须有重启冷却期 → 避免频繁重启(默认 60 秒)
- 必须有重启次数限制 → 防止无限循环(默认 3 次)
故障排查
# 网关反复重启
tail -f ~/.openclaw/logs/watchdog.log
bash ~/.openclaw/scripts/core.sh
bash ~/.openclaw/scripts/config-rollback.sh --dry-run
# 告警不生效
bash ~/.openclaw/scripts/notify.sh "测试消息"
cat ~/.openclaw/logs/unsent_alerts.log
# 配置回滚失败
ls -la ~/.openclaw/backups/
bash ~/.openclaw/scripts/git-tag.sh list
详细文档
# 网关反复重启
tail -f ~/.openclaw/logs/watchdog.log
bash ~/.openclaw/scripts/core.sh
bash ~/.openclaw/scripts/config-rollback.sh --dry-run
# 告警不生效
bash ~/.openclaw/scripts/notify.sh "测试消息"
cat ~/.openclaw/logs/unsent_alerts.log
# 配置回滚失败
ls -la ~/.openclaw/backups/
bash ~/.openclaw/scripts/git-tag.sh list
详细文档
完整使用说明和踩坑记录见 references/guide.md
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。