From 96b52e63a0f35cb2647bfb08d2d5b124cf97b647 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 29 Nov 2021 09:16:39 +0100 Subject: [PATCH] Add exit-handler with error-detection --- src/main.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main.js b/src/main.js index 5297229..6660c5e 100644 --- a/src/main.js +++ b/src/main.js @@ -71,4 +71,16 @@ if(errorMsg){ logger.error(data); }); + logger.debug("Attaching exit-handler.."); + proc.on("exit", (code) => { + logger.info(`tcpdump exited code: ${code}`); + if (code) { + logger.fatal(`tcpdump exited with non-zero code: ${code}`); + exit(1); + } + logger.info("Shutdown"); + exit(0); + }); + + logger.info("Startup complete"); })();