diff --git a/loader.js b/loader.js index c5f325ad9d..42d198c047 100644 --- a/loader.js +++ b/loader.js @@ -68,6 +68,11 @@ Loader.init = function() { }); }); break; + case 'listening': + if (message.primary) { + Loader.primaryWorker = parseInt(worker.id, 10); + } + break; case 'user:connect': case 'user:disconnect': notifyWorkers(worker, message); @@ -106,7 +111,11 @@ Loader.init = function() { console.log('[cluster] Child Process (' + worker.process.pid + ') has exited (code: ' + code + ')'); if (!worker.suicide) { console.log('[cluster] Spinning up another process...') - cluster.fork(); + + var wasPrimary = parseInt(worker.id, 10) === Loader.primaryWorker; + cluster.fork({ + handle_jobs: wasPrimary + }); } }); @@ -116,9 +125,14 @@ Loader.init = function() { }; Loader.start = function() { + Loader.primaryWorker = 1; + for(var x=0;x