tt-help-cli-ycl 1.4.67 → 1.4.68
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 +1 -1
- package/src/watchdog/process-manager.js +28 -14
package/package.json
CHANGED
|
@@ -112,10 +112,17 @@ export class ProcessManager extends EventEmitter {
|
|
|
112
112
|
command = parts[0] || command;
|
|
113
113
|
args = parts.slice(1);
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
// Windows .cmd 文件必须 shell:true,macOS/Linux 直接 spawn
|
|
116
|
+
child = IS_WIN
|
|
117
|
+
? spawn(command, args, {
|
|
118
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
119
|
+
detached: false,
|
|
120
|
+
shell: true,
|
|
121
|
+
})
|
|
122
|
+
: spawn(command, args, {
|
|
123
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
124
|
+
detached: false,
|
|
125
|
+
});
|
|
119
126
|
} catch (e) {
|
|
120
127
|
console.error(`[watchdog] 启动命令 ${id} 失败: ${e.message}`);
|
|
121
128
|
this.processes.set(id, {
|
|
@@ -203,16 +210,23 @@ export class ProcessManager extends EventEmitter {
|
|
|
203
210
|
|
|
204
211
|
if (info.child) {
|
|
205
212
|
try {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
if (IS_WIN) {
|
|
214
|
+
// Windows: shell:true 产生 cmd.exe 中间层,必须杀整个进程树
|
|
215
|
+
execSync(`taskkill /PID ${info.child.pid} /T /F`, {
|
|
216
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
217
|
+
timeout: 5000,
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
// macOS/Linux: 优雅终止,2 秒后强制 kill
|
|
221
|
+
info.child.kill("SIGTERM");
|
|
222
|
+
setTimeout(() => {
|
|
223
|
+
try {
|
|
224
|
+
if (info.child && info.child.exitCode === null) {
|
|
225
|
+
info.child.kill("SIGKILL");
|
|
226
|
+
}
|
|
227
|
+
} catch {}
|
|
228
|
+
}, 2000);
|
|
229
|
+
}
|
|
216
230
|
} catch (e) {
|
|
217
231
|
console.error(`[watchdog] 停止命令 ${cmdId} 失败: ${e.message}`);
|
|
218
232
|
}
|