-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (27 loc) · 921 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
36
37
38
39
const cluster = require('cluster');
const fs = require('fs');
const process = require('process');
const os = require('os');
process.chdir(__dirname);
if (!fs.existsSync('config.json')) {
fs.copyFileSync('config.default.json', 'config.json');
}
const config = require('./config.json');
let clusterWorkerSize = config.workers || os.cpus().length;
if (cluster.isMaster) {
let workers = [];
for (let i = 0; i < clusterWorkerSize; i++) {
workers.push(cluster.fork());
}
cluster.on('exit', worker => {
console.log('Worker ', worker.id, ' has exited.');
});
const DatabaseServer = require('./database_server/database_server.js');
new DatabaseServer(workers);
if (config.httpsEnabled) {
require('./acme-master.js')(config);
}
} else {
const HttpServer = require('./http_server/http_server.js');
new HttpServer(config);
}