Skip to content

Commit

Permalink
fixes to binaries to allow full shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Tahler committed Jan 25, 2013
1 parent f320ca2 commit 0f12e12
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
47 changes: 24 additions & 23 deletions bin/include/start.js
Expand Up @@ -4,7 +4,7 @@ exports['start'] = function(binary, next){
var actionHeroPrototype = require(binary.paths.actionHero_root + "/actionHero.js").actionHeroPrototype;
var actionHero = new actionHeroPrototype();

var shutdownTimeout = 10000 // number of ms to wait to do a forcible shutdown if actionHero won't stop gracefully
var shutdownTimeout = 1000 * 60 // number of ms to wait to do a forcible shutdown if actionHero won't stop gracefully

var title = process.title;
var api = {};
Expand Down Expand Up @@ -46,28 +46,6 @@ exports['start'] = function(binary, next){
});
}

// handle posix signals
process.on('SIGINT', function(){
setTimeout(process.exit, shutdownTimeout);
stopServer(function(){
setTimeout(process.exit, 500);
});
});
process.on('SIGTERM', function(){
stopServer(function(){
setTimeout(process.exit, 500);
});
});
process.on('SIGKILL', function(){
setTimeout(process.exit, shutdownTimeout);
stopServer(function(){
setTimeout(process.exit, 500);
});
});
process.on('SIGUSR2', function(){
restartServer();
});

// handle signals from master if running in cluster
if(cluster.isWorker){
process.on('message', function(msg) {
Expand All @@ -80,6 +58,7 @@ exports['start'] = function(binary, next){
process.send("stopping");
stopServer(function(){
process.send("stopped");
setTimeout(process.exit, 500);
})
}
else if(msg == "restart"){
Expand All @@ -89,6 +68,28 @@ exports['start'] = function(binary, next){
});
}
});
process.on('SIGINT', function(){}); // catch to ignore
}else{
process.on('SIGINT', function(){
setTimeout(process.exit, shutdownTimeout);
stopServer(function(){
setTimeout(process.exit, 500);
});
});
process.on('SIGTERM', function(){
stopServer(function(){
setTimeout(process.exit, 500);
});
});
process.on('SIGKILL', function(){
setTimeout(process.exit, shutdownTimeout);
stopServer(function(){
setTimeout(process.exit, 500);
});
});
process.on('SIGUSR2', function(){
restartServer();
});
}

// start the server!
Expand Down
6 changes: 3 additions & 3 deletions bin/include/startCluster.js
Expand Up @@ -124,7 +124,7 @@ exports['startCluster'] = function(binary, next){
}

binary.setupShutdown = function(){
binary.log("Cluster manager quitting", "red", "bold");
binary.log("Cluster manager quitting", ["red", "bold"]);
binary.log("Stopping each worker...");
for(var i in cluster.workers){
cluster.workers[i].send('stop');
Expand All @@ -133,9 +133,9 @@ exports['startCluster'] = function(binary, next){
}

binary.loopUntilNoWorkers = function(){
if(cluster.workers.length > 0){
if(binary.utils.hashLength(cluster.workers) > 0){
binary.log("there are still " + binary.utils.hashLength(cluster.workers) + " workers...");
setTimeout(loopUntilNoWorkers, loopSleep);
setTimeout(binary.loopUntilNoWorkers, loopSleep);
}else{
binary.log("all workers gone");
if(binary.clusterConfig.pidfile != null){
Expand Down

0 comments on commit 0f12e12

Please sign in to comment.