claw-subagent-service 0.0.15 → 0.0.16
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/cli.js +5 -5
- package/package.json +1 -1
- package/scripts/install-silent.js +4 -4
- package/scripts/post-install.js +32 -6
- package/scripts/pre-uninstall.js +1 -1
- package/service/modules/service-manager.js +3 -3
- package/version.json +2 -2
package/cli.js
CHANGED
|
@@ -57,9 +57,9 @@ function installService() {
|
|
|
57
57
|
: `"${execPath}" "${DAEMON_PATH}"`;
|
|
58
58
|
|
|
59
59
|
// 先停止并删除旧服务(避免文件锁)
|
|
60
|
-
exec(`net stop "${SERVICE_NAME}" 2>nul & sc delete "${SERVICE_NAME}" 2>nul`, () => {
|
|
60
|
+
exec(`net stop "${SERVICE_NAME}" 2>nul & sc.exe delete "${SERVICE_NAME}" 2>nul`, () => {
|
|
61
61
|
// sc.exe 是 cmd 时代的工具,必须用 exec(走 cmd 解析)才能正确传递 binPath
|
|
62
|
-
const createCmd = `sc create "${SERVICE_NAME}" binPath= ${binPath} start= auto displayname= "OpenClaw Guard"`;
|
|
62
|
+
const createCmd = `sc.exe create "${SERVICE_NAME}" binPath= ${binPath} start= auto displayname= "OpenClaw Guard"`;
|
|
63
63
|
exec(createCmd, { windowsHide: true }, (err2) => {
|
|
64
64
|
if (err2) return console.error(`[CLI] 服务安装失败: ${err2.message}`);
|
|
65
65
|
console.log('[CLI] 服务安装成功');
|
|
@@ -146,8 +146,8 @@ function uninstallService() {
|
|
|
146
146
|
svc.on('uninstall', () => console.log('[CLI] 服务卸载成功'));
|
|
147
147
|
svc.uninstall();
|
|
148
148
|
} catch (err) {
|
|
149
|
-
console.log('[CLI] 使用 sc 命令卸载服务...');
|
|
150
|
-
exec(`sc stop ${SERVICE_NAME} 2>nul & sc delete ${SERVICE_NAME}`, (err2) => {
|
|
149
|
+
console.log('[CLI] 使用 sc.exe 命令卸载服务...');
|
|
150
|
+
exec(`sc.exe stop ${SERVICE_NAME} 2>nul & sc.exe delete ${SERVICE_NAME}`, (err2) => {
|
|
151
151
|
if (err2) console.error(`[CLI] 卸载失败: ${err2.message}`);
|
|
152
152
|
else console.log('[CLI] 服务卸载成功');
|
|
153
153
|
});
|
|
@@ -203,7 +203,7 @@ function checkStatus() {
|
|
|
203
203
|
let cmd;
|
|
204
204
|
|
|
205
205
|
if (platform === 'win32') {
|
|
206
|
-
cmd = `sc query ${SERVICE_NAME}`;
|
|
206
|
+
cmd = `sc.exe query ${SERVICE_NAME}`;
|
|
207
207
|
} else if (platform === 'linux') {
|
|
208
208
|
cmd = `systemctl status ${SERVICE_NAME}`;
|
|
209
209
|
} else if (platform === 'darwin') {
|
package/package.json
CHANGED
|
@@ -45,11 +45,11 @@ if (platform === 'win32') {
|
|
|
45
45
|
setTimeout(() => finish(1, '安装操作超时'), 60000);
|
|
46
46
|
|
|
47
47
|
// 先停止并删除旧服务(避免文件锁导致更新失败)
|
|
48
|
-
exec(`net stop "${SERVICE_NAME}" 2>nul & sc delete "${SERVICE_NAME}" 2>nul`, () => {
|
|
48
|
+
exec(`net stop "${SERVICE_NAME}" 2>nul & sc.exe delete "${SERVICE_NAME}" 2>nul`, () => {
|
|
49
49
|
const binPath = `"${process.execPath}" "${DAEMON_PATH}"`;
|
|
50
50
|
|
|
51
51
|
// sc.exe 是 cmd 时代的工具,必须用 exec(走 cmd 解析)才能正确传递 binPath
|
|
52
|
-
const createCmd = `sc create "${SERVICE_NAME}" binPath= ${binPath} start= auto displayname= "Node.js 静默后台服务"`;
|
|
52
|
+
const createCmd = `sc.exe create "${SERVICE_NAME}" binPath= ${binPath} start= auto displayname= "Node.js 静默后台服务"`;
|
|
53
53
|
exec(createCmd, { windowsHide: true }, (err) => {
|
|
54
54
|
if (err) {
|
|
55
55
|
log(`创建服务失败: ${err.message}`);
|
|
@@ -58,14 +58,14 @@ if (platform === 'win32') {
|
|
|
58
58
|
log('服务注册成功');
|
|
59
59
|
|
|
60
60
|
// 设置恢复策略:崩溃后自动重启
|
|
61
|
-
const recoveryCmd = `sc failure "${SERVICE_NAME}" reset= 0 actions= restart/0/restart/0/restart/0`;
|
|
61
|
+
const recoveryCmd = `sc.exe failure "${SERVICE_NAME}" reset= 0 actions= restart/0/restart/0/restart/0`;
|
|
62
62
|
exec(recoveryCmd, (err) => {
|
|
63
63
|
if (err) log(`设置恢复策略失败: ${err.message}`);
|
|
64
64
|
else log('恢复策略已设置:服务崩溃后系统自动无限重启');
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
// 设置自动启动
|
|
68
|
-
exec(`sc config "${SERVICE_NAME}" start= auto`, (err) => {
|
|
68
|
+
exec(`sc.exe config "${SERVICE_NAME}" start= auto`, (err) => {
|
|
69
69
|
if (err) log(`设置自动启动失败: ${err.message}`);
|
|
70
70
|
else log('启动类型已设为:自动');
|
|
71
71
|
});
|
package/scripts/post-install.js
CHANGED
|
@@ -15,7 +15,7 @@ function isGlobalInstall() {
|
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
// 方法2: 检查包路径是否在全局 node_modules
|
|
18
|
+
// 方法2: 检查包路径是否在全局 node_modules 下(支持 nvm)
|
|
19
19
|
try {
|
|
20
20
|
const globalRoot = execSync('npm root -g', { encoding: 'utf8', timeout: 5000 }).trim();
|
|
21
21
|
const pkgPath = path.join(__dirname, '..');
|
|
@@ -23,11 +23,37 @@ function isGlobalInstall() {
|
|
|
23
23
|
const normalizedGlobal = path.normalize(globalRoot).toLowerCase();
|
|
24
24
|
const isGlobal = normalizedPkg.startsWith(normalizedGlobal);
|
|
25
25
|
console.log(`[postinstall] 全局安装检测: pkgPath=${normalizedPkg}, globalRoot=${normalizedGlobal}, result=${isGlobal}`);
|
|
26
|
-
return
|
|
26
|
+
if (isGlobal) return true;
|
|
27
27
|
} catch (e) {
|
|
28
|
-
console.log(`[postinstall]
|
|
28
|
+
console.log(`[postinstall] npm root -g 检测失败: ${e.message}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 方法3: 检查包路径是否在 node 安装目录的 node_modules 下(nvm 场景)
|
|
32
|
+
try {
|
|
33
|
+
const nodeDir = path.dirname(process.execPath);
|
|
34
|
+
const nodeModulesDir = path.join(nodeDir, 'node_modules');
|
|
35
|
+
const pkgPath = path.join(__dirname, '..');
|
|
36
|
+
const normalizedPkg = path.normalize(pkgPath).toLowerCase();
|
|
37
|
+
const normalizedNodeModules = path.normalize(nodeModulesDir).toLowerCase();
|
|
38
|
+
const isGlobal = normalizedPkg.startsWith(normalizedNodeModules);
|
|
39
|
+
console.log(`[postinstall] nvm 检测: pkgPath=${normalizedPkg}, nodeModules=${normalizedNodeModules}, result=${isGlobal}`);
|
|
40
|
+
if (isGlobal) return true;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.log(`[postinstall] nvm 检测失败: ${e.message}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 方法4: 兜底 - 如果包在 node_modules 下且路径较深,认为是全局安装
|
|
46
|
+
const pkgPath = path.normalize(path.join(__dirname, '..')).toLowerCase();
|
|
47
|
+
const hasNodeModules = pkgPath.includes('node_modules');
|
|
48
|
+
const notInCwd = !process.cwd().toLowerCase().includes(pkgPath);
|
|
49
|
+
console.log(`[postinstall] 兜底检测: hasNodeModules=${hasNodeModules}, notInCwd=${notInCwd}`);
|
|
50
|
+
if (hasNodeModules && notInCwd) {
|
|
51
|
+
console.log('[postinstall] 兜底检测通过,按全局安装处理');
|
|
29
52
|
return true;
|
|
30
53
|
}
|
|
54
|
+
|
|
55
|
+
console.log('[postinstall] 所有检测均失败,按本地安装处理');
|
|
56
|
+
return false;
|
|
31
57
|
}
|
|
32
58
|
|
|
33
59
|
function isWindowsAdmin() {
|
|
@@ -58,10 +84,10 @@ function installAndStartService() {
|
|
|
58
84
|
|
|
59
85
|
// 先停止并删除旧服务(避免冲突)
|
|
60
86
|
try { execSync(`net stop "${SERVICE_NAME}" 2>nul`, { stdio: 'ignore', timeout: 10000 }); } catch (e) {}
|
|
61
|
-
try { execSync(`sc delete "${SERVICE_NAME}" 2>nul`, { stdio: 'ignore', timeout: 10000 }); } catch (e) {}
|
|
87
|
+
try { execSync(`sc.exe delete "${SERVICE_NAME}" 2>nul`, { stdio: 'ignore', timeout: 10000 }); } catch (e) {}
|
|
62
88
|
|
|
63
89
|
// sc.exe 是 cmd 时代的工具,必须用 exec(走 cmd 解析)才能正确传递 binPath
|
|
64
|
-
const createCmd = `sc create "${SERVICE_NAME}" binPath= ${binPath} start= auto displayname= "OpenClaw Guard"`;
|
|
90
|
+
const createCmd = `sc.exe create "${SERVICE_NAME}" binPath= ${binPath} start= auto displayname= "OpenClaw Guard"`;
|
|
65
91
|
exec(createCmd, { windowsHide: true }, (err) => {
|
|
66
92
|
if (err) {
|
|
67
93
|
console.error(`[postinstall] 注册服务失败: ${err.message}`);
|
|
@@ -70,7 +96,7 @@ function installAndStartService() {
|
|
|
70
96
|
console.log('[postinstall] 服务注册成功');
|
|
71
97
|
|
|
72
98
|
// 设置恢复策略
|
|
73
|
-
exec(`sc failure "${SERVICE_NAME}" reset= 0 actions= restart/0/restart/0/restart/0`, (err) => {
|
|
99
|
+
exec(`sc.exe failure "${SERVICE_NAME}" reset= 0 actions= restart/0/restart/0/restart/0`, (err) => {
|
|
74
100
|
if (!err) console.log('[postinstall] 恢复策略已设置');
|
|
75
101
|
});
|
|
76
102
|
|
package/scripts/pre-uninstall.js
CHANGED
|
@@ -12,7 +12,7 @@ if (process.platform === 'win32') {
|
|
|
12
12
|
execSync(`net stop "${name}" 2>nul`, { stdio: 'ignore', timeout: 10000 });
|
|
13
13
|
} catch (e) {}
|
|
14
14
|
try {
|
|
15
|
-
execSync(`sc delete "${name}" 2>nul`, { stdio: 'ignore', timeout: 10000 });
|
|
15
|
+
execSync(`sc.exe delete "${name}" 2>nul`, { stdio: 'ignore', timeout: 10000 });
|
|
16
16
|
} catch (e) {}
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -141,7 +141,7 @@ class ServiceManager {
|
|
|
141
141
|
try {
|
|
142
142
|
switch (this.platform) {
|
|
143
143
|
case 'win32':
|
|
144
|
-
return await this.execCommand(`sc query ${this.serviceName}`);
|
|
144
|
+
return await this.execCommand(`sc.exe query ${this.serviceName}`);
|
|
145
145
|
case 'linux':
|
|
146
146
|
return await this.execCommand(`systemctl status ${this.serviceName}`);
|
|
147
147
|
case 'darwin':
|
|
@@ -161,10 +161,10 @@ class ServiceManager {
|
|
|
161
161
|
|
|
162
162
|
// 先停止并删除旧服务(避免文件锁导致更新失败)
|
|
163
163
|
try { await this.execCommand(`net stop "${this.serviceName}" 2>nul`); } catch (e) {}
|
|
164
|
-
try { await this.execCommand(`sc delete "${this.serviceName}" 2>nul`); } catch (e) {}
|
|
164
|
+
try { await this.execCommand(`sc.exe delete "${this.serviceName}" 2>nul`); } catch (e) {}
|
|
165
165
|
|
|
166
166
|
// sc.exe 是 cmd 时代的工具,必须用 exec(走 cmd 解析)才能正确传递 binPath
|
|
167
|
-
const createCmd = `sc create "${this.serviceName}" binPath= ${binPath} start= auto displayname= "${this.serviceDesc}"`;
|
|
167
|
+
const createCmd = `sc.exe create "${this.serviceName}" binPath= ${binPath} start= auto displayname= "${this.serviceDesc}"`;
|
|
168
168
|
await this.execCommand(createCmd);
|
|
169
169
|
this.log?.info('[ServiceManager] Windows 服务注册成功');
|
|
170
170
|
|
package/version.json
CHANGED