class GraphiteAPI::Runner
Public Class Methods
new(argv)
click to toggle source
# File lib/graphite-api/runner.rb, line 7 def initialize argv CLI.parse argv, options validate_options end
Public Instance Methods
run()
click to toggle source
# File lib/graphite-api/runner.rb, line 12 def run Logger.init Hash[[:std,:level].zip options.values_at(:log_file, :log_level) ] options[:daemonize] ? daemonize(options[:pid], &method(:run!)) : run! end
Private Instance Methods
daemonize(pid, &block)
click to toggle source
# File lib/graphite-api/runner.rb, line 19 def daemonize pid, &block block_given? or raise ArgumentError.new "the block is missing..." fork do Process.setsid exit if fork Dir.chdir '/tmp' STDIN.reopen('/dev/null') STDOUT.reopen('/dev/null','a') STDERR.reopen('/dev/null','a') File.open(pid,'w') { |f| f.write(Process.pid) } rescue nil block.call end end
options()
click to toggle source
# File lib/graphite-api/runner.rb, line 43 def options @options ||= Utils.default_middleware_options end
run!()
click to toggle source
# File lib/graphite-api/runner.rb, line 34 def run! begin Middleware.start options rescue Interrupt Logger.info "Shutting down..." Zscheduler.stop end end
validate_options()
click to toggle source
# File lib/graphite-api/runner.rb, line 47 def validate_options abort "You must specify at least one graphite host" if options[:backends].empty? end