其他

OpenClaw Systemd 管理指南

2026年3月25日
摘要生成中
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.servicesystemd 服务文件
/etc/openclaw/openclaw.jsonOpenClaw 主配置文件
/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 --followsudo journalctl -u openclaw -f
修改配置后重启sudo systemctl restart openclaw
完全停止sudo systemctl stop openclaw && sudo systemctl disable openclaw
完全启用sudo systemctl enable --now openclaw

六、与 supervisord 对比

功能systemdsupervisord
启动服务sudo systemctl start openclawsudo supervisorctl start openclaw
停止服务sudo systemctl stop openclawsudo supervisorctl stop openclaw
重启服务sudo systemctl restart openclawsudo supervisorctl restart openclaw
查看状态sudo systemctl status openclawsudo supervisorctl status openclaw
查看日志sudo journalctl -u openclawsudo supervisorctl tail openclaw
开机自启sudo systemctl enable openclaw需单独配置
现代 Linux 支持✅ 原生支持❌ 需额外安装

七、注意事项

  1. 不要同时使用 systemd 和 supervisord 管理 OpenClaw,会导致重复启动
  2. 修改配置文件后务必重启服务:sudo systemctl restart openclaw
  3. 查看日志时推荐用 openclaw logs,格式更友好
  4. 如果遇到问题,先用 sudo systemctl status openclaw -l 查看详细错误

八、延伸阅读

  • OpenClaw 官方文档:https://docs.openclaw.ai
  • systemd 官方文档:https://systemd.io
  • 日志文件位置:/tmp/openclaw/openclaw-YYYY-MM-DD.log

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理