bin/replication_status in reptile-0.0.6 vs bin/replication_status in reptile-0.1.0

- old
+ new

@@ -1,47 +1,53 @@ #!/usr/bin/env ruby -require 'rubygems' require 'optparse' + +require 'rubygems' require 'reptile' +Reptile::Log.level = :info +Mixlib::Log::Formatter.show_time = false + commands = [] OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($0)} [path_to_config_file]" opts.on("-h", "--help", "Displays this help info") do puts opts exit 0 end - - opts.on("-s", "--status", "Displays the slave status") do + + opts.on("--status", "Displays the slave status") do commands << 'check_slaves' end - - opts.on("-d", "--diff", "Checks the row count difference between master and slave") do + + opts.on("--diff", "Checks the row count difference between master and slave") do commands << 'diff_tables' end - - opts.on("-r", "--report", "Sends a report email") do + + opts.on("--report", "Prints a report") do commands << 'report' end - - opts.on("-b", "--heartbeat", "Checks the heartbeat timestamp difference between master and slave") do + + opts.on("--heartbeat", "Checks the heartbeat timestamp difference between master and slave") do commands << 'heartbeat' end - - opts.on("-x", "--stop_slaves", "Stops all slaves") do + + opts.on("--stop-slaves", "Stops all slaves") do commands << 'stop_slaves' end - - opts.on("-g", "--start_slaves", "Starts all slaves") do + + opts.on("--start-slaves", "Starts all slaves") do commands << 'start_slaves' end - - opts.on("-e", "--errors", "Show only errors.") do - commands << 'errors' + + log_levels = [:debug, :info, :warn, :error, :fatal] + opts.on("-l", "--log-level [LEVEL]", log_levels, + "Specify log level (#{log_levels.join(',')})") do |t| + Reptile::Log.level = t.to_sym end begin opts.parse!(ARGV) rescue OptionParser::ParseError => e @@ -50,42 +56,38 @@ exit 1 end end if !ARGV.empty? && ARGV.length > 1 - abort "Too many arguments; please specify only the directory containing the 'reptile.yml' file, or a yml config file itself." + abort "Too many arguments; please specify only the config file." end -config_file_name = "reptile.yml" -config_file_locations = ["/etc/#{config_file_name}", "/etc/reptile/#{config_file_name}", "./#{config_file_name}"] config_location_param = ARGV.first config_file = nil if config_location_param - if File.directory?(config_location_param) && File.exist?(File.join(config_location_param, config_file_name)) - config_file = File.join(config_location_param, config_file_name) - elsif File.exist?(config_location_param) && !File.directory?(config_location_param) + if File.exist?(config_location_param) && !File.directory?(config_location_param) config_file = config_location_param else - abort "Please specify the directory containing the '#{config_file_name}' file, or the config file itself." + abort "Please specify the config file." end else - config_file_locations.each do |f| + ["/etc/reptile.yml", "/etc/reptile/reptile.yml", "./reptile.yml"].each do |f| if File.exist?(f) config_file = f break end end if config_file.nil? abort "Couldn't find a config file at #{config_file_locations.join(', ')}" end end - +Reptile::Log.debug "Loading config from #{config_file}" Reptile::ReplicationMonitor.load_config_file(config_file) if (commands.include?('start_slaves') || commands.include?('stop_slaves')) - Reptile::Runner.send(commands[0]) + Reptile::Runner.send(commands[0]) else (commands.empty? ? ['check_slaves', 'heartbeat', 'diff_tables'] : commands).each do |command| Reptile::ReplicationMonitor.send(command) end end \ No newline at end of file