From 86d2b8c1cfedac0156cef7eeae050872d1780673 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 29 Nov 2021 15:34:19 +0100 Subject: [PATCH] Added event for SIGTERM and SIGINT --- src/main.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.js b/src/main.js index 2a0a0a6..5710070 100644 --- a/src/main.js +++ b/src/main.js @@ -117,5 +117,14 @@ if(errorMsg){ exit(0); }); + // Handle stop-signals for graceful shutdown + function shutdownReq() { + logger.info("Shutdown request received.."); + logger.debug("Stopping subprocess tcpdump, then exiting myself.."); + proc.kill(); // Kill process (send SIGTERM), then upper event-handler will stop self + } + process.on('SIGTERM', shutdownReq); + process.on('SIGINT', shutdownReq); + logger.info("Startup complete"); })();