class BaselineRedAgent::CLI
Public Class Methods
new()
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 12 def initialize end
Public Instance Methods
handle_signal(sig)
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 40 def handle_signal(sig) case sig when 'INT' raise Interrupt when 'TERM' raise Interrupt end end
options()
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 49 def options BaselineRedAgent.options end
parse(args=ARGV)
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 15 def parse(args=ARGV) setup_options(args) daemonize write_pid end
run()
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 21 def run worker = BaselineRedAgent::Worker.new worker.load_plugins begin BaselineRedAgent.logger.info "Starting BaselineRedAgent." worker.start while readable_io = IO.select([self_read]) signal = readable_io.first[0].gets.strip handle_signal(signal) end rescue Interrupt BaselineRedAgent.logger.info "Shutting down BaselineRedAgent." worker.stop exit(0) end end
Private Instance Methods
daemonize()
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 55 def daemonize return unless options[:daemon] ::Process.daemon(true, true) end
parse_options(argv)
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 66 def parse_options(argv) opts = {} parser = OptionParser.new do |o| o.banner = "baseline_red_agent [options]" o.on '-d', '--daemon', "Daemonize process" do |arg| opts[:daemon] = arg end o.on '-l', '--license-key LICENSE_KEY', "License Key" do |arg| opts[:license_key] = arg end o.on '--host HOST', 'Baseline Red Host' do |arg| opts[:host] = arg end o.on '--ssl', 'Enable SSL To App Perf' do |arg| opts[:ssl] = arg end o.on '-v', '--verbose', 'Enable verbose logging' do |arg| BaselineRedAgent.logger.level = ::Logger::DEBUG end o.on_tail "-h", "--help", "Show help" do puts o exit end end parser.parse!(argv) if opts[:license_key].to_s.length == 0 BaselineRedAgent.logger.info "No license key specified. Exiting." exit 1 end BaselineRedAgent.logger.info "Initializing with options: #{opts}" opts end
setup_options(args)
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 61 def setup_options(args) opts = parse_options(args) options.merge!(opts) end
write_pid()
click to toggle source
# File lib/baseline_red_agent/cli.rb, line 110 def write_pid if path = options[:pidfile] pidfile = File.expand_path(path) File.open(pidfile, 'w') do |f| f.puts ::Process.pid end end end