-
Notifications
You must be signed in to change notification settings - Fork 3
/
resist.js
executable file
·56 lines (48 loc) · 1.45 KB
/
resist.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
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
var os = require('os'),
cluster = require('cluster'),
resistConfigOptions = require("./conf/resist-server-config"),
routes = require("./conf/routes"),
ResistServer = require('./lib/resist_server'),
ResistConfig = require('./lib/resist_config');
//
// You should not need to change anything below this line,
// unless you know what you're doing.
//
var cpus = os.cpus().length;
var DEBUG = true;
if (!(DEBUG)) {
process.env.NODE_ENV = "production";
}
process.on('uncaughtException', function (err) {
if (err.stack) {
err.stack.split("\n").forEach(function (line) {
console.error(line);
});
}
else {
console.error('Caught exception: ' + err);
}
process.exit(1);
});
if (cluster.isMaster) {
for (var i = 0; i < cpus; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
if (DEBUG) { console.log('worker ' + worker.process.pid + ' died'); }
setTimeout(function () { cluster.fork(); }, 5000);
});
} else {
if (DEBUG) { console.log('worker ' + process.pid + ': started'); }
var resistConfig = new ResistConfig(resistConfigOptions, function (config) {
// XXX: so yeah, make this syntax correct
for (var key in routes) {
config.setHost(key, routes[key]);
}
var resistServer = new ResistServer({
"config" : config,
"debug" : DEBUG
});
});
}