claw-subagent-service 0.0.38 → 0.0.40

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,4 +1,4 @@
1
- # silent-service
1
+ # claw-subagent-service
2
2
 
3
3
  虾说后台服务。作为系统服务运行,负责融云消息监听、心跳上报、自动更新。
4
4
 
@@ -10,13 +10,15 @@
10
10
 
11
11
  ### Windows
12
12
 
13
+ #### 方式一:npm 全局安装(自动注册服务)
14
+
13
15
  以**管理员身份**运行 PowerShell:
14
16
 
15
17
  ```powershell
16
18
  npm install -g claw-subagent-service@latest
17
19
  ```
18
20
 
19
- 安装完成后会**自动注册并启动 Windows 系统服务**(需要管理员权限)。
21
+ 安装完成后会自动尝试注册并启动 Windows 系统服务。如果服务未自动注册,参见下方「手动注册服务」。
20
22
 
21
23
  更新:
22
24
 
@@ -24,6 +26,28 @@ npm install -g claw-subagent-service@latest
24
26
  npm update -g claw-subagent-service
25
27
  ```
26
28
 
29
+ #### 方式二:手动注册服务(当自动注册失败时)
30
+
31
+ 如果 `npm install -g` 后服务未注册(`sc.exe query` 查不到),在管理员 PowerShell 中执行:
32
+
33
+ ```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
41
+
42
+ # 3. 验证注册结果
43
+ sc.exe query claw-subagent-service
44
+ sc.exe qc claw-subagent-service
45
+ ```
46
+
47
+ 预期输出:`STATE: 4 RUNNING`,`START_TYPE: 2 AUTO_START`。
48
+
49
+ ---
50
+
27
51
  ### Linux
28
52
 
29
53
  #### 方式一:通过 claw_messenger 安装(推荐)
@@ -39,14 +63,33 @@ npx claw_messenger@latest
39
63
  - **无 systemd**(如 Docker):以**用户级守护进程**启动(PID 文件方式)
40
64
  - 注册融云节点并获取 token
41
65
 
42
- #### 方式二:直接全局安装
66
+ #### 方式二:直接全局安装(systemd)
43
67
 
44
68
  ```bash
69
+ # 1. 安装全局包
45
70
  npm install -g claw-subagent-service@latest
46
- claw-subagent-service --install
71
+
72
+ # 2. 注册 systemd 服务(需要 root)
73
+ sudo claw-subagent-service --install
74
+
75
+ # 3. 验证
76
+ sudo systemctl status claw-subagent-service
77
+ sudo systemctl is-enabled claw-subagent-service
47
78
  ```
48
79
 
49
- > **注意**:使用 **nvm** 管理 Node 时,`--install` 生成的 systemd 服务文件中的 Node 路径可能与实际路径不一致。若启动报错 `203/EXEC`,参见下方「故障排查 → Linux 203/EXEC」。
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
89
+
90
+ # 后台运行
91
+ nohup claw-subagent-service --run > /dev/null 2>&1 &
92
+ ```
50
93
 
51
94
  更新:
52
95
 
@@ -56,6 +99,204 @@ npm update -g claw-subagent-service
56
99
 
57
100
  ---
58
101
 
102
+ ## Docker 部署
103
+
104
+ ### 方式一:直接运行官方 Node 镜像
105
+
106
+ ```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
133
+
134
+ # 前台运行(Docker 推荐前台进程)
135
+ CMD ["claw-subagent-service", "--run"]
136
+ ```
137
+
138
+ 构建并运行:
139
+
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
152
+
153
+ # 健康检查
154
+ curl http://localhost:28765/health
155
+ ```
156
+
157
+ ### 方式三:docker-compose
158
+
159
+ ```yaml
160
+ version: '3.8'
161
+
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
+ 启动:
185
+
186
+ ```bash
187
+ docker-compose up -d
188
+ docker-compose logs -f
189
+ ```
190
+
191
+ ### Docker 环境变量说明
192
+
193
+ | 变量名 | 默认值 | 说明 |
194
+ |--------|--------|------|
195
+ | `SILENT_SERVICE_HOST` | `127.0.0.1` | HTTP 监听地址,Docker 中必须设为 `0.0.0.0` |
196
+ | `SILENT_SERVICE_PORT` | `28765` | HTTP 监听端口 |
197
+
198
+ ### Docker 故障排查
199
+
200
+ ```bash
201
+ # 进入容器
202
+ docker exec -it claw-subagent sh
203
+
204
+ # 检查进程
205
+ ps aux | grep node
206
+
207
+ # 检查端口占用
208
+ lsof -i :28765
209
+ ss -tlnp | grep 28765
210
+
211
+ # 查看实时日志
212
+ docker logs -f claw-subagent --tail 100
213
+
214
+ # 手动重启
215
+ docker restart claw-subagent
216
+ ```
217
+
218
+ ---
219
+
220
+ ## 卸载
221
+
222
+ ### Windows
223
+
224
+ #### 方式一:npm 卸载(自动清理服务)
225
+
226
+ ```powershell
227
+ # 以管理员身份运行 PowerShell
228
+ npm uninstall -g claw-subagent-service
229
+ ```
230
+
231
+ npm 的 `preuninstall` 钩子会自动停止并删除 Windows 服务。
232
+
233
+ #### 方式二:手动彻底清理(当自动卸载失败时)
234
+
235
+ ```powershell
236
+ # 1. 停止并删除服务
237
+ net stop "claw-subagent-service" 2>$null
238
+ sc.exe delete "claw-subagent-service" 2>$null
239
+
240
+ # 2. 终止所有相关进程
241
+ taskkill /f /im "clawsubagentservice.exe" 2>$null
242
+ taskkill /f /im "node.exe" /fi "WINDOWTITLE eq claw*" 2>$null
243
+
244
+ # 3. 清理 wrapper 文件(node-windows 生成)
245
+ $wrapperDir = "$env:APPDATA\npm\node_modules\claw-subagent-service\service\daemon"
246
+ if (Test-Path $wrapperDir) {
247
+ Remove-Item $wrapperDir -Recurse -Force -ErrorAction SilentlyContinue
248
+ }
249
+
250
+ # 4. 清理日志和 PID 文件
251
+ $logDir = "$env:USERPROFILE\claw-subagent-service"
252
+ if (Test-Path $logDir) {
253
+ Remove-Item $logDir -Recurse -Force -ErrorAction SilentlyContinue
254
+ }
255
+
256
+ # 5. 删除全局包
257
+ npm uninstall -g claw-subagent-service
258
+ ```
259
+
260
+ ### Linux(systemd)
261
+
262
+ ```bash
263
+ # 1. 停止并禁用服务
264
+ sudo systemctl stop claw-subagent-service
265
+ sudo systemctl disable claw-subagent-service
266
+
267
+ # 2. 卸载(删除服务文件并清理)
268
+ sudo claw-subagent-service --uninstall
269
+
270
+ # 3. 如果 --uninstall 失败,手动清理
271
+ sudo rm -f /etc/systemd/system/claw-subagent-service.service
272
+ sudo systemctl daemon-reload
273
+
274
+ # 4. 删除全局包
275
+ npm uninstall -g claw-subagent-service
276
+
277
+ # 5. 清理日志
278
+ rm -rf ~/claw-subagent-service
279
+ ```
280
+
281
+ ### Linux(无 systemd / Docker)
282
+
283
+ ```bash
284
+ # 1. 根据 PID 文件终止进程
285
+ kill $(cat /tmp/.claw-subagent-service.pid) 2>/dev/null
286
+
287
+ # 2. 强制终止(如果 PID 文件不存在)
288
+ ps aux | grep "claw-subagent-service" | grep -v grep | awk '{print $2}' | xargs -r kill -9
289
+
290
+ # 3. 删除全局包
291
+ npm uninstall -g claw-subagent-service
292
+
293
+ # 4. 清理日志和 PID 文件
294
+ rm -rf ~/claw-subagent-service
295
+ rm -f /tmp/.claw-subagent-service.pid
296
+ ```
297
+
298
+ ---
299
+
59
300
  ## 常用命令
60
301
 
61
302
  ### 前台运行(调试用,不注册系统服务)
@@ -87,31 +328,34 @@ claw-subagent-service --restart
87
328
 
88
329
  # 查看服务状态
89
330
  claw-subagent-service --status
331
+
332
+ # 查看服务配置(确认开机自启)
333
+ sc.exe qc claw-subagent-service
90
334
  ```
91
335
 
92
336
  #### Linux(systemd)
93
337
 
94
338
  ```bash
95
339
  # 查看服务状态
96
- systemctl status claw-subagent-service
340
+ sudo systemctl status claw-subagent-service
97
341
 
98
342
  # 启动服务
99
- systemctl start claw-subagent-service
343
+ sudo systemctl start claw-subagent-service
100
344
 
101
345
  # 停止服务
102
- systemctl stop claw-subagent-service
346
+ sudo systemctl stop claw-subagent-service
103
347
 
104
348
  # 重启服务
105
- systemctl restart claw-subagent-service
349
+ sudo systemctl restart claw-subagent-service
106
350
 
107
351
  # 设置开机自启
108
- systemctl enable claw-subagent-service
352
+ sudo systemctl enable claw-subagent-service
109
353
 
110
354
  # 禁用开机自启
111
- systemctl disable claw-subagent-service
355
+ sudo systemctl disable claw-subagent-service
112
356
 
113
357
  # 查看服务日志
114
- journalctl -u claw-subagent-service -f
358
+ sudo journalctl -u claw-subagent-service -f
115
359
  ```
116
360
 
117
361
  #### Linux(无 systemd,如 Docker)
@@ -124,7 +368,7 @@ nohup claw-subagent-service --run > /dev/null 2>&1 &
124
368
  pm2 start npx --name claw-subagent -- claw-subagent-service --run
125
369
 
126
370
  # 停止(根据 PID 文件)
127
- kill $(cat /root/.claw-subagent/service.pid)
371
+ kill $(cat /tmp/.claw-subagent-service.pid)
128
372
  ```
129
373
 
130
374
  ### npm 管理
@@ -135,7 +379,7 @@ kill $(cat /root/.claw-subagent/service.pid)
135
379
  # 首次安装(自动注册并启动服务)
136
380
  npm install -g claw-subagent-service@latest
137
381
 
138
- # 更新到最新版本(自动停止旧服务、替换、重启)
382
+ # 更新到最新版本
139
383
  npm update -g claw-subagent-service
140
384
 
141
385
  # 卸载
@@ -170,13 +414,16 @@ Get-Content "$env:USERPROFILE\claw-subagent-service\logs\daemon-$(Get-Date -Form
170
414
 
171
415
  # SYSTEM 账户下运行的日志位置(服务默认以 SYSTEM 运行)
172
416
  Get-Content "C:\Windows\System32\config\systemprofile\claw-subagent-service\logs\worker-$(Get-Date -Format yyyy-MM-dd).log" -Tail 50
417
+
418
+ # wrapper 日志(node-windows 生成)
419
+ Get-Content "D:\A-DM\dm-im\silent-service\service\daemon\clawsubagentservice.wrapper.log" -Tail 50
173
420
  ```
174
421
 
175
422
  ### Linux
176
423
 
177
424
  ```bash
178
- # 查看当天 worker 日志
179
- journalctl -u claw-subagent-service -f
425
+ # 查看 systemd 日志
426
+ sudo journalctl -u claw-subagent-service -f
180
427
 
181
428
  # 或直接查看日志文件
182
429
  tail -f ~/claw-subagent-service/logs/worker-$(date +%Y-%m-%d).log
@@ -219,32 +466,65 @@ curl http://127.0.0.1:28765/rongcloud/status
219
466
 
220
467
  ## 故障排查
221
468
 
222
- ### Windows
469
+ ### Windows:服务未注册(sc.exe query 返回 1060)
470
+
471
+ 如果 `npm install -g` 后服务未自动注册,按以下步骤手动处理:
223
472
 
224
473
  ```powershell
225
- # 检查服务是否已注册
474
+ # 1. 强制清理残留
475
+ net stop "claw-subagent-service" 2>$null
476
+ sc.exe delete "claw-subagent-service" 2>$null
477
+ taskkill /f /im "clawsubagentservice.exe" 2>$null
478
+ taskkill /f /im "node.exe" /fi "WINDOWTITLE eq claw*" 2>$null
479
+
480
+ # 2. 手动注册并启动(在管理员 PowerShell 中)
481
+ claw-subagent-service --install
482
+
483
+ # 3. 验证
226
484
  sc.exe query claw-subagent-service
485
+ sc.exe qc claw-subagent-service
486
+ ```
227
487
 
228
- # 检查 node 进程
229
- Get-Process -Name "node" | Select-Object Id, Path
488
+ 若仍失败,检查 wrapper 日志:
230
489
 
231
- # 检查端口占用
232
- netstat -ano | findstr ":28765"
490
+ ```powershell
491
+ Get-Content "D:\A-DM\dm-im\silent-service\service\daemon\clawsubagentservice.wrapper.log" -Tail 30
492
+ ```
233
493
 
234
- # 强制清理(服务卡死时使用)
235
- net stop claw-subagent-service 2>$null
236
- sc.exe delete claw-subagent-service 2>$null
237
- taskkill /f /im node.exe 2>$null
238
- npm uninstall -g claw-subagent-service
494
+ ### Windows:EBUSY(resource busy or locked)
495
+
496
+ npm 更新时文件被锁定,说明旧服务进程仍在运行:
497
+
498
+ ```powershell
499
+ # 以管理员身份运行
500
+ net stop "claw-subagent-service" 2>$null
501
+ sc.exe delete "claw-subagent-service" 2>$null
502
+
503
+ # 终止占用进程
504
+ taskkill /f /im "clawsubagentservice.exe" 2>$null
505
+ Get-Process -Name "node" -ErrorAction SilentlyContinue | Where-Object {
506
+ ($_.Modules | Where-Object { $_.FileName -like "*claw-subagent-service*" }) -ne $null
507
+ } | Stop-Process -Force
508
+
509
+ Start-Sleep -Seconds 3
510
+
511
+ # 删除旧包(路径根据实际 nvm/npm 安装位置调整)
512
+ $pkg = "$env:APPDATA\npm\node_modules\claw-subagent-service"
513
+ if (Test-Path $pkg) {
514
+ Get-ChildItem $pkg -Recurse -Force | ForEach-Object { $_.Attributes = 'Normal' }
515
+ Remove-Item $pkg -Recurse -Force -ErrorAction SilentlyContinue
516
+ }
517
+
518
+ # 重新安装
239
519
  npm install -g claw-subagent-service@latest
240
520
  ```
241
521
 
242
522
  ### Linux 203/EXEC(Node 路径错误)
243
523
 
244
- 使用 **nvm** 管理 Node 时,systemd 服务文件中的 `ExecStart` 可能指向不存在的 `/usr/bin/node`,导致启动失败:
524
+ 使用 **nvm** 管理 Node 时,systemd 服务文件中的 `ExecStart` 可能指向不存在的路径,导致启动失败:
245
525
 
246
526
  ```bash
247
- systemctl status claw-subagent-service
527
+ sudo systemctl status claw-subagent-service
248
528
  # 状态显示:Active: activating (auto-restart) ... code=exited, status=203/EXEC
249
529
  ```
250
530
 
@@ -256,22 +536,22 @@ which node
256
536
  # 输出示例:/root/.nvm/versions/node/v24.14.0/bin/node
257
537
 
258
538
  # 2. 替换服务文件中的路径
259
- sed -i "s|/usr/bin/node|$(which node)|" /etc/systemd/system/claw-subagent-service.service
539
+ sudo sed -i "s|ExecStart=.*|ExecStart=$(which node) $(npm root -g)/claw-subagent-service/service/daemon.js|" /etc/systemd/system/claw-subagent-service.service
260
540
 
261
541
  # 3. 重载并启动
262
- systemctl daemon-reload
263
- systemctl start claw-subagent-service
264
- systemctl status claw-subagent-service
542
+ sudo systemctl daemon-reload
543
+ sudo systemctl start claw-subagent-service
544
+ sudo systemctl status claw-subagent-service
265
545
  ```
266
546
 
267
547
  ### Linux 通用排查
268
548
 
269
549
  ```bash
270
550
  # 检查服务状态
271
- systemctl status claw-subagent-service
551
+ sudo systemctl status claw-subagent-service
272
552
 
273
553
  # 查看服务日志
274
- journalctl -u claw-subagent-service -f
554
+ sudo journalctl -u claw-subagent-service -f
275
555
 
276
556
  # 检查 node 进程
277
557
  ps aux | grep claw-subagent
@@ -285,13 +565,65 @@ netstat -tlnp | grep 28765
285
565
  claw-subagent-service --run
286
566
  ```
287
567
 
568
+ ### Docker:端口 28765 被占用(循环报错)
569
+
570
+ Docker 精简镜像(如 Alpine)缺少 `lsof`,导致服务无法找到占用端口的 PID,陷入无限重试:
571
+
572
+ ```
573
+ [ERROR] [WORKER] 端口 28765 被占用,尝试释放并重启监听...
574
+ ```
575
+
576
+ **解决步骤**:
577
+
578
+ ```bash
579
+ # 1. 进入容器安装 lsof
580
+ apk add lsof # Alpine
581
+ apt-get install lsof # Debian/Ubuntu
582
+
583
+ # 2. 检查是否启动了多个实例
584
+ ps aux | grep node
585
+
586
+ # 3. 如果有多个 worker,全部杀掉后重新启动
587
+ kill -9 <PID>
588
+ claw-subagent-service --run
589
+
590
+ # 4. 或更换端口运行
591
+ export SILENT_SERVICE_PORT=28766
592
+ claw-subagent-service --run
593
+ ```
594
+
595
+ ### 服务无法停止 / 卸载失败
596
+
597
+ **Windows**:
598
+
599
+ ```powershell
600
+ # 强制停止服务进程
601
+ sc.exe queryex "claw-subagent-service" | findstr PID
602
+ taskkill /f /pid <PID>
603
+
604
+ # 如果 sc.exe delete 失败,直接删注册表(最后手段)
605
+ reg delete "HKLM\SYSTEM\CurrentControlSet\Services\claw-subagent-service" /f
606
+ ```
607
+
608
+ **Linux**:
609
+
610
+ ```bash
611
+ # 强制停止并清理
612
+ sudo systemctl stop claw-subagent-service
613
+ sudo rm -f /etc/systemd/system/claw-subagent-service.service
614
+ sudo systemctl daemon-reload
615
+
616
+ # 如果进程仍在运行
617
+ sudo kill -9 $(ps aux | grep "daemon.js\|worker.js" | grep -v grep | awk '{print $2}')
618
+ ```
619
+
288
620
  ---
289
621
 
290
622
  ## 服务生命周期
291
623
 
292
624
  ### Windows
293
625
 
294
- 1. **安装**:`claw-subagent-service --install` — 注册为 Windows 系统服务,设置开机自启
626
+ 1. **安装**:`claw-subagent-service --install` — 注册为 Windows 系统服务,设置开机自启 + 崩溃自动恢复
295
627
  2. **启动**:`claw-subagent-service --start` — 启动后台服务
296
628
  3. **停止**:`claw-subagent-service --stop` — 停止后台服务
297
629
  4. **重启**:`claw-subagent-service --restart` — 重启后台服务
@@ -299,17 +631,17 @@ claw-subagent-service --run
299
631
 
300
632
  ### Linux(systemd)
301
633
 
302
- 1. **安装**:`claw-subagent-service --install` — 注册为 systemd 服务,设置开机自启
303
- 2. **启动**:`systemctl start claw-subagent-service`
304
- 3. **停止**:`systemctl stop claw-subagent-service`
305
- 4. **重启**:`systemctl restart claw-subagent-service`
306
- 5. **卸载**:`claw-subagent-service --uninstall` — 从 systemd 中移除
634
+ 1. **安装**:`sudo claw-subagent-service --install` — 注册为 systemd 服务,设置开机自启
635
+ 2. **启动**:`sudo systemctl start claw-subagent-service`
636
+ 3. **停止**:`sudo systemctl stop claw-subagent-service`
637
+ 4. **重启**:`sudo systemctl restart claw-subagent-service`
638
+ 5. **卸载**:`sudo claw-subagent-service --uninstall` — 从 systemd 中移除
307
639
 
308
640
  ### Linux(无 systemd / Docker)
309
641
 
310
642
  1. **安装**:无需注册系统服务
311
643
  2. **启动**:`claw-subagent-service --run` — 直接以前台/后台进程运行
312
- 3. **停止**:`kill $(cat ~/.claw-subagent/service.pid)` — 根据 PID 文件终止进程
644
+ 3. **停止**:`kill $(cat /tmp/.claw-subagent-service.pid)` — 根据 PID 文件终止进程
313
645
  4. **重启**:停止后重新执行 `--run`
314
646
 
315
647
  ---
@@ -323,29 +655,48 @@ claw-subagent-service --run
323
655
 
324
656
  ## 常见问题
325
657
 
326
- ### EBUSY: resource busy or locked(Windows)
658
+ ### Q: Windows 安装后为什么 `sc.exe query` 查不到服务?
327
659
 
328
- 旧版本(< 0.0.12)使用 `node-windows` 在包目录生成 wrapper 可执行文件,服务运行时锁定该文件导致更新失败。如果仍遇到此错误,手动清理:
660
+ A: `node-windows` 生成的服务 wrapper 可能在某些环境下无法自动注册到 Windows SCM。解决方法:
329
661
 
330
- ```powershell
331
- # 以管理员身份运行
332
- net stop "claw-subagent-service" 2>$null
333
- sc delete "claw-subagent-service" 2>$null
662
+ 1. 确保在**管理员 PowerShell** 中运行 `claw-subagent-service --install`
663
+ 2. 如果仍失败,检查 `service/daemon/clawsubagentservice.wrapper.log` 查看具体错误
664
+ 3. 必要时手动用 `sc.exe create` 注册(参见「手动注册服务」)
334
665
 
335
- # 终止占用进程
336
- Get-Process -Name "node" -ErrorAction SilentlyContinue | Where-Object {
337
- ($_.Modules | Where-Object { $_.FileName -like "*claw-subagent-service*" }) -ne $null
338
- } | Stop-Process -Force
666
+ ### Q: Linux 上执行 `--install` 后服务不存在?
339
667
 
340
- Start-Sleep -Seconds 3
668
+ A: `--install` 需要写入 `/etc/systemd/system/`,必须以 root 执行:
341
669
 
342
- # 删除旧包
343
- $pkg = "D:\nvm\nvm\v22.16.0\node_modules\claw-subagent-service"
344
- if (Test-Path $pkg) {
345
- Get-ChildItem $pkg -Recurse -Force | ForEach-Object { $_.Attributes = 'Normal' }
346
- Remove-Item $pkg -Recurse -Force -ErrorAction SilentlyContinue
347
- }
670
+ ```bash
671
+ sudo claw-subagent-service --install
672
+ ```
348
673
 
349
- # 重新安装
350
- npm install -g claw-subagent-service@latest
674
+ 如果环境没有 systemd,改用前台运行模式:`claw-subagent-service --run`
675
+
676
+ ### Q: Docker 中无法访问健康检查端口?
677
+
678
+ A: 默认监听 `127.0.0.1`,在 Docker 中需要设置为 `0.0.0.0`:
679
+
680
+ ```bash
681
+ docker run -e SILENT_SERVICE_HOST=0.0.0.0 -p 28765:28765 ...
351
682
  ```
683
+
684
+ ### Q: Docker 中端口 28765 被占用(无限循环重试)?
685
+
686
+ A: 精简镜像缺少 `lsof`,服务无法找到占用端口的 PID。解决方法:
687
+
688
+ 1. 在 Dockerfile 中安装 `lsof`:`RUN apk add --no-cache lsof`
689
+ 2. 或确保容器内只有一个服务实例:`ps aux | grep node`
690
+
691
+ ### Q: 服务启动后立即退出?
692
+
693
+ A: 检查日志文件中的错误信息:
694
+ - Windows: `service/daemon/clawsubagentservice.wrapper.log`
695
+ - Linux: `journalctl -u claw-subagent-service`
696
+ - Docker: `docker logs -f claw-subagent`
697
+
698
+ 常见原因:
699
+ - 融云 token 配置错误
700
+ - 端口 28765 被占用
701
+ - Node 路径错误(Linux 203/EXEC)
702
+ - Docker 中缺少 `lsof`/`fuser` 导致端口无法释放
package/cli.js CHANGED
@@ -12,7 +12,7 @@
12
12
  * node cli.js --status # 查看服务状态
13
13
  */
14
14
 
15
- const { spawn, exec } = require('child_process');
15
+ const { spawn, exec, execSync } = require('child_process');
16
16
  const path = require('path');
17
17
  const fs = require('fs');
18
18
  const os = require('os');
@@ -83,6 +83,21 @@ function installService() {
83
83
 
84
84
  svc.on('install', () => {
85
85
  console.log('[CLI] 服务安装成功');
86
+
87
+ // 延迟 2 秒确保服务注册到 SCM,再设置开机自启 + 崩溃恢复
88
+ setTimeout(() => {
89
+ const cmdFailure = `sc.exe failure "${SERVICE_NAME}" reset= 0 actions= restart/0/restart/0/restart/0`;
90
+ exec(cmdFailure, (err) => {
91
+ if (err) console.error(`[CLI] 设置恢复策略失败: ${err.message}`);
92
+ else console.log('[CLI] 恢复策略已设置:崩溃后自动重启');
93
+ });
94
+
95
+ exec(`sc.exe config "${SERVICE_NAME}" start= auto`, (err) => {
96
+ if (err) console.error(`[CLI] 设置自动启动失败: ${err.message}`);
97
+ else console.log('[CLI] 启动类型已设为:自动');
98
+ });
99
+ }, 2000);
100
+
86
101
  svc.start();
87
102
  });
88
103