From fcf757f7155b0a39285e79b882bdf29010f5168c Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 31 Jan 2020 18:11:58 +0000 Subject: [PATCH 1/3] 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 From 0622be843bd6aaabe2b927abba05a7f7272b7b6d Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 4 Feb 2020 13:42:34 +0000 Subject: [PATCH 2/3] Add catcher for PM2 graceful shutdown --- packages/node_modules/node-red/red.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index e758a00f3..aa1f9f726 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -353,3 +353,6 @@ process.on('SIGTERM', brexit); process.on('SIGHUP', brexit); process.on('SIGUSR2', brexit); // for nodemon restart process.on('SIGBREAK', brexit); // for windows ctrl-break +process.on('message', function(m) { // for PM2 under window with --shutdown-with-message + if (m === 'shutdown') { brexit } +}); From b2f53a183e0ce5dfab81942d018c06132b84c3bf Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Wed, 5 Feb 2020 13:58:45 +0000 Subject: [PATCH 3/3] rename BreakingExit call (undo Brexit :-) --- packages/node_modules/node-red/red.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index aa1f9f726..95a42d9fd 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -342,17 +342,17 @@ process.on('uncaughtException',function(err) { process.exit(1); }); -function brexit() { +function exitWhenStopped() { 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 +process.on('SIGINT', exitWhenStopped); +process.on('SIGTERM', exitWhenStopped); +process.on('SIGHUP', exitWhenStopped); +process.on('SIGUSR2', exitWhenStopped); // for nodemon restart +process.on('SIGBREAK', exitWhenStopped); // for windows ctrl-break process.on('message', function(m) { // for PM2 under window with --shutdown-with-message - if (m === 'shutdown') { brexit } + if (m === 'shutdown') { exitWhenStopped } });