Skip to content

Commit df3f1e3

Browse files
authored
fix: handle SIGINT/SIGTERM for graceful shutdown in Docker (#74)
1 parent f9d7116 commit df3f1e3

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/chronicle/src/cli/commands/dev.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ export const devCommand = new Command('dev')
2828

2929
await server.listen();
3030
server.printUrls();
31+
32+
let shuttingDown = false;
33+
const shutdown = async () => {
34+
if (shuttingDown) return;
35+
shuttingDown = true;
36+
try {
37+
await server.close();
38+
} catch { /* ignore close errors */ }
39+
process.exit(0);
40+
};
41+
process.once('SIGINT', shutdown);
42+
process.once('SIGTERM', shutdown);
3143
});

packages/chronicle/src/cli/commands/start.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ export const startCommand = new Command('start')
2626
});
2727

2828
server.printUrls();
29+
30+
let shuttingDown = false;
31+
const shutdown = async () => {
32+
if (shuttingDown) return;
33+
shuttingDown = true;
34+
try {
35+
await server.close();
36+
} catch { /* ignore close errors */ }
37+
process.exit(0);
38+
};
39+
process.once('SIGINT', shutdown);
40+
process.once('SIGTERM', shutdown);
2941
});

0 commit comments

Comments
 (0)