@profullstack/threatcrush 0.11.4 → 0.11.5

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/dist/index.js CHANGED
@@ -18273,7 +18273,7 @@ function printTrustRequired(name) {
18273
18273
  function notifyDaemonIfRunning() {
18274
18274
  if (!findRunningDaemon()) return;
18275
18275
  console.log(source_default.dim(` \u2139 threatcrushd is running \u2014 restart it to load/unload modules:`));
18276
- console.log(source_default.dim(` ${source_default.white("threatcrush stop && threatcrush start")}`));
18276
+ console.log(source_default.dim(` ${source_default.white("threatcrush restart")}`));
18277
18277
  }
18278
18278
  async function modulesListCommand() {
18279
18279
  banner();
@@ -21822,7 +21822,7 @@ async function daemonStop() {
21822
21822
  const pid = findRunningDaemon();
21823
21823
  if (!pid) {
21824
21824
  console.log(source_default.dim(" No running daemon found."));
21825
- return;
21825
+ return true;
21826
21826
  }
21827
21827
  try {
21828
21828
  const client = new IpcClient();
@@ -21836,28 +21836,48 @@ async function daemonStop() {
21836
21836
  } catch {
21837
21837
  }
21838
21838
  }
21839
- const deadline = Date.now() + 3e3;
21840
- while (Date.now() < deadline) {
21841
- try {
21842
- process.kill(pid, 0);
21843
- } catch {
21844
- break;
21845
- }
21846
- await new Promise((r) => setTimeout(r, 100));
21847
- }
21848
- try {
21849
- process.kill(pid, 0);
21850
- } catch {
21839
+ if (await waitForExit(pid, 3e3)) {
21851
21840
  removePidFile();
21852
21841
  console.log(source_default.green(` \u2713 threatcrushd stopped.`));
21853
- return;
21842
+ return true;
21854
21843
  }
21855
21844
  try {
21856
21845
  process.kill(pid, "SIGKILL");
21857
21846
  } catch {
21858
21847
  }
21848
+ if (!await waitForExit(pid, 1e3)) {
21849
+ console.log(source_default.red(` \u2717 threatcrushd (pid ${pid}) is still running and could not be stopped.`));
21850
+ console.log(source_default.dim(" It may be owned by another user \u2014 try `sudo threatcrush stop`.\n"));
21851
+ return false;
21852
+ }
21859
21853
  removePidFile();
21860
21854
  console.log(source_default.yellow(` ! threatcrushd was killed (SIGKILL).`));
21855
+ return true;
21856
+ }
21857
+ async function daemonRestart() {
21858
+ if (!await daemonStop()) return;
21859
+ await releaseStaleSocket();
21860
+ await daemonStart();
21861
+ }
21862
+ async function waitForExit(pid, timeoutMs) {
21863
+ const deadline = Date.now() + timeoutMs;
21864
+ while (isProcessAlive(pid)) {
21865
+ if (Date.now() >= deadline) return false;
21866
+ await new Promise((r) => setTimeout(r, 100));
21867
+ }
21868
+ return true;
21869
+ }
21870
+ async function releaseStaleSocket() {
21871
+ const deadline = Date.now() + 2e3;
21872
+ while ((0, import_node_fs26.existsSync)(PATHS.socket) && Date.now() < deadline) {
21873
+ await new Promise((r) => setTimeout(r, 50));
21874
+ }
21875
+ if ((0, import_node_fs26.existsSync)(PATHS.socket)) {
21876
+ try {
21877
+ (0, import_node_fs26.unlinkSync)(PATHS.socket);
21878
+ } catch {
21879
+ }
21880
+ }
21861
21881
  }
21862
21882
 
21863
21883
  // src/commands/service.ts
@@ -23266,6 +23286,10 @@ program2.command("stop").description("Stop the ThreatCrush daemon").action(async
23266
23286
  console.log(LOGO2);
23267
23287
  await daemonStop();
23268
23288
  });
23289
+ program2.command("restart").description("Restart the ThreatCrush daemon (stop, then start)").action(async () => {
23290
+ console.log(LOGO2);
23291
+ await daemonRestart();
23292
+ });
23269
23293
  program2.command("daemon").description("Run threatcrushd in the foreground (systemd / Docker ExecStart)").action(async () => {
23270
23294
  await daemonForeground();
23271
23295
  });
@@ -23355,9 +23379,6 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
23355
23379
  console.log(source_default.dim(` Install mode: ${installMode}
23356
23380
  `));
23357
23381
  const commands = [getGlobalInstallCommand(pm, PKG_NAME, "update")];
23358
- if (installMode === "desktop") {
23359
- commands.push(getGlobalInstallCommand(pm, DESKTOP_PKG_NAME, "update"));
23360
- }
23361
23382
  try {
23362
23383
  for (const cmd of commands) {
23363
23384
  console.log(source_default.green(` \u2192 ${cmd}