v1.18.x
Julian Lam 10 years ago
parent 14ba1ff8c0
commit 0d6be40238

@ -42,6 +42,7 @@ Loader.init = function(callback) {
process.on('SIGHUP', Loader.restart); process.on('SIGHUP', Loader.restart);
process.on('SIGUSR2', Loader.reload); process.on('SIGUSR2', Loader.reload);
process.on('SIGTERM', Loader.stop);
callback(); callback();
}; };
@ -217,6 +218,16 @@ Loader.reload = function() {
}); });
}; };
Loader.stop = function() {
Object.keys(cluster.workers).forEach(function(id) {
// Gracefully close workers
cluster.workers[id].kill();
});
// Clean up the pidfile
fs.unlinkSync(__dirname + '/pidfile');
};
Loader.notifyWorkers = function (msg) { Loader.notifyWorkers = function (msg) {
Object.keys(cluster.workers).forEach(function(id) { Object.keys(cluster.workers).forEach(function(id) {
cluster.workers[id].send(msg); cluster.workers[id].send(msg);

@ -12,10 +12,11 @@ fi
function pidExists() { function pidExists() {
if [ -e "pidfile" ]; if [ -e "pidfile" ];
then then
kill -s 0 $(cat pidfile); if ps -p $(cat pidfile) > /dev/null
if [ !$? ];
then return 1; then return 1;
else return 0; else
rm ./pidfile;
return 0;
fi fi
else else
return 0; return 0;

Loading…
Cancel
Save