mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
Recover stale supervised daemons
Teach daemon stop to use lifecycle shutdown when the API is reachable even if the owner pid is stale, then wait for the API to disappear and clean the stale pidfile. Launch desktop-managed daemons detached from desktop stdio, preserve stale reachable daemon ownership for version checks, and allow desktop stop/restart to use the CLI recovery path. Add supervisor heartbeats so supervised workers shut down when their supervisor disappears instead of surviving as orphaned reachable daemons.
This commit is contained in:
@@ -24,6 +24,10 @@ type WorkerLifecycleMessage =
|
||||
reason?: string;
|
||||
};
|
||||
|
||||
interface SupervisorHeartbeatMessage {
|
||||
type: "paseo:supervisor-heartbeat";
|
||||
}
|
||||
|
||||
interface SupervisorOptions {
|
||||
name: string;
|
||||
startupMessage: string;
|
||||
@@ -183,6 +187,15 @@ export function runSupervisor(options: SupervisorOptions): void {
|
||||
});
|
||||
}
|
||||
|
||||
const currentChild = child;
|
||||
const heartbeat = setInterval(() => {
|
||||
const message: SupervisorHeartbeatMessage = { type: "paseo:supervisor-heartbeat" };
|
||||
if (currentChild.connected) {
|
||||
currentChild.send?.(message, () => undefined);
|
||||
}
|
||||
}, 1000);
|
||||
heartbeat.unref();
|
||||
|
||||
child.stdout?.on("data", (chunk: Buffer) => {
|
||||
process.stdout.write(chunk);
|
||||
writeDurableChunk(chunk);
|
||||
@@ -224,6 +237,7 @@ export function runSupervisor(options: SupervisorOptions): void {
|
||||
});
|
||||
|
||||
child.on("close", (code, signal) => {
|
||||
clearInterval(heartbeat);
|
||||
const exitDescriptor = describeExit(code, signal);
|
||||
writeLifecycleLog("Worker exited", { code, signal, exit: exitDescriptor });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user