chatccc 0.2.164 → 0.2.165

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatccc",
3
- "version": "0.2.164",
3
+ "version": "0.2.165",
4
4
  "description": "Feishu bot bridge for Claude Code",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -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 全局包并重启(父进程存活等待,避免 systemd KillMode=control-group watcher) */
180
+ /** 同步更新 npm 全局包。不自行 spawn 新进程,而是 exit(1) 让 systemd Restart=on-failure 拉起新版本。 */
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,27 +216,8 @@ function syncUpdateAndRestart(): void {
216
216
  }
217
217
  }
218
218
 
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 in 2s", { pid: process.pid });
219
+ updLog("sync update done, exiting with code 1 to trigger systemd restart");
220
+ appendStartupTrace("updateg: sync update done, will exit(1) for systemd restart", { pid: process.pid });
240
221
  }
241
222
 
242
223
  // ---------------------------------------------------------------------------
@@ -305,7 +286,11 @@ export async function handleCommand(
305
286
  logTrace(tid, "DONE", { outcome: "updateg" });
306
287
  appendStartupTrace("updateg: sync update begin", { fromPid: process.pid });
307
288
  syncUpdateAndRestart();
308
- setTimeout(() => process.exit(0), 2000);
289
+ // exit(1) 而非 exit(0):systemd KillMode=control-group 下,exit(0) 会让
290
+ // systemd 判定服务正常结束并清理整个 cgroup(杀死刚 spawn 的子进程)。
291
+ // exit(1) 触发 Restart=on-failure,由 systemd 重新拉起 ExecStart,此时
292
+ // npm 已更新到新版本,服务正常重启。
293
+ setTimeout(() => process.exit(1), 2000);
309
294
  return;
310
295
  }
311
296