diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts index 6d157dbf6..468b3005b 100644 --- a/apps/server/src/main.ts +++ b/apps/server/src/main.ts @@ -118,7 +118,13 @@ export class Application { // Immediate exit without graceful shutdown. Chromium may kill us on update/restart, // and we need to free the port instantly so the HTTP port doesn't keep switching. - process.exit(EXIT_CODES.SUCCESS) + // Exit 0 only for managed shutdowns (POST /shutdown from Chromium). + // Signal kills exit non-zero so Chromium's OnProcessExited restarts us. + const code = + reason === 'SIGTERM' || reason === 'SIGINT' + ? EXIT_CODES.SIGNAL_KILL + : EXIT_CODES.SUCCESS + process.exit(code) } private initCoreServices(): void { diff --git a/packages/shared/src/constants/exit-codes.ts b/packages/shared/src/constants/exit-codes.ts index 245d6d5a7..b82d830a0 100644 --- a/packages/shared/src/constants/exit-codes.ts +++ b/packages/shared/src/constants/exit-codes.ts @@ -16,6 +16,9 @@ export const EXIT_CODES = { /** Port conflict after retries - Chromium should increment port and restart */ PORT_CONFLICT: 2, + + /** Killed by external signal - Chromium should restart */ + SIGNAL_KILL: 3, } as const export type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES]