From fd53541719d336f6ab8eaaff82cfefcd89e6277a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Arnauts?= Date: Sat, 6 Apr 2019 20:50:54 +0200 Subject: [PATCH] Handle SIGTERM messages --- js/app.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/app.js b/js/app.js index 95c9693b..da1d24a8 100644 --- a/js/app.js +++ b/js/app.js @@ -263,6 +263,15 @@ var App = function() { this.stop(); process.exit(0); }); + + /* We also need to listen to SIGTERM signals so we stop everything when we are asked to stop by the OS. + */ + process.on("SIGTERM", () => { + console.log("[SIGTERM] Received. Shutting down server..."); + setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds + this.stop(); + process.exit(0); + }); }; module.exports = new App();