hot restart a node server in cluster mode.
npm install hot-restart
in master:
var restarter = require('hot-restart')();
restarter.on('restart', fuction () {
// fork new workers
});
// when new work forked
restarter.add(newWorker);
// when old work died
restarter.remove(oldWorker);
in worker:
var restarter = require('hot-restart/worker');
restarter({
disconnectTime: 1000,
exitTime: 2000
});
use signal to hot restart the server: kill -PIPE 3132
checkout the example.
- in master,
require('restarter')(opts)
, and add every worker torestarter
. - in workers,
require('restarter/worker')(opts)
, set disconnect options. kill -PIPE 3132
to tell master restart.- master will send restart message to all workers, then emit
restart
event, user need to start some new workers manually(also need to add these new works to restarter). - old workers got restart message, will disconnect after
disconnectTime
and exit afterexitTme
.
MIT