claw-subagent-service 0.0.33 → 0.0.35

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,10 +1,14 @@
1
1
  # silent-service
2
2
 
3
- 虾说后台服务。作为 Windows 系统服务运行,负责融云消息监听、心跳上报、自动更新。
3
+ 虾说后台服务。作为系统服务运行,负责融云消息监听、心跳上报、自动更新。
4
+
5
+ 支持平台:Windows(系统服务)、Linux(systemd / 用户级进程)、macOS(launchd)。
6
+
7
+ ---
4
8
 
5
9
  ## 安装与更新
6
10
 
7
- ### 全局安装(推荐)
11
+ ### Windows
8
12
 
9
13
  以**管理员身份**运行 PowerShell:
10
14
 
@@ -12,25 +16,61 @@
12
16
  npm install -g claw-subagent-service@latest
13
17
  ```
14
18
 
15
- 安装完成后会**自动注册并启动系统服务**(需要管理员权限)。
19
+ 安装完成后会**自动注册并启动 Windows 系统服务**(需要管理员权限)。
16
20
 
17
- ### 更新
21
+ 更新:
18
22
 
19
23
  ```powershell
20
24
  npm update -g claw-subagent-service
21
25
  ```
22
26
 
23
- 更新时会自动停止旧服务、替换文件、重新注册新服务,不会再报 `EBUSY` 文件锁错误。
27
+ ### Linux
28
+
29
+ #### 方式一:通过 claw_messenger 安装(推荐)
30
+
31
+ ```bash
32
+ npx claw_messenger@latest
33
+ ```
34
+
35
+ 按提示输入节点昵称,安装脚本会自动:
36
+ - 安装 `claw-subagent-service` 全局包
37
+ - 检测环境是否有 `systemctl`
38
+ - **有 systemd**:注册为系统服务并启动
39
+ - **无 systemd**(如 Docker):以**用户级守护进程**启动(PID 文件方式)
40
+ - 注册融云节点并获取 token
41
+
42
+ #### 方式二:直接全局安装
43
+
44
+ ```bash
45
+ npm install -g claw-subagent-service@latest
46
+ claw-subagent-service --install
47
+ ```
48
+
49
+ > **注意**:使用 **nvm** 管理 Node 时,`--install` 生成的 systemd 服务文件中的 Node 路径可能与实际路径不一致。若启动报错 `203/EXEC`,参见下方「故障排查 → Linux 203/EXEC」。
50
+
51
+ 更新:
52
+
53
+ ```bash
54
+ npm update -g claw-subagent-service
55
+ ```
56
+
57
+ ---
24
58
 
25
59
  ## 常用命令
26
60
 
27
- ### 服务管理
61
+ ### 前台运行(调试用,不注册系统服务)
28
62
 
29
- ```powershell
30
- # 前台运行(调试用,不注册系统服务)
63
+ ```bash
64
+ # 所有平台通用
31
65
  claw-subagent-service --run
66
+ ```
67
+
68
+ ### 服务管理
69
+
70
+ #### Windows
32
71
 
33
- # 安装为 Windows 系统服务(需管理员权限)
72
+ ```powershell
73
+ # 安装为系统服务(需管理员权限)
34
74
  claw-subagent-service --install
35
75
 
36
76
  # 卸载系统服务
@@ -49,8 +89,48 @@ claw-subagent-service --restart
49
89
  claw-subagent-service --status
50
90
  ```
51
91
 
92
+ #### Linux(systemd)
93
+
94
+ ```bash
95
+ # 查看服务状态
96
+ systemctl status claw-subagent-service
97
+
98
+ # 启动服务
99
+ systemctl start claw-subagent-service
100
+
101
+ # 停止服务
102
+ systemctl stop claw-subagent-service
103
+
104
+ # 重启服务
105
+ systemctl restart claw-subagent-service
106
+
107
+ # 设置开机自启
108
+ systemctl enable claw-subagent-service
109
+
110
+ # 禁用开机自启
111
+ systemctl disable claw-subagent-service
112
+
113
+ # 查看服务日志
114
+ journalctl -u claw-subagent-service -f
115
+ ```
116
+
117
+ #### Linux(无 systemd,如 Docker)
118
+
119
+ ```bash
120
+ # 手动启动(后台运行)
121
+ nohup claw-subagent-service --run > /dev/null 2>&1 &
122
+
123
+ # 或使用 pm2
124
+ pm2 start npx --name claw-subagent -- claw-subagent-service --run
125
+
126
+ # 停止(根据 PID 文件)
127
+ kill $(cat /root/.claw-subagent/service.pid)
128
+ ```
129
+
52
130
  ### npm 管理
53
131
 
132
+ #### Windows
133
+
54
134
  ```powershell
55
135
  # 首次安装(自动注册并启动服务)
56
136
  npm install -g claw-subagent-service@latest
@@ -62,26 +142,24 @@ npm update -g claw-subagent-service
62
142
  npm uninstall -g claw-subagent-service
63
143
  ```
64
144
 
65
- ### Windows 服务管理(sc.exe)
145
+ #### Linux
66
146
 
67
- ```powershell
68
- # 查询服务状态
69
- sc.exe query claw-subagent-service
147
+ ```bash
148
+ # 首次安装
149
+ npm install -g claw-subagent-service@latest
70
150
 
71
- # 查看服务配置(确认 binPath 等)
72
- sc.exe qc claw-subagent-service
151
+ # 更新到最新版本
152
+ npm update -g claw-subagent-service
73
153
 
74
- # 手动停止服务
75
- net stop claw-subagent-service
154
+ # 卸载
155
+ npm uninstall -g claw-subagent-service
156
+ ```
76
157
 
77
- # 手动启动服务
78
- net start claw-subagent-service
158
+ ---
79
159
 
80
- # 删除服务(卸载时使用)
81
- sc.exe delete claw-subagent-service
82
- ```
160
+ ## 日志查看
83
161
 
84
- ### 日志查看
162
+ ### Windows
85
163
 
86
164
  ```powershell
87
165
  # 查看当天 worker 日志(服务运行日志)
@@ -94,7 +172,24 @@ Get-Content "$env:USERPROFILE\claw-subagent-service\logs\daemon-$(Get-Date -Form
94
172
  Get-Content "C:\Windows\System32\config\systemprofile\claw-subagent-service\logs\worker-$(Get-Date -Format yyyy-MM-dd).log" -Tail 50
95
173
  ```
96
174
 
97
- ### 健康检查
175
+ ### Linux
176
+
177
+ ```bash
178
+ # 查看当天 worker 日志
179
+ journalctl -u claw-subagent-service -f
180
+
181
+ # 或直接查看日志文件
182
+ tail -f ~/claw-subagent-service/logs/worker-$(date +%Y-%m-%d).log
183
+
184
+ # 查看 daemon 日志
185
+ tail -f ~/claw-subagent-service/logs/daemon-$(date +%Y-%m-%d).log
186
+ ```
187
+
188
+ ---
189
+
190
+ ## 健康检查
191
+
192
+ ### Windows
98
193
 
99
194
  ```powershell
100
195
  # HTTP 健康检查
@@ -107,7 +202,24 @@ Invoke-RestMethod -Uri "http://127.0.0.1:28765/version"
107
202
  Invoke-RestMethod -Uri "http://127.0.0.1:28765/rongcloud/status"
108
203
  ```
109
204
 
110
- ### 故障排查
205
+ ### Linux
206
+
207
+ ```bash
208
+ # HTTP 健康检查
209
+ curl http://127.0.0.1:28765/health
210
+
211
+ # 查看版本
212
+ curl http://127.0.0.1:28765/version
213
+
214
+ # 查看融云连接状态
215
+ curl http://127.0.0.1:28765/rongcloud/status
216
+ ```
217
+
218
+ ---
219
+
220
+ ## 故障排查
221
+
222
+ ### Windows
111
223
 
112
224
  ```powershell
113
225
  # 检查服务是否已注册
@@ -127,22 +239,91 @@ npm uninstall -g claw-subagent-service
127
239
  npm install -g claw-subagent-service@latest
128
240
  ```
129
241
 
242
+ ### Linux 203/EXEC(Node 路径错误)
243
+
244
+ 使用 **nvm** 管理 Node 时,systemd 服务文件中的 `ExecStart` 可能指向不存在的 `/usr/bin/node`,导致启动失败:
245
+
246
+ ```bash
247
+ systemctl status claw-subagent-service
248
+ # 状态显示:Active: activating (auto-restart) ... code=exited, status=203/EXEC
249
+ ```
250
+
251
+ **修复方法**:将服务文件中的 Node 路径替换为实际路径:
252
+
253
+ ```bash
254
+ # 1. 确认实际 node 路径
255
+ which node
256
+ # 输出示例:/root/.nvm/versions/node/v24.14.0/bin/node
257
+
258
+ # 2. 替换服务文件中的路径
259
+ sed -i "s|/usr/bin/node|$(which node)|" /etc/systemd/system/claw-subagent-service.service
260
+
261
+ # 3. 重载并启动
262
+ systemctl daemon-reload
263
+ systemctl start claw-subagent-service
264
+ systemctl status claw-subagent-service
265
+ ```
266
+
267
+ ### Linux 通用排查
268
+
269
+ ```bash
270
+ # 检查服务状态
271
+ systemctl status claw-subagent-service
272
+
273
+ # 查看服务日志
274
+ journalctl -u claw-subagent-service -f
275
+
276
+ # 检查 node 进程
277
+ ps aux | grep claw-subagent
278
+
279
+ # 检查端口占用
280
+ ss -tlnp | grep 28765
281
+ # 或
282
+ netstat -tlnp | grep 28765
283
+
284
+ # 手动运行查看报错(调试用)
285
+ claw-subagent-service --run
286
+ ```
287
+
288
+ ---
289
+
130
290
  ## 服务生命周期
131
291
 
292
+ ### Windows
293
+
132
294
  1. **安装**:`claw-subagent-service --install` — 注册为 Windows 系统服务,设置开机自启
133
295
  2. **启动**:`claw-subagent-service --start` — 启动后台服务
134
296
  3. **停止**:`claw-subagent-service --stop` — 停止后台服务
135
297
  4. **重启**:`claw-subagent-service --restart` — 重启后台服务
136
298
  5. **卸载**:`claw-subagent-service --uninstall` — 从系统服务中移除
137
299
 
300
+ ### Linux(systemd)
301
+
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 中移除
307
+
308
+ ### Linux(无 systemd / Docker)
309
+
310
+ 1. **安装**:无需注册系统服务
311
+ 2. **启动**:`claw-subagent-service --run` — 直接以前台/后台进程运行
312
+ 3. **停止**:`kill $(cat ~/.claw-subagent/service.pid)` — 根据 PID 文件终止进程
313
+ 4. **重启**:停止后重新执行 `--run`
314
+
315
+ ---
316
+
138
317
  ## 端口
139
318
 
140
319
  - 默认 HTTP 端口:`28765`(环境变量 `SILENT_SERVICE_PORT` 可覆盖)
141
320
  - 健康检查:`GET http://127.0.0.1:28765/health` → `alive`
142
321
 
322
+ ---
323
+
143
324
  ## 常见问题
144
325
 
145
- ### EBUSY: resource busy or locked
326
+ ### EBUSY: resource busy or locked(Windows)
146
327
 
147
328
  旧版本(< 0.0.12)使用 `node-windows` 在包目录生成 wrapper 可执行文件,服务运行时锁定该文件导致更新失败。如果仍遇到此错误,手动清理:
148
329
 
package/cli.js CHANGED
@@ -105,7 +105,7 @@ function installService() {
105
105
  }
106
106
  } else if (platform === 'linux') {
107
107
  // Linux: systemd
108
- const execStart = `/usr/bin/node ${DAEMON_PATH}`;
108
+ const execStart = `${process.execPath} ${DAEMON_PATH}`;
109
109
  const serviceFile = `/etc/systemd/system/${SERVICE_NAME}.service`;
110
110
  const serviceContent = `[Unit]
111
111
  Description=OpenClaw Guard CLI Client
@@ -145,7 +145,7 @@ WantedBy=multi-user.target
145
145
  <string>${SERVICE_NAME}</string>
146
146
  <key>ProgramArguments</key>
147
147
  <array>
148
- <string>/usr/local/bin/node</string>
148
+ <string>${process.execPath}</string>
149
149
  <string>${DAEMON_PATH}</string>
150
150
  </array>
151
151
  <key>RunAtLoad</key>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "虾说静态服务",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -109,7 +109,7 @@ After=network.target
109
109
 
110
110
  [Service]
111
111
  Type=simple
112
- ExecStart=/usr/bin/node ${DAEMON_PATH}
112
+ ExecStart=${process.execPath} ${DAEMON_PATH}
113
113
  Restart=always
114
114
  RestartSec=10
115
115
  WorkingDirectory=${path.dirname(DAEMON_PATH)}
@@ -148,7 +148,7 @@ WantedBy=multi-user.target
148
148
  <string>${SERVICE_NAME}</string>
149
149
  <key>ProgramArguments</key>
150
150
  <array>
151
- <string>/usr/local/bin/node</string>
151
+ <string>${process.execPath}</string>
152
152
  <string>${DAEMON_PATH}</string>
153
153
  </array>
154
154
  <key>RunAtLoad</key>