diff --git a/examples/reload.js b/examples/reload.js index ac7b555..699e6e5 100644 --- a/examples/reload.js +++ b/examples/reload.js @@ -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'];