Permalink
Browse files

support children restart upon receiving SIGHUP

  • Loading branch information...
1 parent 9bf988e commit c2ded4f6ba268eaef4d1bb398d8087a7d2dd4f9b user committed Sep 30, 2010
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/multi-node.js
View
@@ -37,7 +37,7 @@ exports.listen = function(options, server){
tcpDescriptor = netBinding.socket("tcp4");
netBinding.bind(tcpDescriptor, options.port || 80);
netBinding.listen(tcpDescriptor, 128);
- var masterListen = !("masterListen" in options) || options.masterListen;
+ var masterListen = options.masterListen !== false;
var numChildren = (options.nodes || 1) - (masterListen ? 1 : 0);
if(masterListen){
server.listenFD(tcpDescriptor, 'tcp4');
@@ -78,18 +78,20 @@ exports.listen = function(options, server){
});
})(child);
child.addListener("exit", function(){
+//console.log('CHILD is gone!');
// remove the dead one
children.splice(i, 1);
// make a new process to replace the dead one
- if(!("restartChildren" in options) || options.restartChildren){
+ if(options.restartChildren !== false){
createChild(children.length);
+//console.log('CHILD respawned!');
}
});
}
for(var i = 0; i < numChildren; i++){
createChild(i);
}
- ["SIGINT", "SIGTERM", "SIGKILL", "SIGQUIT", "exit"].forEach(function(signal){
+ ["SIGINT", "SIGTERM", "SIGKILL", "SIGQUIT", "SIGHUP", "exit"].forEach(function(signal){
process.addListener(signal, function(){
children.forEach(function(child){
try{
@@ -98,7 +100,8 @@ exports.listen = function(options, server){
}
});
- if(signal !== 'exit'){
+ // N.B. we use SIGHUP to restart the children
+ if(signal !== 'exit' && signal !== 'SIGHUP'){
process.exit();
}
});
@@ -193,4 +196,4 @@ exports.frameStreamLengthEncoded = function(stream){
stream.write(new Buffer([buffer.length >> 24, buffer.length >> 16 & 255, buffer.length >> 8 & 255, buffer.length & 255]));
};
return emitter;
-};
+};

0 comments on commit c2ded4f

Please sign in to comment.