forked from dougbtv/kamailio-etcd-dispatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
78 lines (51 loc) · 1.97 KB
/
app.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Authored by: Doug Smith <[email protected]>
---------------------------------------
A tool to automatically build dynamically load balance asterisk hosts with coreos & etc.
Part of a High Availability setup with Asterisk under coreOS & docker.
Works in both "dispatcher" mode, which sits next to a Kamailio box and watches for Asterisk to announce itself.
And in "announce" mode where it announces to Kamailio that it's available (and pulses heartbeats to it)
You can always get help with:
node app.js --help
Run an dispatcher like:
node app.js --etcdhost 192.168.1.1 --timeout 25000
Run an announcer like:
node app.js --announce --etcdhost 192.168.1.1 --timeout 5500
*/
module.exports = function() {
var Options = require('./library/Options.js');
var options = new Options();
var opts = options.options;
// Create a log object.
var Log = require('./library/Log.js');
var log = new Log(opts);
var Alive = require('./library/Alive.js');
var alive = new Alive(log,opts);
// Check to see if etcd is alive...
alive.isalive(function(err){
if (!err) {
// Ok, let's load this next module based on announce/dispatch mode.
if (opts.announce) {
// We need to generate a name if there isn't one. We'll use a UUID.
if (!opts.announcename) {
var uuid = require('uuid');
opts.announcename = uuid.v4();
log.warn("autogenerated_announce_name",{ announcing_as: opts.announcename });
}
// Instantiate our main app.
var Announcer = require('./library/Announcer.js');
var announcer = new Announcer(log,opts);
} else {
// Create the Kamailio object (which writes dispatcher.list files)
var Kamailio = require('./library/Kamailio.js');
var kamailio = new Kamailio(log,opts);
// Instantiate our main app.
var Dispatcher = require('./library/Dispatcher.js');
var dispatcher = new Dispatcher(log,opts,kamailio);
}
} else {
// Ok, that's not good, we can't start if we can't see etcd.
throw err;
}
});
};