When the main server process is killed, kill the children too

Change-Id: If07a8c290d5c1d4ac977222fe8cd25ef345c4132
This commit is contained in:
Catrope 2012-07-14 16:07:43 -07:00
parent 235739e253
commit c79b62f869

View file

@ -17,10 +17,27 @@ if (cluster.isMaster) {
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died, restarting.');
// restart worker
cluster.fork();
if(!worker.suicide) {
console.log('worker ' + worker.pid + ' died, restarting.');
// restart worker
cluster.fork();
}
});
process.on('SIGTERM', function() {
console.log('master shutting down, killing workers');
for(var i = 0; i < workers.length; i++) {
console.log('Killing worker ' + i + ' with PID ' + workers[i].pid);
// disconnect() doesn't work for some reason
//workers[i].disconnect();
workers[i].kill('SIGTERM');
}
console.log('Done killing workers, bye');
process.exit(1);
} );
} else {
process.on('SIGTERM', function() {
console.log('Worker shutting down');
process.exit(1);
});
app.listen(8000);
}