From 60dc9bcc4ceec63ade18ae2149fc188b8f3bfecd Mon Sep 17 00:00:00 2001 From: zefie Date: Thu, 5 Aug 2021 17:50:56 -0400 Subject: [PATCH] update: app.js: enable graceful shutdown with SIGTERM --- zefie_wtvp_minisrv/app.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/zefie_wtvp_minisrv/app.js b/zefie_wtvp_minisrv/app.js index 3739aecb..50ffea09 100644 --- a/zefie_wtvp_minisrv/app.js +++ b/zefie_wtvp_minisrv/app.js @@ -14,6 +14,20 @@ var WTVSec = require('./WTVSec.js'); var WTVClientCapabilities = require('./WTVClientCapabilities.js'); var WTVClientSessionData = require('./WTVClientSessionData.js'); +process + .on('SIGTERM', shutdown('SIGTERM')) + .on('SIGINT', shutdown('SIGINT')) + .on('uncaughtException', shutdown('uncaughtException')); + + +function shutdown(signal) { + return (err) => { + console.log("Received signal", signal); + if (err) console.error(err.stack || err); + process.exit(err ? 1 : 0); + }; +} + // Where we store our session information var ssid_sessions = new Array(); var socket_sessions = new Array(); @@ -1330,4 +1344,4 @@ initstring = initstring.substring(0, initstring.length - 2); console.log(" * Started server on ports " + initstring + "...") var listening_ip_string = (minisrv_config.config.bind_ip != "0.0.0.0") ? "IP: " + minisrv_config.config.bind_ip : "all interfaces"; -console.log(" * Listening on", listening_ip_string,"~","Service IP:", service_ip); +console.log(" * Listening on", listening_ip_string,"~","Service IP:", service_ip); \ No newline at end of file