From cf5c818ee32c22dbc6852df98c4b06bbe00df144 Mon Sep 17 00:00:00 2001 From: Kevin Stone Date: Thu, 29 May 2025 17:37:40 -0700 Subject: [PATCH] Gracefully shutdown on both SIGINT + SIGTERM Most service managers (systemd, docker, etc) use SIGTERM as the shutdown signal by default rather than SIGINT (which is used for interactive CTRL-C). --- index.mjs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.mjs b/index.mjs index 4ca315e..8c2169b 100644 --- a/index.mjs +++ b/index.mjs @@ -99,8 +99,11 @@ const server = app.listen(port, () => { }); // graceful shutdown -process.on('SIGINT', () => { +const gracefulShutdown = () => { server.close(() => { console.log('Server closed'); }); -}); +}; + +process.on('SIGINT', gracefulShutdown); +process.on('SIGTERM', gracefulShutdown);