The way I did this was to make sure that at least 2 workers were working for me, and then reboot only once.
This bit of code will automatically restart workers who commit suicide through cluster.worker.destroy ()
cluster.on('exit', function(worker, code, signal) { if (worker.suicide === true) { console.log(new Date()+' Worker committed suicide'); cluster.fork(); } });
From there, it's a simple matter for every worker to commit suicide using setTimeout () (or any other condition you want to use). My approach was to get the boss to kill the workers:
function killWorker(worker) { return function() { worker.destroy(); }; }
As you can see, this inserts a 5-minute delay between workers reloading, which gives each worker enough time to restart himself - this means that there should never be a case where all workers are omitted.
source share