-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (27 loc) · 814 Bytes
/
server.js
File metadata and controls
35 lines (27 loc) · 814 Bytes
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
#!/usr/bin/env node
/* eslint global-require: "off" */
// Use strict mode in all project modules
require('auto-strict');
// Initialize config, logger and cluster
const logger = require('./lib/logger');
const cluster = require('./lib/cluster');
// Cluster callback functions
function startMaster() {
logger.info(`Master started on pid ${process.pid}, forking ${process.worker.count} processes`);
}
function startWorker(id) {
process.worker.id = id;
logger.info('Worker started');
process.on('SIGTERM', () => {
logger.info('Worker exiting...');
process.exit();
});
require('./worker');
}
function startNoCluster() {
require('./worker');
}
// Start cluster support
cluster(startMaster, startWorker, startNoCluster).catch((err) => {
logger.error(`Failed to start: ${err.message}`);
});