forked from antt001/parse-server-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
44 lines (39 loc) · 1.09 KB
/
start.js
File metadata and controls
44 lines (39 loc) · 1.09 KB
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
43
44
var cluster = require('cluster'),
os = require('os'),
stopSignals = [
'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
],
production = process.env.NODE_ENV == 'production';
var stopping = false;
cluster.on('disconnect', function(worker) {
if (production) {
if (!stopping) {
cluster.fork();
}
} else {
process.exit(1);
}
});
var numCPUs = os.cpus().length;
if (cluster.isMaster) {
var workerCount = process.env.NODE_CLUSTER_WORKERS || numCPUs || 4;
console.log('Starting ' + workerCount + ' workers...');
for (var i = 0; i < workerCount; i++) {
cluster.fork();
}
if (production) {
stopSignals.forEach(function (signal) {
process.on(signal, function () {
console.log('Got ' + signal + ', stopping workers...');
stopping = true;
cluster.disconnect(function () {
console.log('All workers stopped, exiting.');
process.exit(0);
});
});
});
}
} else {
require('./index.js');
}