-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (31 loc) · 930 Bytes
/
server.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
var HttpServer = require('./HttpServer');
var Logger = require('./Logger');
var Raft = require('./Raft');
var utils = require('./utils');
var config = require('./config');
// Setup server hosts
GLOBAL.servers = utils.setupHosts();
var role = process.argv[2];
var serverId = parseInt(process.argv[3]); // Important: server ids are always integers, not strings!
var port = config.portRangeStart + serverId;
// Setup logger
GLOBAL.logger = new Logger({
listenForRemoteLogs: role === 'logger',
deferLogging: false, // role != 'logger',
logServerHost: config.host,
logServerPort: 7770,
serverId: serverId
});
var raft = null;
if(role != 'logger') {
// Setup Raft
raft = new Raft({
serverId: serverId,
host: config.host,
port: port,
electionTimeoutInterval: utils.randomInt(2000, 2300),
heartbeatTimeoutInterval: 500
});
raft.start();
logger.log('Raft server running at http://' + config.host + ':' + port);
}