早上 9 点,我在飞书给 AI 发消息:"汇总昨天的任务完成情况。"

没有回复。

10 分钟后,我再发一条:"检查一下有没有新邮件。"

还是没有回复。

我突然意识到:Gateway 可能挂了。

Gateway 是跑在服务器上的程序,监听端口 18789。所有飞书消息都经过它路由到 AI。它挂了等于整个系统罢工。

SSH 登录服务器,第一个命令:

ps aux | grep openclaw

没有输出。进程没了。

第二个命令检查端口:

lsof -i :18789

也没有输出。端口没人监听。

确认为 Gateway 进程挂了。

查看日志:

tail -100 /root/.openclaw/logs/gateway.log

最后一行是凌晨 3 点的错误:"Memory allocation failed, out of memory."

内存爆了。我的服务器只有 2G 内存,跑了太多东西。

重启 Gateway:

cd /root/.openclaw && ./start_gateway.sh

等了几秒,再检查进程:

ps aux | grep openclaw

这次看到进程了。Gateway 恢复运行。

飞书上再发消息给 AI,秒回。

总结踩坑教训:

1. Gateway 挂了 = 整个 AI 罢工。首先要学会检查进程和端口。

2. 内存不足是常见原因。我后来把服务器升级到 4G,再没出现过。

3. 配一个监控脚本,定期检查 Gateway 状态,挂了自动重启。

监控脚本我放在 /root/.openclaw/scripts/monitor.sh:

#!/bin/bash
if ! pgrep -f "openclaw" > /dev/null; then
    cd /root/.openclaw && ./start_gateway.sh
    echo "Gateway crashed, auto-restarted at $(date)" >> /root/.openclaw/logs/monitor.log
fi

crontab 里加一行,每 5 分钟检查一次:

*/5 * * * * /root/.openclaw/scripts/monitor.sh

从此之后,Gateway 挂了会自动恢复,不用人工介入。

踩坑是最好的学习方式。书本上不会告诉你内存不够会崩溃,但真实运行会。