-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (33 loc) · 1.05 KB
/
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
36
37
38
39
40
41
42
var config = require("./config/" + (process.env.NODE_ENV || "development") + ".json"),
cluster = require('cluster'),
numCPUs = config.workerCount || require('os').cpus().length;
// Force support for self-signed certificates
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
if(cluster.isMaster){
console.log("Starting server");
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
console.log('Worker ' + worker.process.pid + ' died, restarting');
cluster.fork();
});
// Handle error conditions
process.on("SIGTERM", function(){
console.log("Exited on SIGTERM");
process.exit(0);
});
process.on("SIGINT", function(){
console.log("Exited on SIGINT");
process.exit(0);
});
}else{
console.log("Starting worker "+process.pid);
require("./server");
}
process.on('uncaughtException', function(err) {
console.log("uncaughtException");
console.log(err.stack);
process.exit(1);
});