forked from N4SJAMK/teamboard-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (30 loc) · 842 Bytes
/
index.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
27
28
29
30
31
32
33
34
35
'use strict';
var nr = require('newrelic');
var os = require('os');
var cluster = require('cluster');
// Fork worker processes to each CPU core.
if(cluster.isMaster) {
for(var i = 0; i < os.cpus().length; i++) {
cluster.fork();
}
}
// Run the forked worker process.
else {
var server = require('./server');
/**
* Attempt some form of cleanup when the process is killed.
*/
var shutdown = function() {
server.shutdown(function() {
console.log(
'Worker [', cluster.worker.process.pid, '] going down...');
process.exit(0);
});
}
// Kill the process on 'SIGINT' and 'SIGTERM' signals.
process.on('SIGINT', shutdown).on('SIGTERM', shutdown);
// Start the server application on this worker process.
server.listen(function() {
console.log('Worker [', cluster.worker.process.pid, '] listening');
});
}