From eb9b31a21b20e525c5d69f9fbac93276e36e9546 Mon Sep 17 00:00:00 2001 From: Nicholas O'Leary Date: Sun, 13 Oct 2013 19:14:39 +0100 Subject: [PATCH] Bit more of a shuffle round of the shutdown handling --- red.js | 3 ++- red/nodes.js | 13 +++++++------ red/red.js | 4 ++-- red/server.js | 7 ++++++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/red.js b/red.js index 4001cba12..f63ee64f5 100644 --- a/red.js +++ b/red.js @@ -72,6 +72,7 @@ process.on('uncaughtException',function(err) { process.on('SIGINT', function () { RED.stop(); - util.log('[red] Exiting Node-RED. Thank you.'); + // TODO: need to allow nodes to close asynchronously before terminating the + // process - ie, promises process.exit(); }); diff --git a/red/nodes.js b/red/nodes.js index c3d901223..4e813d2d4 100644 --- a/red/nodes.js +++ b/red/nodes.js @@ -271,16 +271,17 @@ module.exports.getNode = function(nid) { return registry.get(nid); } -module.exports.closedown = function() { - util.log("[red] Closing Down Nodes"); - registry.clear(); -} - -module.exports.setConfig = function(conf) { +function stopFlows() { if (activeConfig&&activeConfig.length > 0) { util.log("[red] Stopping flows"); } registry.clear(); +} + +module.exports.stopFlows = stopFlows; + +module.exports.setConfig = function(conf) { + stopFlows(); activeConfig = conf; parseConfig(); } diff --git a/red/red.js b/red/red.js index b2d18b2c5..e15787c24 100644 --- a/red/red.js +++ b/red/red.js @@ -33,10 +33,10 @@ var RED = { }, start: server.start, + stop: server.stop, nodes: nodes, library: library, - events: events, - stop: nodes.closedown, + events: events }; RED.__defineGetter__("app", function() { return server.app }); diff --git a/red/server.js b/red/server.js index 5361cb7af..876317bc9 100644 --- a/red/server.js +++ b/red/server.js @@ -101,9 +101,14 @@ function start() { }); } +function stop() { + redNodes.stopFlows(); +} + module.exports = { init: createServer, - start: start + start: start, + stop: stop } module.exports.__defineGetter__("app", function() { return app });