claw-subagent-service 0.0.135 → 0.0.137
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/package.json
CHANGED
package/scripts/post-install.js
CHANGED
|
@@ -37,7 +37,45 @@ function isWindowsAdmin() {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function fixShellScriptLineEndings() {
|
|
41
|
+
if (process.platform === 'win32') return;
|
|
42
|
+
|
|
43
|
+
const fs = require('fs');
|
|
44
|
+
const path = require('path');
|
|
45
|
+
const scriptDir = path.join(__dirname, '..', 'command', 'linux');
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
if (!fs.existsSync(scriptDir)) return;
|
|
49
|
+
const files = fs.readdirSync(scriptDir);
|
|
50
|
+
let fixedCount = 0;
|
|
51
|
+
|
|
52
|
+
for (const file of files) {
|
|
53
|
+
if (!file.endsWith('.sh')) continue;
|
|
54
|
+
const filePath = path.join(scriptDir, file);
|
|
55
|
+
try {
|
|
56
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
57
|
+
if (content.includes('\r\n')) {
|
|
58
|
+
fs.writeFileSync(filePath, content.replace(/\r\n/g, '\n'));
|
|
59
|
+
fixedCount++;
|
|
60
|
+
console.log(`[postinstall] 已修复 ${file} 换行符(CRLF → LF)`);
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.warn(`[postinstall] 修复 ${file} 失败: ${e.message}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (fixedCount > 0) {
|
|
68
|
+
console.log(`[postinstall] 共修复 ${fixedCount} 个脚本换行符`);
|
|
69
|
+
}
|
|
70
|
+
} catch (e) {
|
|
71
|
+
console.warn(`[postinstall] 修复换行符失败: ${e.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
40
75
|
function installAndStartService() {
|
|
76
|
+
// 先修复 Linux 脚本的换行符
|
|
77
|
+
fixShellScriptLineEndings();
|
|
78
|
+
|
|
41
79
|
if (process.platform !== 'win32') {
|
|
42
80
|
console.log(`[postinstall] 跳过(非 Windows: ${process.platform})`);
|
|
43
81
|
return;
|
|
@@ -58,14 +58,61 @@ function getCommandName(command) {
|
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* 检测是否在 Docker 环境(无 systemd)
|
|
61
|
+
* 使用多种方法检测,提高可靠性
|
|
61
62
|
*/
|
|
62
63
|
function isDockerEnvironment() {
|
|
63
64
|
try {
|
|
64
65
|
const fs = require('fs');
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const { execSync } = require('child_process');
|
|
67
|
+
|
|
68
|
+
// 方法1: 检查 /proc/1/cgroup 是否包含 docker
|
|
69
|
+
try {
|
|
70
|
+
const cgroup = fs.readFileSync('/proc/1/cgroup', 'utf8');
|
|
71
|
+
if (cgroup.includes('docker') || cgroup.includes('containerd')) {
|
|
72
|
+
console.log('[OpenClawControl] Docker 检测: /proc/1/cgroup 包含 docker/containerd');
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
// 文件不存在或读取失败
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 方法2: 检查 /.dockerenv 文件是否存在
|
|
80
|
+
try {
|
|
81
|
+
fs.accessSync('/.dockerenv', fs.constants.F_OK);
|
|
82
|
+
console.log('[OpenClawControl] Docker 检测: /.dockerenv 文件存在');
|
|
83
|
+
return true;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
// 文件不存在
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 方法3: 检查环境变量
|
|
89
|
+
if (process.env.DOCKER_CONTAINER || process.env.KUBERNETES_SERVICE_HOST) {
|
|
90
|
+
console.log('[OpenClawControl] Docker 检测: 环境变量指示 Docker/K8s');
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 方法4: 检查 systemd 是否运行(Docker 通常没有 systemd)
|
|
95
|
+
try {
|
|
96
|
+
// 如果 systemctl 命令不存在,可能是 Docker
|
|
97
|
+
execSync('command -v systemctl', { stdio: 'ignore' });
|
|
98
|
+
// systemctl 存在,检查是否实际运行
|
|
99
|
+
try {
|
|
100
|
+
execSync('systemctl status', { stdio: 'ignore', timeout: 2000 });
|
|
101
|
+
// systemd 正在运行,不是 Docker
|
|
102
|
+
console.log('[OpenClawControl] Docker 检测: systemd 正在运行,不是 Docker');
|
|
103
|
+
return false;
|
|
104
|
+
} catch (e) {
|
|
105
|
+
// systemctl 存在但无法使用,可能是 Docker
|
|
106
|
+
console.log('[OpenClawControl] Docker 检测: systemctl 存在但无法使用,可能是 Docker');
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
// systemctl 命令不存在,可能是 Docker
|
|
111
|
+
console.log('[OpenClawControl] Docker 检测: systemctl 命令不存在,可能是 Docker');
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
68
114
|
} catch (e) {
|
|
115
|
+
console.error('[OpenClawControl] Docker 检测异常:', e.message);
|
|
69
116
|
return false;
|
|
70
117
|
}
|
|
71
118
|
}
|
|
@@ -81,6 +128,12 @@ async function manageWithServiceManager(command) {
|
|
|
81
128
|
return null;
|
|
82
129
|
}
|
|
83
130
|
|
|
131
|
+
// 强制 Docker 模式:通过环境变量强制使用脚本方式(用于自动检测失败的情况)
|
|
132
|
+
if (process.env.FORCE_DOCKER_MODE === 'true' || process.env.FORCE_DOCKER_MODE === '1') {
|
|
133
|
+
console.log('[OpenClawControl] FORCE_DOCKER_MODE 已设置,跳过 ServiceManager,使用脚本方式');
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
84
137
|
const serviceMgr = new ServiceManager('openclaw-gateway', 'OpenClaw Gateway');
|
|
85
138
|
|
|
86
139
|
try {
|