From fcf757f7155b0a39285e79b882bdf29010f5168c Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 31 Jan 2020 18:11:58 +0000 Subject: [PATCH] catch mode signals to allow clean context flush on shutdown (yes the name is intentionally ironic) Code pattern copied from https://nodejs.org/api/process.html#process_signal_events --- packages/node_modules/node-red/red.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 26b6d1fc8..e758a00f3 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -342,8 +342,14 @@ process.on('uncaughtException',function(err) { process.exit(1); }); -process.on('SIGINT', function () { +function brexit() { RED.stop().then(function() { process.exit(); }); -}); +} + +process.on('SIGINT', brexit); +process.on('SIGTERM', brexit); +process.on('SIGHUP', brexit); +process.on('SIGUSR2', brexit); // for nodemon restart +process.on('SIGBREAK', brexit); // for windows ctrl-break