bin/flapper in flapjack-0.7.34 vs bin/flapper in flapjack-0.7.35

- old
+ new

@@ -23,25 +23,26 @@ end ensure Socket.do_not_reverse_lookup = orig end -def main(bind_ip) - start_every = 120 - stop_after = 60 - bind_port = 12345 +def main(bind_ip, bind_port, frequency) + raise "bind_port must be an integer" unless bind_port.is_a?(Integer) + start_every = frequency + stop_after = frequency.to_f / 2 + EM.run { - puts "#{Time.now}: starting server" + puts "#{Time.now}: starting server on #{bind_ip}:#{bind_port}" server_init = EM.start_server bind_ip, bind_port, Flapper EM.add_timer(stop_after) do puts "#{Time.now}: stopping server" EM.stop_server(server_init) end EM.add_periodic_timer(start_every) do - puts "#{Time.now}: starting server" + puts "#{Time.now}: starting server on #{bind_ip}:#{bind_port}" server = EM.start_server bind_ip, bind_port, Flapper EM.add_timer(stop_after) do puts "#{Time.now}: stopping server" EM.stop_server(server) end @@ -80,16 +81,26 @@ opts.on("-b", "--bind-ip [ADDRESS]", String, "ADDRESS (IPv4 or IPv6) for flapper to bind to") do |b| options.bind_ip = b end + opts.on("-P", "--bind-port [PORT]", String, "PORT for flapper to bind to") do |p| + options.bind_port = p.to_i + end + + opts.on("-f", "--frequency [SECONDS]", String, "oscillate with a frequency of SECONDS [120]") do |f| + options.frequency = f.to_f + end + end.parse!(ARGV) -pidfile = options.pidfile || "/var/run/flapjack/#{exe}.pid" -logfile = options.log_path || "/var/log/flapjack/#{exe}.log" daemonize = options.daemonize.nil? ? true : options.daemonize -bind_ip = options.bind_ip || local_ip +pidfile = options.pidfile || "/var/run/flapjack/#{exe}.pid" +logfile = options.log_path || "/var/log/flapjack/#{exe}.log" +bind_ip = options.bind_ip || local_ip +bind_port = options.bind_port || 12345 +frequency = options.frequency || 120.0 runner = Dante::Runner.new(exe, :pid_path => pidfile, :log_path => logfile) case ARGV[0] when "start" @@ -97,11 +108,11 @@ puts "#{exe} is already running." exit 1 else print "#{exe} starting..." runner.execute(:daemonize => daemonize) { - main(bind_ip) + main(bind_ip, bind_port, frequency) } puts " done." end when "stop" @@ -115,10 +126,10 @@ end when "restart" print "#{exe} restarting..." runner.execute(:daemonize => true, :restart => true) { - main(bind_ip) + main(bind_ip, bind_port, frequency) } puts " done." when "status" uptime = (runner.daemon_running?) ? (Time.now - File.stat(pidfile).ctime) : 0