Phase 2 / Ep 07: Gateway 管理 —— start, stop, restart 与 daemon 模式

⏱ 预计阅读 3 分钟 更新于 2026/4/13

🎯 学习目标:掌握 Gateway 的启动、停止、重启和 daemon 配置。

1. Gateway 是什么?

Gateway 是 OpenClaw 的控制平面——它不直接处理 AI 推理,而是负责:

  • 接收来自所有 Channel 的消息
  • 身份验证和权限检查
  • 将消息路由给正确的 Agent
  • Plugin 管道的执行
  • 日志和监控

2. 核心命令

启动 Gateway

# 前台运行(开发调试用)
openclaw gateway start

# 后台 daemon 模式(生产用)
openclaw gateway start --daemon

停止 Gateway

openclaw gateway stop

重启 Gateway

# 平滑重启(不丢消息)
openclaw gateway restart

查看状态

openclaw status

3. Daemon 模式详解

Daemon 模式让 OpenClaw 在后台静默运行,即使关闭 Terminal 也不会停止。

macOS:使用 LaunchAgent

# 安装 daemon
openclaw onboard --install-daemon

# 手动管理
launchctl load ~/Library/LaunchAgents/ai.openclaw.gateway.plist
launchctl unload ~/Library/LaunchAgents/ai.openclaw.gateway.plist

Linux:使用 systemd

sudo systemctl start openclaw
sudo systemctl stop openclaw
sudo systemctl enable openclaw   # 开机自启

4. CLI vs Telegram 对照

操作 CLI 命令 Telegram 命令 说明
启动网关 openclaw gateway start N/A 仅 CLI 可操作
停止网关 openclaw gateway stop N/A 仅 CLI 可操作
重启网关 openclaw gateway restart /restart Telegram 需管理员
查看状态 openclaw status /status 双线可用
诊断修复 openclaw doctor /doctor 双线可用

⚠️ Gateway 管理是基础设施操作,大部分只能通过 CLI 进行。Telegram 的 /restart 需要白名单用户权限。

下节预告: Ep 08,深入 openclaw configopenclaw.json,掌握配置管理的艺术。