Files
my-project/tools/xiufu_openclaw2.sh
T

61 lines
2.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
echo "=== OpenClaw 加强修复 (2026-02-26 版) ==="
# 0. 先杀干净所有可能残留(最重要,避免鬼进程)
echo "强制杀死所有 OpenClaw / node 相关进程..."
pkill -9 -f "openclaw|clawdbot|gateway|molt" 2>/dev/null
pkill -9 -f node 2>/dev/null # 如果你确定没其他 node 程序在跑才安全,否则注释掉这行
sleep 2
# 检查端口是否真释放
echo "检查 18789 端口占用:"
sudo lsof -i :18789 || sudo netstat -tuln | grep 18789 || echo "端口已释放"
# 1. 运行 doctor --fix(官方推荐修复工具)
echo "运行 openclaw doctor --fix ..."
openclaw doctor --fix || openclaw doctor --repair --force
# 2. 清理更多可能导致崩溃的东西
echo "清理锁、旧 session、缓存..."
find ~/.openclaw -name "*.lock" -delete 2>/dev/null
rm -rf ~/.openclaw/sessions/* 2>/dev/null # 如果你不怕丢对话历史
openclaw system clean --cache 2>/dev/null || true
# 3. 以后台 + verbose + force 方式启动(方便看崩溃原因)
echo "启动 gateway(前台 verbose + force)..."
openclaw gateway stop 2>/dev/null || true
sleep 2
openclaw gateway --force --verbose --port 18789 > /tmp/gateway_crash.log 2>&1 &
# 4. 等待并监控(延长到 30 秒,看是否秒崩)
echo "等待 gateway 稳定启动(最多 30 秒)..."
for i in {1..30}; do
if curl -s --connect-timeout 2 http://127.0.0.1:18789/ > /dev/null; then
echo "✅ 端口已监听(第 ${i} 秒)"
# 再等 8 秒看会不会掉
sleep 8
if curl -s http://127.0.0.1:18789/ > /dev/null; then
echo "✅ 稳定!(没在 8 秒内崩溃)"
break
else
echo "❌ 端口又消失了 → 崩溃了"
fi
fi
sleep 1
done
# 5. 如果起来了,测试
if curl -s http://127.0.0.1:18789/ > /dev/null; then
echo "测试 agent 对话..."
openclaw agent --to "fix_test_$(date +%s)" --message "测试:你现在状态正常吗?请回复 '爪子已复活,汪!'" --local --timeout 25
else
echo "❌ Gateway 没起来,看日志:"
echo "tail -n 80 /tmp/gateway_crash.log"
echo "请把上面日志贴给我,我帮你看具体崩溃原因。"
fi
echo "修复结束。如果还是不行,请提供:"
echo "1. /tmp/gateway_crash.log 的最后 30 行"
echo "2. openclaw status --all 的输出"
echo "3. journalctl --user -u openclaw-gateway -n 50 (如果用了 systemd)"