diff --git a/src/bin/turbowatch.ts b/src/bin/turbowatch.ts index e6180df..f9fc851 100644 --- a/src/bin/turbowatch.ts +++ b/src/bin/turbowatch.ts @@ -87,11 +87,35 @@ const main = async () => { ...turbowatchConfiguration, }); + let terminating = false; + process.once('SIGINT', () => { + if (terminating) { + log.warn('already terminating; ignoring SIGINT'); + + return; + } + + terminating = true; + log.warn('received SIGINT; gracefully terminating'); void turbowatchController.shutdown(); }); + + process.once('SIGTERM', () => { + if (terminating) { + log.warn('already terminating; ignoring SIGTERM'); + + return; + } + + terminating = true; + + log.warn('received SIGTERM; gracefully terminating'); + + void turbowatchController.shutdown(); + }); } };