forked from jehervy/node-virtual-gamepads
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
48 lines (35 loc) · 1.11 KB
/
main.js
File metadata and controls
48 lines (35 loc) · 1.11 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
45
46
47
48
// Generated by CoffeeScript 1.10.0
/*
Created by Robsdedude on 01/10/2017
Virtual gamepad application
*/
(function() {
var config, earlyDeathCount, forever, server, winston;
forever = require('forever-monitor');
config = require('./config.json');
winston = require('winston');
winston.level = config.logLevel;
server = new forever.Monitor('server.js', {
max: Infinity,
args: []
});
server.on('exit', function() {
return winston.log('error', 'server.js has exited (gave up to restart)');
});
earlyDeathCount = 0;
server.on('exit:code', function() {
var diedAfter;
diedAfter = Date.now() - server.ctime;
winston.log('info', 'diedAfter:', diedAfter);
earlyDeathCount = diedAfter < 5000 ? earlyDeathCount + 1 : 0;
winston.log('info', 'earlyDeathCount:', earlyDeathCount);
if (earlyDeathCount >= 3) {
winston.log('error', 'Died too often too fast.');
return server.stop();
}
});
server.on('restart', function() {
return winston.log('error', 'Forever restarting script for ' + server.times + ' time');
});
server.start();
}).call(this);