Last active
December 22, 2015 04:28
-
-
Save Zyber17/6417321 to your computer and use it in GitHub Desktop.
App with setup and clusters
This file contains hidden or 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 app, cluster, cpu, cpus, express, http, path, setup; | |
cluster = require('cluster'); | |
if (cluster.isMaster) { | |
if (process.env.NODE_ENV === 'setup') { | |
console.log('Starting setup process.'); | |
express = require('express'); | |
setup = require('./routes/setup'); | |
app = express(); | |
app.configure('setup', function() { | |
setup(function(resp) { | |
console.log(resp); | |
process.kill(process.pid, "SIGTERM"); | |
}); | |
}); | |
} else { | |
cpus = require('os').cpus().length; | |
for (var i = 0; i < cpus; i++) { | |
cluster.fork(); | |
} | |
cluster.on('exit', function(worker) { | |
console.log("Worker " + worker.id + " died :("); | |
cluster.fork(); | |
}); | |
} | |
}else if (process.env.NODE_ENV !== 'setup') { | |
// Stuff your app does here | |
}else { | |
console.log("Uhh. This should never happen. See app.js."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment