- make the agent use LogStash::Program

This commit is contained in:
Jordan Sissel 2009-10-21 01:02:38 +00:00
parent 21f04f4e8b
commit 875a6a9fee

View file

@ -3,6 +3,7 @@
$: << File.join(File.dirname(__FILE__), "..")
require 'lib/net/clients/agent'
require 'lib/program'
require 'logger'
require 'optparse'
@ -13,51 +14,17 @@ $logger.level = Logger::INFO
$logger.progname = $progname
$logger.datetime_format = "%Y-%m-%d %H:%M:%S"
class Agent < LogStash::Program
def run
super
agent = LogStash::Net::Clients::Agent.new(@options[:config], $logger)
agent.run
end
end
def main(args)
Thread::abort_on_exception = true
options = parse_options(args)
if options[:logfile]
logfd = File.open(options[:logfile], "a")
$stdout.reopen(logfd)
$stderr.reopen(logfd)
else
# Require a logfile for daemonization
if options[:daemonize]
$stderr.puts "Daemonizing requires you specify a logfile (--logfile), " \
"none was given"
return 1
end
end
if options[:daemonize]
fork and exit(0)
# Copied mostly from Daemons.daemonize, but since the ruby 1.8 'daemons'
# and gem 'daemons' have api variances, let's do it ourselves since nobody
# agrees.
trap("SIGHUP", "IGNORE")
ObjectSpace.each_object(IO) do |io|
# closing STDIN is ok, but keep STDOUT and STDERR
# close everything else
next if [STDOUT, STDERR].include?(io)
begin
unless io.closed?
io.close
end
rescue ::Exception
end
end
end
if options[:pidfile]
File.open(options[:pidfile], "w+") { |f| f.puts $$ }
end
agent = LogStash::Net::Clients::Agent.new(options[:config], $logger)
agent.run
Agent.new(options).run
end
def parse_options(args)