-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
executable file
·45 lines (37 loc) · 1.53 KB
/
main.rb
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
#!/usr/bin/ruby
require 'json'
require 'net/http'
require './client.rb'
zk_hosts = ENV.fetch('ZK_HOSTS')
host = ENV.fetch('HOSTNAME')
ip = ENV.fetch('IP')
nerve_config_path = ENV.fetch('NERVE') || '/etc/nerve/services'
synapse_config_path = ENV.fetch('SYNAPSE') || '/etc/synapse/services'
marathon = ENV.fetch('MARATHON')
ichnaea = Ichnaea.new
apps = ichnaea.request("http://#{marathon}:8080/v2/apps")
apps['apps'].each do |app|
target = ichnaea.request("http://#{marathon}:8080/v2/apps/#{app['id']}")
if target['app']['healthChecks'].empty? == false
i = 1
if target['app']['container']['docker'].key?('portMappings')
target['app']['tasks'].each do |task|
# wrote_file = false
id = target['app']['id'].tr("/", "")
if File.exist?("#{synapse_config_path}/#{id}.json}") == false
synapse_conf = ichnaea.build_synapse_json(zk_hosts, app)
ichnaea.write_config(synapse_config_path, id, synapse_conf)
end
if task['host'].include?(host) && File.exist?("#{nerve_config_path}/#{id}#{i}.json") == false
nerve_conf = ichnaea.build_nerve_json(ip, zk_hosts, app, task)
ichnaea.write_config(nerve_config_path, "#{id}#{i}", nerve_conf)
# wrote_file = true
i += 1
# elsif wrote_file == false && File.exist?("#{nerve_config_path}/#{id}#{i}.json")
elsif task['host'].include?(host) == false && File.exist?("#{nerve_config_path}/#{id}#{i}.json")
ichnaea.delete_config(nerve_config_path, "#{id}#{i}")
end
end
end
end
end