- Add daemonize and logfile flags support to logstash-web.

This commit is contained in:
Jordan Sissel 2010-12-22 16:16:15 -08:00
parent 1317ed187f
commit a4a4490baf

View file

@ -99,9 +99,42 @@ class LogStash::Web::Server < Sinatra::Base
body haml :"search/ajax", :layout => !request.xhr?
end # elasticsearch.search
end # apost '/search/ajax'
end # class LogStashWeb
require "optparse"
Settings = Struct.new(:daemonize, :logfile)
settings = Settings.new
progname = File.basename($0)
opts = OptionParser.new do |opts|
opts.banner = "Usage: #{progname} [options]"
opts.on("-d", "--daemonize", "Daemonize (default is run in foreground)") do
settings.daemonize = true
end
opts.on("-l", "--log FILE", "Log to a given path. Default is stdout.") do |path|
settings.logfile = path
end
end
opts.parse!
if settings.daemonize
if Process.fork == nil
Process.setsid
else
exit(0)
end
end
if settings.logfile
logfile = File.open(settings.logfile, "w")
STDOUT.reopen(logfile)
STDERR.reopen(logfile)
end
Rack::Handler::Thin.run(
Rack::CommonLogger.new( \
Rack::ShowExceptions.new( \