Class: ZkExec::Runner
Constant Summary
Constants included from ZkExec
Instance Method Summary collapse
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #run(args) ⇒ Object
Methods included from ZkExec
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
7 8 |
# File 'lib/zkexec/runner.rb', line 7 def initialize end |
Instance Method Details
#run(args) ⇒ Object
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 79 80 |
# File 'lib/zkexec/runner.rb', line 10 def run(args) = { :mirrors => [], :cluster => "localhost:2181", :health_interval => 30, :health_delay => 30 } opts = OptionParser.new do |opts| opts. = "Usage: zkexec [options]\n\nRun a command, and restart if the config files change on the remote zookeeper.\n\n" opts.on("-e", "--exec COMMAND", "Run this command") do |s| [:exec] = s end opts.on("-c", "--cluster HOST:PORT,...", "Comma-delimited list of zookeeper hosts") do |s| [:cluster] = s end opts.on("-H", "--health COMMAND", "Run this command to health-check") do |s| [:health] = s end opts.on("-i", "--health-interval INTERVAL", "Health-check every INTERVAL seconds") do |s| [:health_interval] = s.to_f end opts.on("-d", "--health-delay INTERVAL", "Wait before starting health checks") do |s| [:health_delay] = s.to_f end opts.on("-m", "--mirror LOCAL_PATH=ZK_PATH", "Mirror a config file from zookeeper to localhost") do |s| [:mirrors] << s.split("=") end opts.on("-l", "--lock NAME", "Name of a zk lockfile, used to enforce rolling restarts") do |s| [:lock] = s end opts.on("-a", "--alert COMMAND", "Run this command if the primary command returns","falsey or health checks fail for too long") do |s| [:alert] = s end opts.on("-v", "--verbose") do [:verbose] = true end opts.on("-s", "--silent") do [:silent] = true end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end opts.parse! unless [:exec] puts "Missing required option --exec. See --help for usage." exit 1 end silence! if [:silent] begin Executor.new().execute rescue => e if [:verbose] raise else log(e.) exit 1 end end end |