chatccc 0.2.165 → 0.2.166
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/orchestrator.ts +23 -8
package/package.json
CHANGED
package/src/orchestrator.ts
CHANGED
|
@@ -177,7 +177,7 @@ function updLog(msg: string): void {
|
|
|
177
177
|
try { appendFileSync(UPDATEG_LOG, `${ts} [UPG-SYNC] ${msg}\n`, "utf-8"); } catch {}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
/** 同步更新 npm
|
|
180
|
+
/** 同步更新 npm 全局包并 spawn 新进程重启。不依赖 systemd 或任何服务管理器。 */
|
|
181
181
|
function syncUpdateAndRestart(): void {
|
|
182
182
|
updLog(`sync update start, pid=${process.pid}`);
|
|
183
183
|
appendStartupTrace("updateg: sync update start", { pid: process.pid });
|
|
@@ -216,8 +216,27 @@ function syncUpdateAndRestart(): void {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
219
|
+
// 2. resolve bin path
|
|
220
|
+
const npmPrefix = process.env.NPM_PREFIX || "";
|
|
221
|
+
const binName = process.platform === "win32" ? "chatccc.cmd" : "chatccc";
|
|
222
|
+
const binPath = npmPrefix ? join(npmPrefix, binName) : "chatccc";
|
|
223
|
+
updLog(`bin path: npmPrefix=${npmPrefix || "(empty)"}, binPath=${binPath}`);
|
|
224
|
+
appendStartupTrace("updateg: spawn begin", { npmPrefix: npmPrefix || "(empty)", binPath });
|
|
225
|
+
|
|
226
|
+
// 3. spawn new chatccc
|
|
227
|
+
try {
|
|
228
|
+
const child = spawn(binPath, [], { detached: true, stdio: "ignore", shell: true });
|
|
229
|
+
child.unref();
|
|
230
|
+
updLog(`spawn new chatccc OK, childPid=${child.pid}, bin=${binPath}`);
|
|
231
|
+
appendStartupTrace("updateg: spawn OK", { childPid: child.pid, binPath });
|
|
232
|
+
} catch (e) {
|
|
233
|
+
const errMsg = (e as Error).message;
|
|
234
|
+
updLog(`spawn new chatccc failed: ${errMsg}`);
|
|
235
|
+
appendStartupTrace("updateg: spawn failed", { error: errMsg });
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
updLog("sync update done, parent exiting in 2s");
|
|
239
|
+
appendStartupTrace("updateg: sync update done, exiting", { pid: process.pid });
|
|
221
240
|
}
|
|
222
241
|
|
|
223
242
|
// ---------------------------------------------------------------------------
|
|
@@ -286,11 +305,7 @@ export async function handleCommand(
|
|
|
286
305
|
logTrace(tid, "DONE", { outcome: "updateg" });
|
|
287
306
|
appendStartupTrace("updateg: sync update begin", { fromPid: process.pid });
|
|
288
307
|
syncUpdateAndRestart();
|
|
289
|
-
|
|
290
|
-
// systemd 判定服务正常结束并清理整个 cgroup(杀死刚 spawn 的子进程)。
|
|
291
|
-
// exit(1) 触发 Restart=on-failure,由 systemd 重新拉起 ExecStart,此时
|
|
292
|
-
// npm 已更新到新版本,服务正常重启。
|
|
293
|
-
setTimeout(() => process.exit(1), 2000);
|
|
308
|
+
setTimeout(() => process.exit(0), 2000);
|
|
294
309
|
return;
|
|
295
310
|
}
|
|
296
311
|
|