Stop the daemon. Never throws — logs and resolves even on failure.
()
| 94 | |
| 95 | /** Stop the daemon. Never throws — logs and resolves even on failure. */ |
| 96 | async stop(): Promise<void> { |
| 97 | this.logger.info(`[hindsight] stopping daemon for profile "${this.profile}"`); |
| 98 | |
| 99 | const [cmd, ...baseArgs] = getEmbedCommand({ |
| 100 | embedVersion: this.embedVersion, |
| 101 | embedPackagePath: this.embedPackagePath, |
| 102 | }); |
| 103 | const args = [...baseArgs, "daemon", "--profile", this.profile, "stop"]; |
| 104 | |
| 105 | const child = spawn(cmd, args, { stdio: "pipe" }); |
| 106 | this.pipeOutput(child, "daemon.stop"); |
| 107 | |
| 108 | await new Promise<void>((resolve) => { |
| 109 | const timeout = setTimeout(() => { |
| 110 | this.logger.warn(`[hindsight] daemon stop timed out after 5s`); |
| 111 | resolve(); |
| 112 | }, 5_000); |
| 113 | child.on("exit", () => { |
| 114 | clearTimeout(timeout); |
| 115 | this.logger.info(`[hindsight] daemon stopped`); |
| 116 | resolve(); |
| 117 | }); |
| 118 | child.on("error", (err) => { |
| 119 | clearTimeout(timeout); |
| 120 | this.logger.warn(`[hindsight] error stopping daemon: ${err.message}`); |
| 121 | resolve(); |
| 122 | }); |
| 123 | }); |
| 124 | } |
| 125 | |
| 126 | /** Probe `/health` once with a short timeout. */ |
| 127 | async checkHealth(): Promise<boolean> { |