(dataDir: string)
| 36 | |
| 37 | /** Stop the detached daemon elected by an `executor mcp` cold start. */ |
| 38 | export const stopAutoSpawnedDaemon = async (dataDir: string): Promise<void> => { |
| 39 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- cleanup tolerates a bridge that failed before writing its manifest |
| 40 | try { |
| 41 | const manifest = JSON.parse( |
| 42 | await readFile(join(dataDir, "server-control", "server.json"), "utf8"), |
| 43 | ) as { readonly pid?: unknown }; |
| 44 | if (!Number.isSafeInteger(manifest.pid) || (manifest.pid as number) <= 0) return; |
| 45 | |
| 46 | const pid = manifest.pid as number; |
| 47 | signal(pid, "SIGTERM"); |
| 48 | if (await waitUntilStopped(pid, 10_000)) return; |
| 49 | |
| 50 | signal(pid, "SIGKILL"); |
| 51 | await waitUntilStopped(pid, 2_000); |
| 52 | } catch { |
| 53 | // No manifest means there is no auto-started daemon to stop. |
| 54 | } |
| 55 | }; |
no test coverage detected