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
This commit is contained in:
Dave Conway-Jones
2020-01-31 18:11:58 +00:00
parent 6b52206186
commit fcf757f715

View File

@@ -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