-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·44 lines (34 loc) · 842 Bytes
/
main.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
43
44
'use strict';
var fork = require('child_process').fork,
server
;
function start() {
var forkArgs = process.argv.slice(0);
forkArgs.splice(0,2);
server = fork('./server', forkArgs);
server.on('close', function(code, signal) {
stop();
console.log(`Server disconnected [CODE: ${code}, SIGNAL: ${signal}] restarting\n`);
start();
});
server.on('disconnect', function(e) {
stop();
console.log('Server disconnected restarting...\n');
start();
});
server.on('message', function(msg) {
if(msg.toString() === 'SHUTDOWN') {
console.log('Shutdown received, stoping server and watchdog...\n');
stop();
process.exit(0);
}
});
server.on('error', function(err) {
console.error(err);
});
}
function stop() {
server.removeAllListeners();
server.kill();
}
start();