mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
- make the agent use LogStash::Program
This commit is contained in:
parent
21f04f4e8b
commit
875a6a9fee
1 changed files with 10 additions and 43 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue