-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (50 loc) · 1.19 KB
/
index.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
// Generated by CoffeeScript 1.9.2
var cluster;
cluster = require('cluster');
module.exports = function(cb) {
var shutdown, toma;
if (cluster.isWorker) {
return cb();
}
toma = {};
cluster.on('exit', function(worker) {
if (toma[worker.id.toString()] == null) {
cluster.fork();
}
if (Object.keys(cluster.workers).length === 0) {
return process.exit();
}
});
cluster.fork();
process.on('SIGHUP', function() {
var worker;
worker = cluster.fork();
return worker.once('listening', function(address) {
var child, id, ref, results;
ref = cluster.workers;
results = [];
for (id in ref) {
child = ref[id];
if (id === worker.id.toString()) {
continue;
}
toma[id.toString()] = true;
results.push(child.process.kill());
}
return results;
});
});
shutdown = function() {
var child, id, ref, results;
ref = cluster.workers;
results = [];
for (id in ref) {
child = ref[id];
toma[id.toString()] = true;
results.push(child.process.kill());
}
return results;
};
process.on('SIGINT', shutdown);
return process.on('SIGTERM', shutdown);
};