/
catch-up.rb
executable file
·51 lines (46 loc) · 1.34 KB
/
catch-up.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
46
47
48
49
50
51
#!/bin/bash ruby
########################################
#
#
# For each proxied host, if there is an upstr
########################################
#
# Configuring File path
#
base = File.dirname( __FILE__ )
$LOAD_PATH.unshift( base )
$LOAD_PATH.unshift( File.join( File.dirname( __FILE__ ), 'lib' ) )
#
# Find the file
#
require "cnp/output"
require 'etcd'
class CatchUp
def main( config )
begin
@etcd = Etcd.client
base_dir = @etcd.get( config.etcd_prefix ).node
if not base_dir.directory?
puts "WARNING: EtcD base key #{config.etcd_prefix} is not a directory"
else
generator = CNP::ErbConfigGenerator.new( config.lb_dir, config.etcd_prefix, config.template, config.notify_key )
base_dir.children.each do |child|
generator.generate_for_etcd( child.key )
end
end
rescue Etcd::KeyNotFound => e
puts "WARNING: configuration key (#{config.etcd_prefix}) not found"
end
end
end
#
# CLI
#
require 'trollop'
opts = Trollop::options do
opt :etcd_prefix, "etcd load balancer prefix", :default => "/lb"
opt :lb_dir, "Place to store the load balancer configurations files", :type => :string, :required => true
opt :notify_key, "Key to notify nginx on the target host to reload the configuration", :type => :string
opt :template, "Use an alternative ERB template for dpeloyment", :type => :string
end
CatchUp.new.main( opts )