-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathloader.js
More file actions
40 lines (33 loc) · 979 Bytes
/
loader.js
File metadata and controls
40 lines (33 loc) · 979 Bytes
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
var cp = require('child_process');
var Loader = function(id, passphrase, key, ids) {
this.id = id;
this.passphrase = passphrase;
this.key = key;
this.ids = ids;
};
Loader.prototype.load = function() {
var self = this;
this.proc = cp.fork('lib/outkept.js');
this.proc.send({'boot': this.passphrase, 'key': this.key, 'ids': this.ids, 'id': this.id});
this.proc.on('exit', function (code) {
console.log(self.id + ' - Loader has exited ' + code);
/*
//TODO: each loader has it's servers to mark as offline
vendors.mongo(function(db) {
db.collection('servers').update({}, {$set: {connected: false}}, { multi: true }, function() {
self.load();
});
});
*/
self.load();
});
};
Loader.prototype.loadServer = function(id) {
this.ids.push(id);
this.proc.send({'server': id});
};
Loader.prototype.kill = function() {
this.proc.removeAllListeners('exit');
this.proc.kill('SIGHUP');
};
module.exports = Loader;