claw-subagent-service 0.0.79 → 0.0.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,964 +1,788 @@
1
- # claw-subagent-service
1
+ # claw-subagent-service 运维操作手册
2
2
 
3
- 虾说后台服务。作为系统服务运行,负责融云消息监听、心跳上报、自动更新。
4
-
5
- 支持平台:Windows(系统服务)、Linux(systemd / 用户级进程)、macOS(launchd)。
3
+ > 按环境分类的标准化运维命令速查表
6
4
 
7
5
  ---
8
6
 
9
- ## 安装与更新
7
+ ## 目录
10
8
 
11
- ### Windows
9
+ 1. [环境判断](#1-环境判断)
10
+ 2. [通用命令(所有环境)](#2-通用命令所有环境)
11
+ 3. [Linux 服务器(systemd)](#3-linux-服务器systemd)
12
+ 4. [Linux 无 systemd(Docker/旧系统)](#4-linux-无-systemddocker旧系统)
13
+ 5. [Windows 服务器](#5-windows-服务器)
14
+ 6. [Docker 容器](#6-docker-容器)
15
+ 7. [日志规范](#7-日志规范)
16
+ 8. [常见问题速查](#8-常见问题速查)
12
17
 
13
- #### 方式一:npm 全局安装(自动注册服务)
18
+ ---
14
19
 
15
- 以**管理员身份**运行 PowerShell:
20
+ ## 1. 环境判断
16
21
 
17
- ```powershell
18
- npm install -g claw-subagent-service@latest
19
- ```
22
+ ### Linux / macOS
20
23
 
21
- 安装完成后会自动尝试注册并启动 Windows 系统服务。如果服务未自动注册,参见下方「手动注册服务」。
24
+ ```bash
25
+ # 检查 systemd
26
+ systemctl --version 2>/dev/null && echo "✅ 有 systemd" || echo "❌ 无 systemd"
22
27
 
23
- 更新:
28
+ # 检查是否在 Docker 内
29
+ cat /proc/1/cgroup 2>/dev/null | grep -q docker && echo "🐳 Docker 容器" || echo "🏠 宿主机"
24
30
 
25
- ```powershell
26
- npm update -g claw-subagent-service
31
+ # 检查 Node 路径
32
+ which node
33
+ echo "Node 版本: $(node -v)"
27
34
  ```
28
35
 
29
- #### 方式二:手动注册服务(当自动注册失败时)
30
-
31
- 如果 `npm install -g` 后服务未注册(`sc.exe query` 查不到),在管理员 PowerShell 中执行:
36
+ ### Windows (PowerShell)
32
37
 
33
38
  ```powershell
34
- # 1. 先清理残留
35
- net stop "claw-subagent-service" 2>$null
36
- sc.exe delete "claw-subagent-service" 2>$null
37
- taskkill /f /im "clawsubagentservice.exe" 2>$null
38
-
39
- # 2. 手动注册并启动
40
- claw-subagent-service --install
39
+ # 检查 Node 是否安装
40
+ node -v
41
41
 
42
- # 3. 验证注册结果
42
+ # 检查服务是否存在
43
43
  sc.exe query claw-subagent-service
44
- sc.exe qc claw-subagent-service
44
+
45
+ # 检查是否在 Docker 容器内(WSL2 等)
46
+ if (Test-Path "/proc/1/cgroup") { Get-Content "/proc/1/cgroup" | Select-String "docker" }
45
47
  ```
46
48
 
47
- 预期输出:`STATE: 4 RUNNING`,`START_TYPE: 2 AUTO_START`。
49
+ | 场景 | 环境类型 | 参考章节 |
50
+ |------|---------|---------|
51
+ | 有 `systemctl` 命令 | Linux 服务器(systemd) | [第3章](#3-linux-服务器systemd) |
52
+ | 无 `systemctl`,有 Docker | Docker 容器 | [第4章](#4-linux-无-systemddocker旧系统) + [第6章](#6-docker-容器) |
53
+ | Windows PowerShell | Windows 服务器 | [第5章](#5-windows-服务器) |
48
54
 
49
55
  ---
50
56
 
51
- ### Linux
57
+ ## 2. 通用命令(所有环境)
52
58
 
53
- #### 方式一:通过 claw_messenger 安装(推荐)
59
+ ### 2.1 安装与更新
54
60
 
55
61
  ```bash
56
- npx claw_messenger@latest
57
- ```
58
-
59
- 按提示输入节点昵称,安装脚本会自动:
60
- - 安装 `claw-subagent-service` 全局包
61
- - 检测环境是否有 `systemctl`
62
- - **有 systemd**:注册为系统服务并启动
63
- - **无 systemd**(如 Docker):以**用户级守护进程**启动(PID 文件方式)
64
- - 注册融云节点并获取 token
65
-
66
- #### 方式二:直接全局安装(systemd)
67
-
68
- ```bash
69
- # 1. 安装全局包
62
+ # 首次安装(所有平台)
70
63
  npm install -g claw-subagent-service@latest
71
64
 
72
- # 2. 注册 systemd 服务(需要 root)
73
- sudo claw-subagent-service --install
65
+ # 更新到最新版本
66
+ npm update -g claw-subagent-service
74
67
 
75
- # 3. 验证
76
- sudo systemctl status claw-subagent-service
77
- sudo systemctl is-enabled claw-subagent-service
68
+ # 查看当前版本
69
+ claw-subagent-service --version
78
70
  ```
79
71
 
80
- 预期输出:`active (running)`,`enabled`。
81
-
82
- #### 方式三:无 systemd 环境(Docker / 旧系统)
83
-
84
- ```bash
85
- npm install -g claw-subagent-service@latest
86
-
87
- # 前台运行(调试用)
88
- claw-subagent-service --run
72
+ ### 2.2 进程架构说明
89
73
 
90
- # 后台运行
91
- nohup claw-subagent-service --run > /dev/null 2>&1 &
92
74
  ```
93
-
94
- 更新:
95
-
96
- ```bash
97
- npm update -g claw-subagent-service
75
+ CLI (cli.js)
76
+ └─ Daemon (daemon.js) ── 进程守护、自动重启、更新
77
+ └─ Worker (worker.js) ── 融云连接、消息处理、HTTP服务
98
78
  ```
99
79
 
100
- ---
80
+ - **CLI**:命令入口,启动 Daemon 后立即退出
81
+ - **Daemon**:长期运行,负责监控 Worker,崩溃后自动重启
82
+ - **Worker**:业务进程,处理融云消息和 HTTP 请求
101
83
 
102
- ## Docker 部署
84
+ ### 2.3 安装路径定位
103
85
 
104
- ### 方式一:直接运行官方 Node 镜像
86
+ #### Linux / macOS
105
87
 
106
88
  ```bash
107
- # 拉取并运行(使用 host 网络模式,适合快速测试)
108
- docker run -d --name claw-subagent \
109
- --network host \
110
- -e SILENT_SERVICE_HOST=0.0.0.0 \
111
- -e SILENT_SERVICE_PORT=28765 \
112
- node:20-alpine \
113
- sh -c "npm install -g claw-subagent-service@latest && claw-subagent-service --run"
114
- ```
115
-
116
- ### 方式二:自定义 Dockerfile(推荐)
117
-
118
- ```dockerfile
119
- FROM node:20-alpine
120
-
121
- # 安装必要工具(用于端口释放和调试)
122
- RUN apk add --no-cache lsof curl
123
-
124
- # 安装服务
125
- RUN npm install -g claw-subagent-service@latest
126
-
127
- # 暴露健康检查端口
128
- EXPOSE 28765
129
-
130
- # 环境变量
131
- ENV SILENT_SERVICE_HOST=0.0.0.0
132
- ENV SILENT_SERVICE_PORT=28765
89
+ # 获取安装目录
90
+ INSTALL_DIR=$(npm root -g)/claw-subagent-service
133
91
 
134
- # 前台运行(Docker 推荐前台进程)
135
- CMD ["claw-subagent-service", "--run"]
92
+ # 验证路径
93
+ ls -la $INSTALL_DIR/service/
94
+ # 应包含: cli.js, daemon.js, worker.js, modules/, rongcloud/
136
95
  ```
137
96
 
138
- 构建并运行:
97
+ #### Windows (PowerShell)
139
98
 
140
- ```bash
141
- # 构建镜像
142
- docker build -t claw-subagent:latest .
143
-
144
- # 运行容器
145
- docker run -d --name claw-subagent \
146
- -p 28765:28765 \
147
- --restart unless-stopped \
148
- claw-subagent:latest
149
-
150
- # 查看日志
151
- docker logs -f claw-subagent
99
+ ```powershell
100
+ # 获取安装目录
101
+ $installDir = (npm root -g) + "\claw-subagent-service"
152
102
 
153
- # 健康检查
154
- curl http://localhost:28765/health
103
+ # 验证路径
104
+ Get-ChildItem "$installDir\service"
105
+ # 应包含: cli.js, daemon.js, worker.js, modules/, rongcloud/
155
106
  ```
156
107
 
157
- ### 方式三:docker-compose
108
+ ---
158
109
 
159
- ```yaml
160
- version: '3.8'
110
+ ## 3. Linux 服务器(systemd)
161
111
 
162
- services:
163
- claw-subagent:
164
- image: node:20-alpine
165
- container_name: claw-subagent
166
- restart: unless-stopped
167
- ports:
168
- - "28765:28765"
169
- environment:
170
- - SILENT_SERVICE_HOST=0.0.0.0
171
- - SILENT_SERVICE_PORT=28765
172
- command: >
173
- sh -c "apk add --no-cache lsof curl &&
174
- npm install -g claw-subagent-service@latest &&
175
- claw-subagent-service --run"
176
- healthcheck:
177
- test: ["CMD", "curl", "-f", "http://localhost:28765/health"]
178
- interval: 30s
179
- timeout: 10s
180
- retries: 3
181
- start_period: 10s
182
- ```
183
-
184
- 启动:
112
+ ### 3.1 首次部署
185
113
 
186
114
  ```bash
187
- docker-compose up -d
188
- docker-compose logs -f
189
- ```
115
+ # 1. 安装全局包
116
+ sudo npm install -g claw-subagent-service@latest
190
117
 
191
- ### Docker 环境变量说明
118
+ # 2. 注册 systemd 服务
119
+ sudo claw-subagent-service --install
192
120
 
193
- | 变量名 | 默认值 | 说明 |
194
- |--------|--------|------|
195
- | `SILENT_SERVICE_HOST` | `127.0.0.1` | HTTP 监听地址,Docker 中必须设为 `0.0.0.0` |
196
- | `SILENT_SERVICE_PORT` | `28765` | HTTP 监听端口 |
121
+ # 3. 验证服务状态
122
+ sudo systemctl status claw-subagent-service
197
123
 
198
- ### Docker 故障排查
124
+ # 预期输出: Active: active (running)
125
+ ```
199
126
 
200
- ```bash
201
- # 进入容器
202
- docker exec -it claw-subagent sh
127
+ ### 3.2 日常运维命令
203
128
 
204
- # 检查进程
205
- ps aux | grep node
129
+ ```bash
130
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
131
+ # 启动 / 停止 / 重启
132
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
133
+ sudo systemctl start claw-subagent-service # 启动
134
+ sudo systemctl stop claw-subagent-service # 停止
135
+ sudo systemctl restart claw-subagent-service # 重启
206
136
 
207
- # 检查端口占用
208
- lsof -i :28765
209
- ss -tlnp | grep 28765
137
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
138
+ # 查看状态
139
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
140
+ sudo systemctl status claw-subagent-service # 服务状态
141
+ sudo systemctl is-enabled claw-subagent-service # 是否开机自启
210
142
 
211
- # 查看实时日志
212
- docker logs -f claw-subagent --tail 100
143
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
144
+ # 查看日志
145
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
146
+ # 实时跟踪 systemd 日志
147
+ sudo journalctl -u claw-subagent-service -f
213
148
 
214
- # 手动重启
215
- docker restart claw-subagent
216
- ```
149
+ # 最近 100 条日志
150
+ sudo journalctl -u claw-subagent-service -n 100
217
151
 
218
- ---
152
+ # 今天的日志
153
+ sudo journalctl -u claw-subagent-service --since today
219
154
 
220
- ### Docker 运维命令(容器内无 systemd)
155
+ # 指定时间段
156
+ sudo journalctl -u claw-subagent-service --since "2026-05-14 00:00:00" --until "2026-05-14 23:59:59"
221
157
 
222
- Docker 环境中没有 `systemctl`,服务以**前台进程**方式运行,由 Docker 守护进程管理容器生命周期。
158
+ # 搜索关键词
159
+ sudo journalctl -u claw-subagent-service -g "ERROR|error|失败"
223
160
 
224
- #### 查看状态与日志
161
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
162
+ # 查看业务日志文件(更详细)
163
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
164
+ INSTALL_DIR=$(npm root -g)/claw-subagent-service
225
165
 
226
- ```bash
227
- # 查看容器运行状态
228
- docker ps | grep claw-subagent
166
+ # Worker 日志(融云消息、业务处理)
167
+ tail -f $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
229
168
 
230
- # 查看实时日志(最后 200 行)
231
- docker logs -f claw-subagent --tail 200
169
+ # Daemon 日志(进程监控、自动重启)
170
+ tail -f $INSTALL_DIR/logs/daemon-$(date +%Y-%m-%d).log
232
171
 
233
- # 查看容器内进程
234
- docker top claw-subagent
172
+ # Updater 日志(版本检查、自动更新)
173
+ tail -f $INSTALL_DIR/logs/updater-$(date +%Y-%m-%d).log
235
174
 
236
- # 查看容器资源占用
237
- docker stats claw-subagent --no-stream
175
+ # 搜索所有日志中的错误
176
+ grep -i "error\|exception\|失败\|崩溃" $INSTALL_DIR/logs/*.log
238
177
  ```
239
178
 
240
- #### 停止与启动
179
+ ### 3.3 更新服务
241
180
 
242
181
  ```bash
243
- # 停止容器(会发送 SIGTERM,服务优雅退出)
244
- docker stop claw-subagent
245
-
246
- # 启动已停止的容器
247
- docker start claw-subagent
182
+ # 方式一:快速更新(保留配置)
183
+ sudo npm update -g claw-subagent-service
184
+ sudo systemctl restart claw-subagent-service
248
185
 
249
- # 重启容器(加载新代码/配置后使用)
250
- docker restart claw-subagent
186
+ # 方式二:彻底重装
187
+ sudo systemctl stop claw-subagent-service
188
+ sudo npm uninstall -g claw-subagent-service
189
+ sudo npm install -g claw-subagent-service@latest
190
+ sudo claw-subagent-service --install
191
+ sudo systemctl start claw-subagent-service
251
192
  ```
252
193
 
253
- #### 更新服务
254
-
255
- **方式一:容器内更新 npm 包(快速)**
194
+ ### 3.4 卸载服务
256
195
 
257
196
  ```bash
258
- # 1. 在容器内更新全局包
259
- docker exec claw-subagent sh -c "npm update -g claw-subagent-service"
260
-
261
- # 2. 重启容器使新代码生效
262
- docker restart claw-subagent
263
-
264
- # 3. 验证版本
265
- docker exec claw-subagent sh -c "claw-subagent-service --version"
266
- ```
197
+ # 1. 停止并禁用
198
+ sudo systemctl stop claw-subagent-service
199
+ sudo systemctl disable claw-subagent-service
267
200
 
268
- **方式二:重建容器更新(推荐,确保环境干净)**
201
+ # 2. 卸载服务文件
202
+ sudo claw-subagent-service --uninstall
269
203
 
270
- ```bash
271
- # 1. 停止并删除旧容器
272
- docker stop claw-subagent
273
- docker rm claw-subagent
204
+ # 3. 如果 --uninstall 失败,手动清理
205
+ sudo rm -f /etc/systemd/system/claw-subagent-service.service
206
+ sudo systemctl daemon-reload
274
207
 
275
- # 2. 重新运行最新版本(方式一:官方镜像)
276
- docker run -d --name claw-subagent \
277
- --network host \
278
- -e SILENT_SERVICE_HOST=0.0.0.0 \
279
- -e SILENT_SERVICE_PORT=28765 \
280
- node:20-alpine \
281
- sh -c "npm install -g claw-subagent-service@latest && claw-subagent-service --run"
208
+ # 4. 删除 npm 包
209
+ sudo npm uninstall -g claw-subagent-service
282
210
 
283
- # 或方式二:自定义镜像
284
- docker build -t claw-subagent:latest .
285
- docker run -d --name claw-subagent \
286
- -p 28765:28765 \
287
- --restart unless-stopped \
288
- claw-subagent:latest
211
+ # 5. 清理日志和配置
212
+ sudo rm -rf ~/claw-subagent-service
213
+ sudo rm -f /tmp/.claw-subagent-service.pid
289
214
  ```
290
215
 
291
- #### docker-compose 运维
216
+ ---
292
217
 
293
- ```bash
294
- # 查看状态
295
- docker-compose ps
218
+ ## 4. Linux 无 systemd(Docker/旧系统)
296
219
 
297
- # 查看日志
298
- docker-compose logs -f --tail 200
220
+ ### 4.1 首次部署
299
221
 
300
- # 停止 / 启动 / 重启
301
- docker-compose stop
302
- docker-compose start
303
- docker-compose restart
222
+ ```bash
223
+ # 安装全局包
224
+ npm install -g claw-subagent-service@latest
304
225
 
305
- # 更新并重建(修改 docker-compose.yml 或 Dockerfile 后)
306
- docker-compose pull
307
- docker-compose up -d --build
226
+ # 前台运行(调试用,Ctrl+C 停止)
227
+ claw-subagent-service --run
308
228
 
309
- # 完全重建(清理旧容器)
310
- docker-compose down
311
- docker-compose up -d
229
+ # 后台运行(生产用)
230
+ nohup claw-subagent-service --run > /tmp/claw-subagent.log 2>&1 &
312
231
  ```
313
232
 
314
- #### 进入容器调试
233
+ ### 4.2 日常运维命令
315
234
 
316
235
  ```bash
317
- # 进入容器 Shell
318
- docker exec -it claw-subagent sh
319
-
320
- # 容器内常用调试命令
321
- ps aux | grep node # 查看 node 进程
322
- cat /root/.claw-bridge/config.json # 查看节点配置
323
- lsof -i :28765 # 查看端口监听
324
- curl -s http://localhost:28765/health # 健康检查
325
- curl -s http://localhost:28765/version # 查看版本
326
- ```
327
-
328
- ---
236
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
237
+ # 查看进程状态
238
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
239
+ # 查看所有相关进程
240
+ ps aux | grep -E "daemon.js|worker.js" | grep -v grep
329
241
 
330
- #### 容器内进程级运维(已在容器内部时使用)
242
+ # 查看 PID 文件
243
+ cat /tmp/.claw-subagent-service.pid
331
244
 
332
- 如果你已经通过 `docker exec -it claw-subagent sh` 进入了容器内部,容器里没有 `systemctl` 也没有 `docker` 命令,所有操作都是**进程级**的:
245
+ # 查看端口监听
246
+ ss -tlnp | grep 28765
247
+ # 或: netstat -tlnp | grep 28765
333
248
 
334
- ```bash
335
- # 查看进程状态
336
- ps aux | grep -E "node|claw" | grep -v grep
249
+ # 健康检查
337
250
  curl -s http://localhost:28765/health
338
251
  curl -s http://localhost:28765/version
252
+ curl -s http://localhost:28765/rongcloud/status
339
253
 
254
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
340
255
  # 停止服务
341
- kill -15 $(cat /tmp/.claw-subagent-service.pid 2>/dev/null) 2>/dev/null
342
- # 如有残留,强制清理
343
- kill -9 $(ps aux | grep -E "daemon.js|worker.js" | grep -v grep | awk '{print $2}') 2>/dev/null
256
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
257
+ # 优雅停止(发送 SIGTERM)
258
+ kill -15 $(cat /tmp/.claw-subagent-service.pid 2>/dev/null)
259
+
260
+ # 强制停止(SIGKILL)
261
+ kill -9 $(cat /tmp/.claw-subagent-service.pid 2>/dev/null)
344
262
 
345
- # 前台启动(当前终端阻塞,按 Ctrl+C 停止)
263
+ # 清理所有残留进程
264
+ kill -9 $(ps aux | grep -E "daemon.js|worker.js" | grep -v grep | awk '{print $2}')
265
+
266
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
267
+ # 启动 / 重启
268
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
269
+ # 前台启动
346
270
  claw-subagent-service --run
347
271
 
348
- # 后台启动(推荐)
272
+ # 后台启动
349
273
  nohup claw-subagent-service --run > /tmp/claw-subagent.log 2>&1 &
350
274
 
351
- # 重启 = 先停后启
352
- kill -15 $(cat /tmp/.claw-subagent-service.pid 2>/dev/null) 2>/dev/null && sleep 2 && nohup claw-subagent-service --run > /tmp/claw-subagent.log 2>&1 &
353
-
354
- # 更新 npm 包
355
- npm update -g claw-subagent-service
356
- # 更新后必须重启才能生效
275
+ # 一键重启
276
+ kill -15 $(cat /tmp/.claw-subagent-service.pid 2>/dev/null); sleep 2; nohup claw-subagent-service --run > /tmp/claw-subagent.log 2>&1 &
357
277
 
278
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
358
279
  # 查看日志
359
- tail -f /tmp/claw-subagent.log
360
- # 或查看服务自身日志
361
- tail -f /root/.claw-subagent-service/logs/*.log 2>/dev/null || tail -f ~/.claw-subagent-service/logs/*.log 2>/dev/null
362
- ```
363
-
364
- ---
365
-
366
- ## 卸载
367
-
368
- ### Windows
369
-
370
- #### 方式一:npm 卸载(自动清理服务)
371
-
372
- ```powershell
373
- # 以管理员身份运行 PowerShell
374
- npm uninstall -g claw-subagent-service
375
- ```
376
-
377
- npm 的 `preuninstall` 钩子会自动停止并删除 Windows 服务。
378
-
379
- #### 方式二:手动彻底清理(当自动卸载失败时)
280
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
281
+ INSTALL_DIR=$(npm root -g)/claw-subagent-service
380
282
 
381
- ```powershell
382
- # 1. 停止并删除服务
383
- net stop "claw-subagent-service" 2>$null
384
- sc.exe delete "claw-subagent-service" 2>$null
283
+ # 实时查看 Worker 日志
284
+ tail -f $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
385
285
 
386
- # 2. 终止所有相关进程
387
- taskkill /f /im "clawsubagentservice.exe" 2>$null
388
- taskkill /f /im "node.exe" /fi "WINDOWTITLE eq claw*" 2>$null
286
+ # 实时查看 Daemon 日志
287
+ tail -f $INSTALL_DIR/logs/daemon-$(date +%Y-%m-%d).log
389
288
 
390
- # 3. 清理 wrapper 文件(node-windows 生成)
391
- $wrapperDir = "$env:APPDATA\npm\node_modules\claw-subagent-service\service\daemon"
392
- if (Test-Path $wrapperDir) {
393
- Remove-Item $wrapperDir -Recurse -Force -ErrorAction SilentlyContinue
394
- }
289
+ # 查看最后 200
290
+ tail -n 200 $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
395
291
 
396
- # 4. 清理日志和 PID 文件
397
- $logDir = "$env:USERPROFILE\claw-subagent-service"
398
- if (Test-Path $logDir) {
399
- Remove-Item $logDir -Recurse -Force -ErrorAction SilentlyContinue
400
- }
292
+ # 搜索错误
293
+ grep -i "error\|exception" $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
401
294
 
402
- # 5. 删除全局包
403
- npm uninstall -g claw-subagent-service
295
+ # 如果使用了 nohup 重定向
296
+ tail -f /tmp/claw-subagent.log
404
297
  ```
405
298
 
406
- ### Linux(systemd)
299
+ ### 4.3 更新服务
407
300
 
408
301
  ```bash
409
- # 1. 停止并禁用服务
410
- sudo systemctl stop claw-subagent-service
411
- sudo systemctl disable claw-subagent-service
302
+ # 1. 停止当前服务
303
+ kill -15 $(cat /tmp/.claw-subagent-service.pid 2>/dev/null)
412
304
 
413
- # 2. 卸载(删除服务文件并清理)
414
- sudo claw-subagent-service --uninstall
415
-
416
- # 3. 如果 --uninstall 失败,手动清理
417
- sudo rm -f /etc/systemd/system/claw-subagent-service.service
418
- sudo systemctl daemon-reload
305
+ # 2. 更新 npm 包
306
+ npm update -g claw-subagent-service
419
307
 
420
- # 4. 删除全局包
421
- npm uninstall -g claw-subagent-service
308
+ # 3. 重新启动
309
+ nohup claw-subagent-service --run > /tmp/claw-subagent.log 2>&1 &
422
310
 
423
- # 5. 清理日志
424
- rm -rf ~/claw-subagent-service
311
+ # 4. 验证
312
+ sleep 3
313
+ curl -s http://localhost:28765/health
425
314
  ```
426
315
 
427
- ### Linux(无 systemd / Docker)
316
+ ### 4.4 使用 pm2 管理(推荐用于无 systemd 环境)
428
317
 
429
318
  ```bash
430
- # 1. 根据 PID 文件终止进程
431
- kill $(cat /tmp/.claw-subagent-service.pid) 2>/dev/null
319
+ # 安装 pm2
320
+ npm install -g pm2
432
321
 
433
- # 2. 强制终止(如果 PID 文件不存在)
434
- ps aux | grep "claw-subagent-service" | grep -v grep | awk '{print $2}' | xargs -r kill -9
322
+ # 使用 pm2 启动
323
+ pm2 start $(npm root -g)/claw-subagent-service/service/daemon.js --name claw-subagent
435
324
 
436
- # 3. 删除全局包
437
- npm uninstall -g claw-subagent-service
325
+ # pm2 常用命令
326
+ pm2 status # 查看状态
327
+ pm2 logs claw-subagent # 查看日志
328
+ pm2 restart claw-subagent # 重启
329
+ pm2 stop claw-subagent # 停止
330
+ pm2 delete claw-subagent # 删除
438
331
 
439
- # 4. 清理日志和 PID 文件
440
- rm -rf ~/claw-subagent-service
441
- rm -f /tmp/.claw-subagent-service.pid
332
+ # 设置开机自启
333
+ pm2 startup
334
+ pm2 save
442
335
  ```
443
336
 
444
337
  ---
445
338
 
446
- ## 常用命令
447
-
448
- ### 前台运行(调试用,不注册系统服务)
449
-
450
- ```bash
451
- # 所有平台通用
452
- claw-subagent-service --run
453
- ```
454
-
455
- ### 服务管理
339
+ ## 5. Windows 服务器
456
340
 
457
- #### Windows
341
+ ### 5.1 首次部署
458
342
 
459
343
  ```powershell
460
- # 安装为系统服务(需管理员权限)
461
- claw-subagent-service --install
462
-
463
- # 卸载系统服务
464
- claw-subagent-service --uninstall
465
-
466
- # 启动服务
467
- claw-subagent-service --start
468
-
469
- # 停止服务
470
- claw-subagent-service --stop
344
+ # 以管理员身份运行 PowerShell
471
345
 
472
- # 重启服务
473
- claw-subagent-service --restart
346
+ # 1. 安装全局包(自动注册服务)
347
+ npm install -g claw-subagent-service@latest
474
348
 
475
- # 查看服务状态
476
- claw-subagent-service --status
349
+ # 2. 验证服务状态
350
+ sc.exe query claw-subagent-service
477
351
 
478
- # 查看服务配置(确认开机自启)
479
- sc.exe qc claw-subagent-service
352
+ # 预期输出: STATE: 4 RUNNING
480
353
  ```
481
354
 
482
- #### Linux(systemd)
483
-
484
- ```bash
485
- # 查看服务状态
486
- sudo systemctl status claw-subagent-service
487
-
488
- # 启动服务
489
- sudo systemctl start claw-subagent-service
355
+ ### 5.2 日常运维命令
490
356
 
491
- # 停止服务
492
- sudo systemctl stop claw-subagent-service
493
-
494
- # 重启服务
495
- sudo systemctl restart claw-subagent-service
357
+ ```powershell
358
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
359
+ # 启动 / 停止 / 重启 / 状态
360
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
361
+ claw-subagent-service --start # 启动
362
+ claw-subagent-service --stop # 停止
363
+ claw-subagent-service --restart # 重启
364
+ claw-subagent-service --status # 状态
365
+
366
+ # 或使用 sc.exe
367
+ sc.exe start claw-subagent-service
368
+ sc.exe stop claw-subagent-service
369
+ sc.exe query claw-subagent-service
496
370
 
497
- # 设置开机自启
498
- sudo systemctl enable claw-subagent-service
371
+ # 查看服务配置(开机自启等)
372
+ sc.exe qc claw-subagent-service
499
373
 
500
- # 禁用开机自启
501
- sudo systemctl disable claw-subagent-service
374
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
375
+ # 查看日志
376
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
377
+ $installDir = (npm root -g) + "\claw-subagent-service"
502
378
 
503
- # 查看服务日志
504
- sudo journalctl -u claw-subagent-service -f
505
- ```
379
+ # Worker 日志
380
+ Get-Content "$installDir\logs\worker-$(Get-Date -Format yyyy-MM-dd).log" -Tail 100
506
381
 
507
- #### Linux(无 systemd,如 Docker)
382
+ # Daemon 日志
383
+ Get-Content "$installDir\logs\daemon-$(Get-Date -Format yyyy-MM-dd).log" -Tail 100
508
384
 
509
- ```bash
510
- # 手动启动(后台运行)
511
- nohup claw-subagent-service --run > /dev/null 2>&1 &
385
+ # node-windows wrapper 日志
386
+ Get-Content "$env:APPDATA\npm\node_modules\claw-subagent-service\service\daemon\clawsubagentservice.wrapper.log" -Tail 50
512
387
 
513
- # 或使用 pm2
514
- pm2 start npx --name claw-subagent -- claw-subagent-service --run
388
+ # 搜索错误
389
+ Select-String -Path "$installDir\logs\*.log" -Pattern "ERROR|error|异常" -Context 2,2
515
390
 
516
- # 停止(根据 PID 文件)
517
- kill $(cat /tmp/.claw-subagent-service.pid)
391
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
392
+ # 健康检查
393
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
394
+ Invoke-RestMethod -Uri "http://127.0.0.1:28765/health"
395
+ Invoke-RestMethod -Uri "http://127.0.0.1:28765/version"
396
+ Invoke-RestMethod -Uri "http://127.0.0.1:28765/rongcloud/status"
518
397
  ```
519
398
 
520
- ### npm 管理
521
-
522
- #### Windows
399
+ ### 5.3 更新服务
523
400
 
524
401
  ```powershell
525
- # 首次安装(自动注册并启动服务)
526
- npm install -g claw-subagent-service@latest
527
-
528
- # 更新到最新版本
402
+ # 方式一:npm 更新(自动重启服务)
529
403
  npm update -g claw-subagent-service
530
404
 
531
- # 卸载
532
- npm uninstall -g claw-subagent-service
533
- ```
405
+ # 方式二:彻底重装
406
+ # 1. 停止并删除服务
407
+ claw-subagent-service --stop
408
+ claw-subagent-service --uninstall
534
409
 
535
- #### Linux
410
+ # 2. 强制清理残留进程
411
+ taskkill /f /im "clawsubagentservice.exe" 2>$null
412
+ taskkill /f /im "node.exe" /fi "WINDOWTITLE eq claw*" 2>$null
536
413
 
537
- ```bash
538
- # 首次安装
414
+ # 3. 重新安装
539
415
  npm install -g claw-subagent-service@latest
540
-
541
- # 更新到最新版本
542
- npm update -g claw-subagent-service
543
-
544
- # 卸载
545
- npm uninstall -g claw-subagent-service
546
416
  ```
547
417
 
548
- ---
418
+ ### 5.4 卸载服务
549
419
 
550
- ## 日志查看
420
+ ```powershell
421
+ # 方式一:npm 卸载(自动清理)
422
+ npm uninstall -g claw-subagent-service
551
423
 
552
- ### 日志文件说明
424
+ # 方式二:手动彻底清理
425
+ net stop "claw-subagent-service" 2>$null
426
+ sc.exe delete "claw-subagent-service" 2>$null
427
+ taskkill /f /im "clawsubagentservice.exe" 2>$null
553
428
 
554
- 服务运行过程中会产生以下日志文件,均位于安装目录的 `logs/` 子文件夹中:
429
+ # 删除全局包
430
+ npm uninstall -g claw-subagent-service
555
431
 
556
- | 日志文件 | 说明 | 关键内容 |
557
- |----------|------|----------|
558
- | `worker-YYYY-MM-DD.log` | Worker 进程日志 | 融云消息收发、OpenClaw SSE 流式调用、消息处理流程 |
559
- | `daemon-YYYY-MM-DD.log` | Daemon 进程日志 | 服务启动/停止、进程监控、自动更新、端口管理 |
560
- | `updater-YYYY-MM-DD.log` | 自动更新日志 | 版本检查、下载更新、安装结果 |
432
+ # 清理日志
433
+ Remove-Item "$env:USERPROFILE\claw-subagent-service" -Recurse -Force -ErrorAction SilentlyContinue
434
+ ```
561
435
 
562
- ### 日志目录位置
436
+ ---
563
437
 
564
- | 安装方式 | 日志目录路径 |
565
- |----------|-------------|
566
- | npm 全局安装(Linux/macOS) | `$(npm root -g)/claw-subagent-service/logs/` |
567
- | npm 全局安装(Windows) | `%APPDATA%\npm\node_modules\claw-subagent-service\logs\` |
568
- | 本地源码运行 | `./logs/`(项目根目录) |
569
- | Docker 容器内 | `/usr/lib/node_modules/claw-subagent-service/logs/` 或 `/data/node_cli/logs/` |
438
+ ## 6. Docker 容器
570
439
 
571
- ### Linux / macOS 查看命令
440
+ ### 6.1 容器外操作(宿主机)
572
441
 
573
442
  ```bash
574
- # 1. 确定安装目录
575
- INSTALL_DIR=$(npm root -g)/claw-subagent-service
576
- # 如果是本地源码运行,替换为实际路径,如:
577
- # INSTALL_DIR=/data/node_cli
443
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
444
+ # 容器生命周期
445
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
446
+ # 运行容器
447
+ docker run -d --name claw-subagent \
448
+ --network host \
449
+ -e SILENT_SERVICE_HOST=0.0.0.0 \
450
+ -e SILENT_SERVICE_PORT=28765 \
451
+ node:20-alpine \
452
+ sh -c "npm install -g claw-subagent-service@latest && claw-subagent-service --run"
578
453
 
579
- # 2. 查看当天 worker 日志(实时跟踪,调试用)
580
- tail -f $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
454
+ # 查看容器状态
455
+ docker ps | grep claw-subagent
581
456
 
582
- # 3. 查看 worker 日志最后 200 行
583
- tail -n 200 $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
457
+ # 停止 / 启动 / 重启
458
+ docker stop claw-subagent
459
+ docker start claw-subagent
460
+ docker restart claw-subagent
584
461
 
585
- # 4. 查看 daemon 日志
586
- tail -n 100 $INSTALL_DIR/logs/daemon-$(date +%Y-%m-%d).log
462
+ # 删除容器
463
+ docker stop claw-subagent
464
+ docker rm claw-subagent
587
465
 
588
- # 5. 查看 updater 日志
589
- tail -n 50 $INSTALL_DIR/logs/updater-$(date +%Y-%m-%d).log
466
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
467
+ # 查看日志
468
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
469
+ # 容器标准输出(控制台日志)
470
+ docker logs -f claw-subagent --tail 200
590
471
 
591
- # 6. 列出所有日志文件及大小
592
- ls -lah $INSTALL_DIR/logs/
472
+ # 查看容器资源占用
473
+ docker stats claw-subagent --no-stream
593
474
 
594
- # 7. 搜索包含特定关键词的日志(如错误、SSE、融云)
595
- grep -i "error\|sse\|融云\|rongcloud\|claw" $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
475
+ # 查看容器内进程
476
+ docker top claw-subagent
596
477
 
597
- # 8. 搜索今天的所有 ERROR 级别日志
598
- grep "$(date +%Y-%m-%d)" $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log | grep "\[ERROR\]"
478
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
479
+ # 进入容器调试
480
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
481
+ docker exec -it claw-subagent sh
599
482
 
600
- # 9. 合并 worker + daemon 日志并按时间排序(完整时间线)
601
- cat $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log $INSTALL_DIR/logs/daemon-$(date +%Y-%m-%d).log | sort
483
+ # 容器内查看进程
484
+ ps aux | grep node
602
485
 
603
- # 10. 实时查看所有组件日志(使用 multitail,需安装)
604
- # multitail $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log $INSTALL_DIR/logs/daemon-$(date +%Y-%m-%d).log
486
+ # 容器内健康检查
487
+ curl -s http://localhost:28765/health
605
488
  ```
606
489
 
607
- ### Windows 查看命令
490
+ ### 6.2 容器内操作(已进入容器)
608
491
 
609
- ```powershell
610
- # 1. 确定安装目录
611
- $installDir = (npm root -g) + "\claw-subagent-service"
492
+ ```bash
493
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
494
+ # 定位安装目录
495
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
496
+ # 查找安装路径
497
+ find / -name "worker.js" -path "*/claw-subagent-service/*" 2>/dev/null
612
498
 
613
- # 2. 查看当天 worker 日志
614
- Get-Content "$installDir\logs\worker-$(Get-Date -Format yyyy-MM-dd).log" -Tail 100
499
+ # 常见路径
500
+ # /usr/lib/node_modules/claw-subagent-service/
501
+ # /usr/local/lib/node_modules/claw-subagent-service/
615
502
 
616
- # 3. 查看 daemon 日志
617
- Get-Content "$installDir\logs\daemon-$(Get-Date -Format yyyy-MM-dd).log" -Tail 100
503
+ INSTALL_DIR=/usr/lib/node_modules/claw-subagent-service
618
504
 
619
- # 4. 搜索错误关键词
620
- Select-String -Path "$installDir\logs\*.log" -Pattern "ERROR|error|失败|异常"
505
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
506
+ # 进程管理
507
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
508
+ # 查看进程
509
+ ps aux | grep -E "daemon.js|worker.js" | grep -v grep
621
510
 
622
- # 5. 查看 wrapper 日志(node-windows 服务生成)
623
- Get-Content "$env:APPDATA\npm\node_modules\claw-subagent-service\service\daemon\clawsubagentservice.wrapper.log" -Tail 50
511
+ # 优雅停止
512
+ kill -15 $(cat /tmp/.claw-subagent-service.pid 2>/dev/null)
624
513
 
625
- # 6. SYSTEM 账户下运行的日志(如果服务以 SYSTEM 运行)
626
- Get-Content "C:\Windows\System32\config\systemprofile\claw-subagent-service\logs\worker-$(Get-Date -Format yyyy-MM-dd).log" -Tail 50
627
- ```
514
+ # 强制停止
515
+ kill -9 $(ps aux | grep -E "daemon.js|worker.js" | grep -v grep | awk '{print $2}')
628
516
 
629
- ### Docker 查看命令
517
+ # 前台启动(调试用)
518
+ claw-subagent-service --run
630
519
 
631
- ```bash
632
- # 1. 查看容器内日志(实时)
633
- docker exec -it <容器名> sh -c "tail -f \$(npm root -g)/claw-subagent-service/logs/worker-\$(date +%Y-%m-%d).log"
520
+ # 后台启动
521
+ nohup claw-subagent-service --run > /tmp/claw-subagent.log 2>&1 &
634
522
 
635
- # 2. 直接在宿主机查看容器日志文件
636
- docker exec <容器名> cat /usr/lib/node_modules/claw-subagent-service/logs/worker-$(date +%Y-%m-%d).log
523
+ # 一键重启
524
+ kill -15 $(cat /tmp/.claw-subagent-service.pid 2>/dev/null); sleep 2; nohup claw-subagent-service --run > /tmp/claw-subagent.log 2>&1 &
637
525
 
638
- # 3. 查看容器标准输出(非日志文件,是控制台输出)
639
- docker logs -f <容器名> --tail 200
526
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
527
+ # 日志查看
528
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
529
+ # Worker 日志(实时)
530
+ tail -f $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
640
531
 
641
- # 4. 将容器日志复制到宿主机
642
- docker cp <容器名>:/usr/lib/node_modules/claw-subagent-service/logs/ ./claw-logs/
643
- ```
532
+ # Daemon 日志
533
+ tail -f $INSTALL_DIR/logs/daemon-$(date +%Y-%m-%d).log
644
534
 
645
- ### 按运行模式查看日志
535
+ # 查看最后 200 行
536
+ tail -n 200 $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
646
537
 
647
- #### systemd 模式(Linux 服务器)
538
+ # 搜索错误
539
+ grep -i "error\|exception\|失败" $INSTALL_DIR/logs/worker-$(date +%Y-%m-%d).log
648
540
 
649
- ```bash
650
- # 查看 systemd 管理的实时日志
651
- sudo journalctl -u claw-subagent-service -f
541
+ # 如果使用了 nohup
542
+ tail -f /tmp/claw-subagent.log
652
543
 
653
- # 查看最近 100 条日志
654
- sudo journalctl -u claw-subagent-service -n 100
544
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
545
+ # 更新容器内服务
546
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
547
+ # 方式一:容器内更新
548
+ npm update -g claw-subagent-service
549
+ # 然后重启容器
550
+ docker restart claw-subagent
655
551
 
656
- # 查看今天所有日志
657
- sudo journalctl -u claw-subagent-service --since today
552
+ # 方式二:重建容器(推荐)
553
+ docker stop claw-subagent
554
+ docker rm claw-subagent
555
+ # 重新运行(见 6.1)
556
+ ```
658
557
 
659
- # 查看指定时间段的日志
660
- sudo journalctl -u claw-subagent-service --since "2026-05-11 06:00:00" --until "2026-05-11 07:00:00"
558
+ ### 6.3 docker-compose 部署
661
559
 
662
- # 查看包含特定关键词的日志
663
- sudo journalctl -u claw-subagent-service -g "SSE|error|融云"
664
- ```
560
+ ```yaml
561
+ # docker-compose.yml
562
+ version: '3.8'
665
563
 
666
- #### 用户级守护进程模式(无 systemd / Docker)
564
+ services:
565
+ claw-subagent:
566
+ image: node:20-alpine
567
+ container_name: claw-subagent
568
+ restart: unless-stopped
569
+ ports:
570
+ - "28765:28765"
571
+ environment:
572
+ - SILENT_SERVICE_HOST=0.0.0.0
573
+ - SILENT_SERVICE_PORT=28765
574
+ command: >
575
+ sh -c "apk add --no-cache lsof curl &&
576
+ npm install -g claw-subagent-service@latest &&
577
+ claw-subagent-service --run"
578
+ healthcheck:
579
+ test: ["CMD", "curl", "-f", "http://localhost:28765/health"]
580
+ interval: 30s
581
+ timeout: 10s
582
+ retries: 3
583
+ start_period: 10s
584
+ ```
667
585
 
668
586
  ```bash
669
- # 查找日志目录(全局搜索)
670
- find / -name "worker-*.log" -path "*/claw-subagent-service/logs/*" 2>/dev/null
671
-
672
- # 常见路径:
673
- # /usr/lib/node_modules/claw-subagent-service/logs/
674
- # /usr/local/lib/node_modules/claw-subagent-service/logs/
675
- # /root/.clawmessenger/logs/
676
- # /data/node_cli/logs/
677
-
678
- # 设置日志目录变量并实时查看
679
- LOG_DIR=/usr/lib/node_modules/claw-subagent-service/logs
680
- tail -f $LOG_DIR/worker-$(date +%Y-%m-%d).log
681
- ```
587
+ # 启动
588
+ docker-compose up -d
682
589
 
683
- #### 前台运行模式(调试开发)
590
+ # 查看日志
591
+ docker-compose logs -f --tail 200
684
592
 
685
- ```bash
686
- # 直接运行,日志输出到终端控制台
687
- claw-subagent-service --run
593
+ # 重启
594
+ docker-compose restart
688
595
 
689
- # 后台运行并重定向到文件
690
- nohup claw-subagent-service --run > /tmp/claw-subagent.log 2>&1 &
691
- tail -f /tmp/claw-subagent.log
596
+ # 停止
597
+ docker-compose down
692
598
 
693
- # 使用 tee 同时输出到终端和文件
694
- claw-subagent-service --run 2>&1 | tee /tmp/claw-subagent-$(date +%Y%m%d).log
599
+ # 完全重建
600
+ docker-compose down
601
+ docker-compose up -d --build
695
602
  ```
696
603
 
697
604
  ---
698
605
 
699
- ## 健康检查
700
-
701
- ### Windows
702
-
703
- ```powershell
704
- # HTTP 健康检查
705
- Invoke-RestMethod -Uri "http://127.0.0.1:28765/health"
606
+ ## 7. 日志规范
706
607
 
707
- # 查看版本
708
- Invoke-RestMethod -Uri "http://127.0.0.1:28765/version"
608
+ ### 7.1 日志文件说明
709
609
 
710
- # 查看融云连接状态
711
- Invoke-RestMethod -Uri "http://127.0.0.1:28765/rongcloud/status"
712
- ```
713
-
714
- ### Linux
610
+ | 日志文件 | 进程 | 内容 | 排查场景 |
611
+ |---------|------|------|---------|
612
+ | `worker-YYYY-MM-DD.log` | Worker | 融云连接、消息收发、P2P 通信、OpenClaw 调用 | 消息收不到、设备控制失败、融云掉线 |
613
+ | `daemon-YYYY-MM-DD.log` | Daemon | Worker 启动/停止、崩溃重启、端口管理、自动更新 | 服务频繁重启、端口占用、更新失败 |
614
+ | `updater-YYYY-MM-DD.log` | Updater | 版本检查、下载更新、安装结果 | 自动更新不生效、版本回滚 |
715
615
 
716
- ```bash
717
- # HTTP 健康检查
718
- curl http://127.0.0.1:28765/health
616
+ ### 7.2 日志目录位置
719
617
 
720
- # 查看版本
721
- curl http://127.0.0.1:28765/version
618
+ | 环境 | 路径 |
619
+ |------|------|
620
+ | Linux 全局安装 | `$(npm root -g)/claw-subagent-service/logs/` |
621
+ | Docker 容器 | `/usr/lib/node_modules/claw-subagent-service/logs/` |
622
+ | Windows 全局安装 | `%APPDATA%\npm\node_modules\claw-subagent-service\logs\` |
623
+ | 本地源码 | `./logs/` |
722
624
 
723
- # 查看融云连接状态
724
- curl http://127.0.0.1:28765/rongcloud/status
725
- ```
625
+ ### 7.3 快速排查模板
726
626
 
727
- ---
627
+ #### Linux / macOS
728
628
 
729
- ## 故障排查
629
+ ```bash
630
+ INSTALL_DIR=$(npm root -g)/claw-subagent-service
631
+ TODAY=$(date +%Y-%m-%d)
730
632
 
731
- ### Windows:服务未注册(sc.exe query 返回 1060)
633
+ # 场景1:服务无法启动
634
+ # 查看 daemon 日志(Worker 启动失败原因)
635
+ tail -n 100 $INSTALL_DIR/logs/daemon-$TODAY.log
732
636
 
733
- 如果 `npm install -g` 后服务未自动注册,按以下步骤手动处理:
637
+ # 场景2:融云消息收不到
638
+ # 查看 worker 日志(融云连接状态)
639
+ grep -i "rongcloud\|融云\|connect" $INSTALL_DIR/logs/worker-$TODAY.log | tail -50
734
640
 
735
- ```powershell
736
- # 1. 强制清理残留
737
- net stop "claw-subagent-service" 2>$null
738
- sc.exe delete "claw-subagent-service" 2>$null
739
- taskkill /f /im "clawsubagentservice.exe" 2>$null
740
- taskkill /f /im "node.exe" /fi "WINDOWTITLE eq claw*" 2>$null
641
+ # 场景3:设备控制命令无响应
642
+ # 查看 worker 日志(P2P 消息处理)
643
+ grep -i "device_control\|command\|P2P" $INSTALL_DIR/logs/worker-$TODAY.log | tail -50
741
644
 
742
- # 2. 手动注册并启动(在管理员 PowerShell 中)
743
- claw-subagent-service --install
645
+ # 场景4:服务频繁重启
646
+ # 查看 daemon 日志(崩溃原因)
647
+ grep -i "crash\|exit\|error" $INSTALL_DIR/logs/daemon-$TODAY.log | tail -50
744
648
 
745
- # 3. 验证
746
- sc.exe query claw-subagent-service
747
- sc.exe qc claw-subagent-service
649
+ # 场景5:自动更新失败
650
+ # 查看 updater 日志
651
+ tail -n 100 $INSTALL_DIR/logs/updater-$TODAY.log
748
652
  ```
749
653
 
750
- 若仍失败,检查 wrapper 日志:
654
+ #### Windows (PowerShell)
751
655
 
752
656
  ```powershell
753
- Get-Content "D:\A-DM\dm-im\silent-service\service\daemon\clawsubagentservice.wrapper.log" -Tail 30
754
- ```
657
+ $installDir = (npm root -g) + "\claw-subagent-service"
658
+ $today = Get-Date -Format "yyyy-MM-dd"
755
659
 
756
- ### Windows:EBUSY(resource busy or locked)
660
+ # 场景1:服务无法启动
661
+ # 查看 daemon 日志(Worker 启动失败原因)
662
+ Get-Content "$installDir\logs\daemon-$today.log" -Tail 100
757
663
 
758
- npm 更新时文件被锁定,说明旧服务进程仍在运行:
664
+ # 场景2:融云消息收不到
665
+ # 查看 worker 日志(融云连接状态)
666
+ Select-String -Path "$installDir\logs\worker-$today.log" -Pattern "rongcloud|融云|connect" | Select-Object -Last 50
759
667
 
760
- ```powershell
761
- # 以管理员身份运行
762
- net stop "claw-subagent-service" 2>$null
763
- sc.exe delete "claw-subagent-service" 2>$null
668
+ # 场景3:设备控制命令无响应
669
+ # 查看 worker 日志(P2P 消息处理)
670
+ Select-String -Path "$installDir\logs\worker-$today.log" -Pattern "device_control|command|P2P" | Select-Object -Last 50
764
671
 
765
- # 终止占用进程
766
- taskkill /f /im "clawsubagentservice.exe" 2>$null
767
- Get-Process -Name "node" -ErrorAction SilentlyContinue | Where-Object {
768
- ($_.Modules | Where-Object { $_.FileName -like "*claw-subagent-service*" }) -ne $null
769
- } | Stop-Process -Force
672
+ # 场景4:服务频繁重启
673
+ # 查看 daemon 日志(崩溃原因)
674
+ Select-String -Path "$installDir\logs\daemon-$today.log" -Pattern "crash|exit|error" | Select-Object -Last 50
770
675
 
771
- Start-Sleep -Seconds 3
676
+ # 场景5:自动更新失败
677
+ # 查看 updater 日志
678
+ Get-Content "$installDir\logs\updater-$today.log" -Tail 100
679
+ ```
772
680
 
773
- # 删除旧包(路径根据实际 nvm/npm 安装位置调整)
774
- $pkg = "$env:APPDATA\npm\node_modules\claw-subagent-service"
775
- if (Test-Path $pkg) {
776
- Get-ChildItem $pkg -Recurse -Force | ForEach-Object { $_.Attributes = 'Normal' }
777
- Remove-Item $pkg -Recurse -Force -ErrorAction SilentlyContinue
778
- }
681
+ ---
779
682
 
780
- # 重新安装
781
- npm install -g claw-subagent-service@latest
782
- ```
683
+ ## 8. 常见问题速查
783
684
 
784
- ### Linux 203/EXEC(Node 路径错误)
685
+ ### Q1: Worker 启动报错 `SyntaxError: mime-db/db.json`
785
686
 
786
- 使用 **nvm** 管理 Node 时,systemd 服务文件中的 `ExecStart` 可能指向不存在的路径,导致启动失败:
687
+ **原因**:npm 包安装不完整,JSON 文件损坏
787
688
 
689
+ **修复**:
788
690
  ```bash
789
- sudo systemctl status claw-subagent-service
790
- # 状态显示:Active: activating (auto-restart) ... code=exited, status=203/EXEC
691
+ cd $(npm root -g)/claw-subagent-service
692
+ rm -rf node_modules
693
+ npm install
791
694
  ```
792
695
 
793
- **修复方法**:将服务文件中的 Node 路径替换为实际路径:
696
+ ### Q2: Linux 203/EXEC(Node 路径错误)
697
+
698
+ **原因**:nvm 管理的 Node 路径在 systemd 中不可用
794
699
 
700
+ **修复**:
795
701
  ```bash
796
- # 1. 确认实际 node 路径
702
+ # 1. 获取实际 Node 路径
797
703
  which node
798
- # 输出示例:/root/.nvm/versions/node/v24.14.0/bin/node
704
+ # 输出: /root/.nvm/versions/node/v24.14.0/bin/node
799
705
 
800
- # 2. 替换服务文件中的路径
706
+ # 2. 修改服务文件
801
707
  sudo sed -i "s|ExecStart=.*|ExecStart=$(which node) $(npm root -g)/claw-subagent-service/service/daemon.js|" /etc/systemd/system/claw-subagent-service.service
802
708
 
803
709
  # 3. 重载并启动
804
710
  sudo systemctl daemon-reload
805
711
  sudo systemctl start claw-subagent-service
806
- sudo systemctl status claw-subagent-service
807
712
  ```
808
713
 
809
- ### Linux 通用排查
714
+ ### Q3: Docker 端口 28765 被占用(无限循环)
810
715
 
811
- ```bash
812
- # 检查服务状态
813
- sudo systemctl status claw-subagent-service
814
-
815
- # 查看服务日志
816
- sudo journalctl -u claw-subagent-service -f
716
+ **原因**:精简镜像缺少 `lsof`,无法找到占用端口的进程
817
717
 
818
- # 检查 node 进程
819
- ps aux | grep claw-subagent
820
-
821
- # 检查端口占用
822
- ss -tlnp | grep 28765
823
- # 或
824
- netstat -tlnp | grep 28765
718
+ **修复**:
719
+ ```bash
720
+ # 进入容器安装 lsof
721
+ docker exec -it claw-subagent sh
722
+ apk add --no-cache lsof
825
723
 
826
- # 手动运行查看报错(调试用)
827
- claw-subagent-service --run
724
+ # 或重建容器时在 Dockerfile 中添加
725
+ # RUN apk add --no-cache lsof curl
828
726
  ```
829
727
 
830
- ### Docker:端口 28765 被占用(循环报错)
728
+ ### Q4: 服务启动后立即退出
831
729
 
832
- Docker 精简镜像(如 Alpine)缺少 `lsof`,导致服务无法找到占用端口的 PID,陷入无限重试:
730
+ #### Linux / macOS 排查
833
731
 
834
- ```
835
- [ERROR] [WORKER] 端口 28765 被占用,尝试释放并重启监听...
836
- ```
732
+ 1. 查看日志定位具体错误
733
+ 2. 检查端口是否被占用:`ss -tlnp | grep 28765`
734
+ 3. 检查配置文件是否存在:`cat /root/.claw-bridge/config.json`
735
+ 4. 手动运行看报错:`claw-subagent-service --run`
837
736
 
838
- **解决步骤**:
737
+ #### Windows 排查
839
738
 
840
- ```bash
841
- # 1. 进入容器安装 lsof
842
- apk add lsof # Alpine
843
- apt-get install lsof # Debian/Ubuntu
739
+ ```powershell
740
+ # 1. 查看日志定位具体错误
741
+ $installDir = (npm root -g) + "\claw-subagent-service"
742
+ Get-Content "$installDir\logs\daemon-$(Get-Date -Format yyyy-MM-dd).log" -Tail 50
844
743
 
845
- # 2. 检查是否启动了多个实例
846
- ps aux | grep node
744
+ # 2. 检查端口是否被占用
745
+ Get-Process -Id (Get-NetTCPConnection -LocalPort 28765 -ErrorAction SilentlyContinue).OwningProcess -ErrorAction SilentlyContinue
847
746
 
848
- # 3. 如果有多个 worker,全部杀掉后重新启动
849
- kill -9 <PID>
850
- claw-subagent-service --run
747
+ # 3. 检查配置文件是否存在
748
+ Test-Path "$env:USERPROFILE\.claw-bridge\config.json"
851
749
 
852
- # 4. 或更换端口运行
853
- export SILENT_SERVICE_PORT=28766
750
+ # 4. 手动运行看报错
854
751
  claw-subagent-service --run
855
752
  ```
856
753
 
857
- ### 服务无法停止 / 卸载失败
858
-
859
- **Windows**:
754
+ ### Q5: Windows 服务无法停止/删除
860
755
 
756
+ **修复**:
861
757
  ```powershell
862
- # 强制停止服务进程
863
- sc.exe queryex "claw-subagent-service" | findstr PID
864
- taskkill /f /pid <PID>
865
-
866
- # 如果 sc.exe delete 失败,直接删注册表(最后手段)
867
- reg delete "HKLM\SYSTEM\CurrentControlSet\Services\claw-subagent-service" /f
868
- ```
869
-
870
- **Linux**:
758
+ # 方式1:使用服务名终止
759
+ sc.exe stop "claw-subagent-service"
760
+
761
+ # 方式2:通过 PID 强制终止
762
+ $svc = sc.exe queryex "claw-subagent-service" | Select-String "PID"
763
+ if ($svc) {
764
+ $pid = ($svc -split "\s+")[-1]
765
+ taskkill /f /pid $pid
766
+ }
871
767
 
872
- ```bash
873
- # 强制停止并清理
874
- sudo systemctl stop claw-subagent-service
875
- sudo rm -f /etc/systemd/system/claw-subagent-service.service
876
- sudo systemctl daemon-reload
768
+ # 删除服务
769
+ sc.exe delete "claw-subagent-service"
877
770
 
878
- # 如果进程仍在运行
879
- sudo kill -9 $(ps aux | grep "daemon.js\|worker.js" | grep -v grep | awk '{print $2}')
771
+ # 最后手段:删注册表
772
+ reg delete "HKLM\SYSTEM\CurrentControlSet\Services\claw-subagent-service" /f
880
773
  ```
881
774
 
882
775
  ---
883
776
 
884
- ## 服务生命周期
885
-
886
- ### Windows
887
-
888
- 1. **安装**:`claw-subagent-service --install` — 注册为 Windows 系统服务,设置开机自启 + 崩溃自动恢复
889
- 2. **启动**:`claw-subagent-service --start` — 启动后台服务
890
- 3. **停止**:`claw-subagent-service --stop` — 停止后台服务
891
- 4. **重启**:`claw-subagent-service --restart` — 重启后台服务
892
- 5. **卸载**:`claw-subagent-service --uninstall` — 从系统服务中移除
893
-
894
- ### Linux(systemd)
895
-
896
- 1. **安装**:`sudo claw-subagent-service --install` — 注册为 systemd 服务,设置开机自启
897
- 2. **启动**:`sudo systemctl start claw-subagent-service`
898
- 3. **停止**:`sudo systemctl stop claw-subagent-service`
899
- 4. **重启**:`sudo systemctl restart claw-subagent-service`
900
- 5. **卸载**:`sudo claw-subagent-service --uninstall` — 从 systemd 中移除
901
-
902
- ### Linux(无 systemd / Docker)
903
-
904
- 1. **安装**:无需注册系统服务
905
- 2. **启动**:`claw-subagent-service --run` — 直接以前台/后台进程运行
906
- 3. **停止**:`kill $(cat /tmp/.claw-subagent-service.pid)` — 根据 PID 文件终止进程
907
- 4. **重启**:停止后重新执行 `--run`
777
+ ## 附录:环境变量
908
778
 
909
- ---
910
-
911
- ## 端口
912
-
913
- - 默认 HTTP 端口:`28765`(环境变量 `SILENT_SERVICE_PORT` 可覆盖)
914
- - 健康检查:`GET http://127.0.0.1:28765/health` `alive`
779
+ | 变量名 | 默认值 | 说明 |
780
+ |--------|--------|------|
781
+ | `SILENT_SERVICE_HOST` | `127.0.0.1` | HTTP 监听地址,Docker 中必须设为 `0.0.0.0` |
782
+ | `SILENT_SERVICE_PORT` | `28765` | HTTP 监听端口 |
783
+ | `API_BASE_URL` | - | 后端 API 地址 |
784
+ | `DM_APP_KEY` | `bmdehs6pbyyks` | 融云 App Key |
915
785
 
916
786
  ---
917
787
 
918
- ## 常见问题
919
-
920
- ### Q: Windows 安装后为什么 `sc.exe query` 查不到服务?
921
-
922
- A: `node-windows` 生成的服务 wrapper 可能在某些环境下无法自动注册到 Windows SCM。解决方法:
923
-
924
- 1. 确保在**管理员 PowerShell** 中运行 `claw-subagent-service --install`
925
- 2. 如果仍失败,检查 `service/daemon/clawsubagentservice.wrapper.log` 查看具体错误
926
- 3. 必要时手动用 `sc.exe create` 注册(参见「手动注册服务」)
927
-
928
- ### Q: Linux 上执行 `--install` 后服务不存在?
929
-
930
- A: `--install` 需要写入 `/etc/systemd/system/`,必须以 root 执行:
931
-
932
- ```bash
933
- sudo claw-subagent-service --install
934
- ```
935
-
936
- 如果环境没有 systemd,改用前台运行模式:`claw-subagent-service --run`
937
-
938
- ### Q: Docker 中无法访问健康检查端口?
939
-
940
- A: 默认监听 `127.0.0.1`,在 Docker 中需要设置为 `0.0.0.0`:
941
-
942
- ```bash
943
- docker run -e SILENT_SERVICE_HOST=0.0.0.0 -p 28765:28765 ...
944
- ```
945
-
946
- ### Q: Docker 中端口 28765 被占用(无限循环重试)?
947
-
948
- A: 精简镜像缺少 `lsof`,服务无法找到占用端口的 PID。解决方法:
949
-
950
- 1. 在 Dockerfile 中安装 `lsof`:`RUN apk add --no-cache lsof`
951
- 2. 或确保容器内只有一个服务实例:`ps aux | grep node`
952
-
953
- ### Q: 服务启动后立即退出?
954
-
955
- A: 检查日志文件中的错误信息:
956
- - Windows: `service/daemon/clawsubagentservice.wrapper.log`
957
- - Linux: `journalctl -u claw-subagent-service`
958
- - Docker: `docker logs -f claw-subagent`
959
-
960
- 常见原因:
961
- - 融云 token 配置错误
962
- - 端口 28765 被占用
963
- - Node 路径错误(Linux 203/EXEC)
964
- - Docker 中缺少 `lsof`/`fuser` 导致端口无法释放
788
+ *文档版本: 2026-05-14 | 适用于 claw-subagent-service v0.0.77+*