diff --git a/lib/logstash/web/server.rb b/lib/logstash/web/server.rb index 71ed30c34..8175305f3 100755 --- a/lib/logstash/web/server.rb +++ b/lib/logstash/web/server.rb @@ -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( \