其他
OpenClaw Systemd 管理指南
摘要生成中
AI生成,仅供参考
本文档介绍如何使用 systemd 管理 OpenClaw 服务,包括启动、停止、重启、查看状态、查看日志等操作。
一、systemd 基础命令
1. 服务状态管理
启动 OpenClaw
sudo systemctl start openclaw
停止 OpenClaw
sudo systemctl stop openclaw
# 重启 OpenClaw(修改配置后使用)
sudo systemctl restart openclaw
# 重载配置(不重启服务)
sudo systemctl reload openclaw
# 查看运行状态
sudo systemctl status openclaw
2. 开机自启设置
# 设置开机自启动(默认已启用)
sudo systemctl enable openclaw
禁用开机自启动
sudo systemctl disable openclaw
查看是否开机自启
sudo systemctl is-enabled openclaw
二、日志查看
1. 使用 journalctl 查看系统日志
查看 OpenClaw 的所有日志
sudo journalctl -u openclaw
查看最新 100 行
sudo journalctl -u openclaw -n 100
# 实时跟踪日志(类似 tail -f)
sudo journalctl -u openclaw -f
查看今天的日志
sudo journalctl -u openclaw --since today
查看最近 1 小时的日志
sudo journalctl -u openclaw --since "1 hour ago"
# 查看特定时间段的日志
sudo journalctl -u openclaw --since "2026-03-25 10:00" --until "2026-03-25 12:00"
2. 使用 openclaw logs 命令
查看最新 200 行日志
openclaw logs
查看指定行数
openclaw logs --limit 500
实时跟踪日志
openclaw logs --follow
本地时间显示
openclaw logs --local-time
# 纯文本格式(无颜色)
openclaw logs --plain
# JSON 格式
openclaw logs --json
三、故障排查
1. 服务无法启动
查看详细错误信息
sudo systemctl status openclaw -l
查看启动失败原因
sudo journalctl -u openclaw -n 50 --no-pager
# 检查配置文件语法
openclaw config validate
2. 查看进程是否重复
# 检查有多少 openclaw 进程
ps aux | grep openclaw | grep -v grep
# 检查进程树
pstree -p | grep openclaw
# 检查端口占用
sudo netstat -tlnp | grep openclaw
sudo ss -tlnp | grep openclaw
3. 强制重启(进程卡死时)
停止服务
sudo systemctl stop openclaw
强制杀掉残留进程
sudo pkill -9 openclaw
# 重新启动
sudo systemctl start openclaw
四、配置管理
1. 配置文件位置
| 文件 | 说明 |
/etc/systemd/system/openclaw-gateway.service | systemd 服务文件 |
/etc/openclaw/openclaw.json | OpenClaw 主配置文件 |
/etc/openclaw/channels/ | 频道配置文件目录 |
2. 修改配置后生效
# 修改配置文件后,重载 systemd
sudo systemctl daemon-reload
# 重启服务
sudo systemctl restart openclaw
3. 编辑服务文件
编辑 systemd 服务文件
sudo systemctl edit --full openclaw
或直接使用编辑器
sudo nano /etc/systemd/system/openclaw-gateway.service
五、常用场景速查
| 场景 | 命令 |
| 快速重启 | sudo systemctl restart openclaw |
| 查看是否在运行 | sudo systemctl is-active openclaw |
| 查看是否开机自启 | sudo systemctl is-enabled openclaw |
| 实时看日志 | openclaw logs --follow 或 sudo journalctl -u openclaw -f |
| 修改配置后重启 | sudo systemctl restart openclaw |
| 完全停止 | sudo systemctl stop openclaw && sudo systemctl disable openclaw |
| 完全启用 | sudo systemctl enable --now openclaw |
六、与 supervisord 对比
| 功能 | systemd | supervisord |
| 启动服务 | sudo systemctl start openclaw | sudo supervisorctl start openclaw |
| 停止服务 | sudo systemctl stop openclaw | sudo supervisorctl stop openclaw |
| 重启服务 | sudo systemctl restart openclaw | sudo supervisorctl restart openclaw |
| 查看状态 | sudo systemctl status openclaw | sudo supervisorctl status openclaw |
| 查看日志 | sudo journalctl -u openclaw | sudo supervisorctl tail openclaw |
| 开机自启 | sudo systemctl enable openclaw | 需单独配置 |
| 现代 Linux 支持 | ✅ 原生支持 | ❌ 需额外安装 |
七、注意事项
- 不要同时使用 systemd 和 supervisord 管理 OpenClaw,会导致重复启动
- 修改配置文件后务必重启服务:
sudo systemctl restart openclaw - 查看日志时推荐用
openclaw logs,格式更友好 - 如果遇到问题,先用
sudo systemctl status openclaw -l查看详细错误
八、延伸阅读
- OpenClaw 官方文档:https://docs.openclaw.ai
- systemd 官方文档:https://systemd.io
- 日志文件位置:
/tmp/openclaw/openclaw-YYYY-MM-DD.log

发表回复