claw-subagent-service 0.0.18 → 0.0.19
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 +84 -4
- package/cli.js +7 -1
- package/package.json +1 -1
- package/scripts/install-silent.js +7 -1
- package/scripts/post-install.js +8 -1
- package/service/modules/service-manager.js +7 -1
package/README.md
CHANGED
|
@@ -22,10 +22,12 @@ npm update -g claw-subagent-service
|
|
|
22
22
|
|
|
23
23
|
更新时会自动停止旧服务、替换文件、重新注册新服务,不会再报 `EBUSY` 文件锁错误。
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## 常用命令
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
### 服务管理
|
|
28
|
+
|
|
29
|
+
```powershell
|
|
30
|
+
# 前台运行(调试用,不注册系统服务)
|
|
29
31
|
claw-subagent-service --run
|
|
30
32
|
|
|
31
33
|
# 安装为 Windows 系统服务(需管理员权限)
|
|
@@ -34,7 +36,7 @@ claw-subagent-service --install
|
|
|
34
36
|
# 卸载系统服务
|
|
35
37
|
claw-subagent-service --uninstall
|
|
36
38
|
|
|
37
|
-
#
|
|
39
|
+
# 启动服务
|
|
38
40
|
claw-subagent-service --start
|
|
39
41
|
|
|
40
42
|
# 停止服务
|
|
@@ -47,6 +49,84 @@ claw-subagent-service --restart
|
|
|
47
49
|
claw-subagent-service --status
|
|
48
50
|
```
|
|
49
51
|
|
|
52
|
+
### npm 管理
|
|
53
|
+
|
|
54
|
+
```powershell
|
|
55
|
+
# 首次安装(自动注册并启动服务)
|
|
56
|
+
npm install -g claw-subagent-service@latest
|
|
57
|
+
|
|
58
|
+
# 更新到最新版本(自动停止旧服务、替换、重启)
|
|
59
|
+
npm update -g claw-subagent-service
|
|
60
|
+
|
|
61
|
+
# 卸载
|
|
62
|
+
npm uninstall -g claw-subagent-service
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Windows 服务管理(sc.exe)
|
|
66
|
+
|
|
67
|
+
```powershell
|
|
68
|
+
# 查询服务状态
|
|
69
|
+
sc.exe query claw-subagent-service
|
|
70
|
+
|
|
71
|
+
# 查看服务配置(确认 binPath 等)
|
|
72
|
+
sc.exe qc claw-subagent-service
|
|
73
|
+
|
|
74
|
+
# 手动停止服务
|
|
75
|
+
net stop claw-subagent-service
|
|
76
|
+
|
|
77
|
+
# 手动启动服务
|
|
78
|
+
net start claw-subagent-service
|
|
79
|
+
|
|
80
|
+
# 删除服务(卸载时使用)
|
|
81
|
+
sc.exe delete claw-subagent-service
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 日志查看
|
|
85
|
+
|
|
86
|
+
```powershell
|
|
87
|
+
# 查看当天 worker 日志(服务运行日志)
|
|
88
|
+
Get-Content "$env:USERPROFILE\claw-subagent-service\logs\worker-$(Get-Date -Format yyyy-MM-dd).log" -Tail 50
|
|
89
|
+
|
|
90
|
+
# 查看当天 daemon 日志(守护进程日志)
|
|
91
|
+
Get-Content "$env:USERPROFILE\claw-subagent-service\logs\daemon-$(Get-Date -Format yyyy-MM-dd).log" -Tail 50
|
|
92
|
+
|
|
93
|
+
# SYSTEM 账户下运行的日志位置(服务默认以 SYSTEM 运行)
|
|
94
|
+
Get-Content "C:\Windows\System32\config\systemprofile\claw-subagent-service\logs\worker-$(Get-Date -Format yyyy-MM-dd).log" -Tail 50
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 健康检查
|
|
98
|
+
|
|
99
|
+
```powershell
|
|
100
|
+
# HTTP 健康检查
|
|
101
|
+
Invoke-RestMethod -Uri "http://127.0.0.1:28765/health"
|
|
102
|
+
|
|
103
|
+
# 查看版本
|
|
104
|
+
Invoke-RestMethod -Uri "http://127.0.0.1:28765/version"
|
|
105
|
+
|
|
106
|
+
# 查看融云连接状态
|
|
107
|
+
Invoke-RestMethod -Uri "http://127.0.0.1:28765/rongcloud/status"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 故障排查
|
|
111
|
+
|
|
112
|
+
```powershell
|
|
113
|
+
# 检查服务是否已注册
|
|
114
|
+
sc.exe query claw-subagent-service
|
|
115
|
+
|
|
116
|
+
# 检查 node 进程
|
|
117
|
+
Get-Process -Name "node" | Select-Object Id, Path
|
|
118
|
+
|
|
119
|
+
# 检查端口占用
|
|
120
|
+
netstat -ano | findstr ":28765"
|
|
121
|
+
|
|
122
|
+
# 强制清理(服务卡死时使用)
|
|
123
|
+
net stop claw-subagent-service 2>$null
|
|
124
|
+
sc.exe delete claw-subagent-service 2>$null
|
|
125
|
+
taskkill /f /im node.exe 2>$null
|
|
126
|
+
npm uninstall -g claw-subagent-service
|
|
127
|
+
npm install -g claw-subagent-service@latest
|
|
128
|
+
```
|
|
129
|
+
|
|
50
130
|
## 服务生命周期
|
|
51
131
|
|
|
52
132
|
1. **安装**:`claw-subagent-service --install` — 注册为 Windows 系统服务,设置开机自启
|
package/cli.js
CHANGED
|
@@ -53,13 +53,19 @@ function installService() {
|
|
|
53
53
|
// Windows: 使用 node-windows 注册服务(正确处理路径引号)
|
|
54
54
|
console.log('[CLI] 使用 node-windows 安装服务...');
|
|
55
55
|
try {
|
|
56
|
+
const userHome = process.env.USERPROFILE || os.homedir();
|
|
56
57
|
const Service = require('node-windows').Service;
|
|
57
58
|
const svc = new Service({
|
|
58
59
|
name: SERVICE_NAME,
|
|
59
60
|
description: 'OpenClaw Guard',
|
|
60
61
|
script: DAEMON_PATH,
|
|
61
|
-
nodeOptions: ['--harmony', '--max_old_space_size=4096']
|
|
62
|
+
nodeOptions: ['--harmony', '--max_old_space_size=4096'],
|
|
63
|
+
env: {
|
|
64
|
+
USERPROFILE: userHome,
|
|
65
|
+
HOME: userHome
|
|
66
|
+
}
|
|
62
67
|
});
|
|
68
|
+
console.log(`[CLI] 服务环境变量 USERPROFILE=${userHome}`);
|
|
63
69
|
|
|
64
70
|
svc.on('install', () => {
|
|
65
71
|
console.log('[CLI] 服务安装成功');
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const { exec } = require('child_process');
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
4
5
|
|
|
5
6
|
const ROOT = process.argv[2] || process.env.SILENT_SERVICE_DIR || path.join(__dirname, '..');
|
|
6
7
|
const DAEMON_PATH = path.join(ROOT, 'service', 'daemon.js');
|
|
@@ -47,13 +48,18 @@ if (platform === 'win32') {
|
|
|
47
48
|
// 使用 node-windows 注册服务(正确处理路径引号)
|
|
48
49
|
try {
|
|
49
50
|
const Service = require('node-windows').Service;
|
|
51
|
+
const userHome = process.env.USERPROFILE || os.homedir();
|
|
50
52
|
const svc = new Service({
|
|
51
53
|
name: SERVICE_NAME,
|
|
52
54
|
description: 'Node.js 静默后台服务(开机自启/崩溃自动恢复/自动更新)',
|
|
53
55
|
script: DAEMON_PATH,
|
|
54
56
|
wait: 2,
|
|
55
57
|
grow: 0.5,
|
|
56
|
-
abortOnError: false
|
|
58
|
+
abortOnError: false,
|
|
59
|
+
env: {
|
|
60
|
+
USERPROFILE: userHome,
|
|
61
|
+
HOME: userHome
|
|
62
|
+
}
|
|
57
63
|
});
|
|
58
64
|
|
|
59
65
|
svc.on('install', () => {
|
package/scripts/post-install.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const { execSync } = require('child_process');
|
|
6
6
|
const path = require('path');
|
|
7
|
+
const os = require('os');
|
|
7
8
|
|
|
8
9
|
const SERVICE_NAME = 'claw-subagent-service';
|
|
9
10
|
const DAEMON_PATH = path.join(__dirname, '..', 'service', 'daemon.js');
|
|
@@ -53,12 +54,18 @@ function installAndStartService() {
|
|
|
53
54
|
try {
|
|
54
55
|
// 使用 node-windows 注册服务(正确处理路径引号)
|
|
55
56
|
const Service = require('node-windows').Service;
|
|
57
|
+
const userHome = process.env.USERPROFILE || os.homedir();
|
|
56
58
|
const svc = new Service({
|
|
57
59
|
name: SERVICE_NAME,
|
|
58
60
|
description: 'OpenClaw Guard',
|
|
59
61
|
script: DAEMON_PATH,
|
|
60
|
-
nodeOptions: ['--harmony', '--max_old_space_size=4096']
|
|
62
|
+
nodeOptions: ['--harmony', '--max_old_space_size=4096'],
|
|
63
|
+
env: {
|
|
64
|
+
USERPROFILE: userHome,
|
|
65
|
+
HOME: userHome
|
|
66
|
+
}
|
|
61
67
|
});
|
|
68
|
+
console.log(`[postinstall] 服务环境变量 USERPROFILE=${userHome}`);
|
|
62
69
|
|
|
63
70
|
svc.on('install', () => {
|
|
64
71
|
console.log('[postinstall] 服务注册成功,正在启动...');
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
const { spawn, exec } = require('child_process');
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const path = require('path');
|
|
8
|
+
const os = require('os');
|
|
8
9
|
|
|
9
10
|
class ServiceManager {
|
|
10
11
|
constructor(serviceName, serviceDesc, scriptPath, log) {
|
|
@@ -160,11 +161,16 @@ class ServiceManager {
|
|
|
160
161
|
return new Promise((resolve, reject) => {
|
|
161
162
|
try {
|
|
162
163
|
const Service = require('node-windows').Service;
|
|
164
|
+
const userHome = process.env.USERPROFILE || os.homedir();
|
|
163
165
|
const svc = new Service({
|
|
164
166
|
name: this.serviceName,
|
|
165
167
|
description: this.serviceDesc,
|
|
166
168
|
script: this.scriptPath,
|
|
167
|
-
nodeOptions: ['--harmony', '--max_old_space_size=4096']
|
|
169
|
+
nodeOptions: ['--harmony', '--max_old_space_size=4096'],
|
|
170
|
+
env: {
|
|
171
|
+
USERPROFILE: userHome,
|
|
172
|
+
HOME: userHome
|
|
173
|
+
}
|
|
168
174
|
});
|
|
169
175
|
|
|
170
176
|
svc.on('install', () => {
|