Last active
December 20, 2015 23:28
-
-
Save BorePlusPlus/6212241 to your computer and use it in GitHub Desktop.
node.js cluster kill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require('cluster'); | |
if (cluster.isMaster) { | |
cluster.fork(); | |
cluster.on('exit', function(worker, code, signal) { | |
console.log('Worker exited:', worker.process.pid); | |
}); | |
setTimeout(function () { | |
for (var id in cluster.workers) { | |
var worker = cluster.workers[id]; | |
worker.kill('SIGUSR2'); | |
} | |
}, 2000); | |
} else { | |
process.on('SIGUSR2', function() { | |
//WHY DOES THIS NOT GET CALLED? http://nodejs.org/api/cluster.html#cluster_worker_kill_signal_sigterm | |
console.log('SIGUSR2 called', process.pid); | |
}); | |
console.log('Worker listening for SIGUSR2', process.pid); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it's very interesting that
worker.kill('SIGUSR1');
worker.process.kill('SIGUSR1');
did completely different things for me as i was probably trying the same thing above.
and the 2nd would actually work as expected:
worker:11380 listening!
Hit SIGUSR1 - starting debugger agent.
debugger listening on port 5858