Method: Metrix::CLI#run

Defined in:
lib/metrix/cli.rb

#runObject



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
81
# File 'lib/metrix/cli.rb', line 38

def run
  parse!
  case @action
  when "start"
    load_configs_from_file!
    if running?
      logger.warn "refuse to run. seems that #{pid_path} exists!"
      abort "not allowed to run" if running?
    end
    if daemonize?
      pid = Process.fork do
        start
      end
      sleep 1
      Process.detach(pid)
    else
      start
    end
  when "status"
    if File.exists?(pid_path)
      logger.debug "#{pid_path} exists"
      puts "STATUS: running with pid #{File.read(pid_path).strip}"
      exit 0
    else
      logger.debug "#{pid_path} does not exist"
      puts "STATUS: not running"
      exit 1
    end
  when "stop"
    abort "not running!" if !running?
    pid = File.read(pid_path).strip
    logger.info "killing pid #{pid}"
    system "kill #{pid}"
    puts "killed #{pid}"
  when "configtest"
    load_configs_from_file!
    puts "running configtest #{attributes.inspect}"
  when "list_metrics"
    puts Metrix.known_metrics.join("\n")
  else
    logger.warn "action #{action} unknown!"
    abort "action #{action} unknown!"
  end
end