From 4e775994d951aeacd2670b598f9625e5043cb03f Mon Sep 17 00:00:00 2001 From: Justin Deal Date: Sun, 31 Jul 2011 16:06:39 -0500 Subject: [PATCH 1/2] Allowing restart to continue after syntax errors. --- examples/reload.js | 4 ++-- lib/master.js | 7 +++++++ lib/plugins/reload.js | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/reload.js b/examples/reload.js index ac7b555..1eef600 100644 --- a/examples/reload.js +++ b/examples/reload.js @@ -8,7 +8,7 @@ var cluster = require('../') // try loading, and changing "Hello", to "Hello World" -var body = 'Hello' +var body = 'Hello, world!' , len = body.length; var server = http.createServer(function(req, res){ res.writeHead(200, { 'Content-Length': len }); @@ -21,4 +21,4 @@ cluster(server) .set('workers', 1) .use(cluster.reload()) .use(cluster.debug()) - .listen(3000); \ No newline at end of file + .listen(3000); diff --git a/lib/master.js b/lib/master.js index 176af0d..b32cdd8 100644 --- a/lib/master.js +++ b/lib/master.js @@ -67,6 +67,7 @@ var node = process.execPath; * which can be patched in order to preserve plugin state. * - `restart`. Restart complete, new master established, previous died. * Receives an object with state preserved by the `restarting` event. + * - `exit`. When a restarted master process exits. * * Signals: * @@ -684,6 +685,12 @@ Master.prototype.spawnMaster = function(){ customFds: customFds , env: env }); + + // watch for exit in case of problem during restart + var self = this; + proc.on('exit',function(){ + self.emit('exit',{}); + }); // unix domain socket for ICP + fd passing proc.sock = new net.Socket(fds[1], 'unix'); diff --git a/lib/plugins/reload.js b/lib/plugins/reload.js index e452c4b..73acd58 100644 --- a/lib/plugins/reload.js +++ b/lib/plugins/reload.js @@ -115,6 +115,11 @@ exports = module.exports = function(files, options){ master.on('restarting', function(){ restarting = true; }); + + master.on('exit', function(){ + // must have been a problem + restarting = false; + }); } }; @@ -122,4 +127,4 @@ exports = module.exports = function(files, options){ * Directories to ignore. */ -exports.ignoreDirectories = ['node_modules', 'support', 'test', 'bin']; \ No newline at end of file +exports.ignoreDirectories = ['node_modules', 'support', 'test', 'bin']; From e9a47973d9316cce2bb4e34cf3e8d92a93f8d6fe Mon Sep 17 00:00:00 2001 From: Justin Deal Date: Sun, 31 Jul 2011 16:27:06 -0500 Subject: [PATCH 2/2] Meant to change example back to 'Hello'. --- examples/reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/reload.js b/examples/reload.js index 1eef600..699e6e5 100644 --- a/examples/reload.js +++ b/examples/reload.js @@ -8,7 +8,7 @@ var cluster = require('../') // try loading, and changing "Hello", to "Hello World" -var body = 'Hello, world!' +var body = 'Hello' , len = body.length; var server = http.createServer(function(req, res){ res.writeHead(200, { 'Content-Length': len });