2014-08-19 23:26:01 +00:00
|
|
|
var cluster = require('cluster');
|
2014-08-13 21:06:14 +00:00
|
|
|
var app = require('./app');
|
2013-10-19 22:59:17 +00:00
|
|
|
|
2014-08-19 23:26:01 +00:00
|
|
|
var count = require('os').cpus().length;
|
|
|
|
|
|
|
|
if(!process.env.NO_CLUSTER && cluster.isMaster) {
|
|
|
|
for(var i = 0; i < count; i++) {
|
|
|
|
cluster.fork();
|
|
|
|
}
|
2014-08-31 19:51:13 +00:00
|
|
|
cluster.on('exit', function() {
|
2014-08-19 23:26:01 +00:00
|
|
|
console.log('Worker died. Spawning a new process...');
|
|
|
|
cluster.fork();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Listen on port 3000
|
|
|
|
var port = process.env.PORT || 3000;
|
|
|
|
app.listen(port, null, function() {
|
|
|
|
console.log('Server started: http://localhost:' + port);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|