forked from kobotoolbox/enketo-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
26 lines (21 loc) · 784 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env node
'use strict';
var cluster = require( 'cluster' );
var numCPUs = require( 'os' ).cpus().length;
if ( cluster.isMaster ) {
// Fork workers.
for ( var i = 0; i < numCPUs; i++ ) {
cluster.fork();
}
cluster.on( 'exit', function( worker ) {
console.log( 'Worker ' + worker.process.pid + ' sadly passed away. It will be reincarnated.' );
cluster.fork();
} );
} else {
var app = require( './config/express' );
var server = app.listen( app.get( 'port' ), function() {
var worker = ( cluster.worker ) ? cluster.worker.id : 'Master';
var msg = 'Worker ' + worker + ' ready for duty at port ' + server.address().port + '! (environment: ' + app.get( 'env' ) + ')';
console.log( msg );
} );
}