mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
- Proper daemonizing
- Add --logfile for directing STDOUT and STDERR to a file. - Require logfile if we are to daemonize - Set parent process $0 to 'logstash (supervisor)'
This commit is contained in:
parent
c151016413
commit
26082d9309
1 changed files with 35 additions and 0 deletions
|
@ -21,8 +21,38 @@ def main(args)
|
|||
options = parse_options(args)
|
||||
children = {}
|
||||
|
||||
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]
|
||||
|
@ -55,6 +85,7 @@ def main(args)
|
|||
end
|
||||
end
|
||||
|
||||
$0 = "logstashd (supervisor)"
|
||||
Signal.trap("INT") do
|
||||
children.keys.each { |pid| Process.kill("TERM", pid) rescue nil }
|
||||
Process.waitall
|
||||
|
@ -135,6 +166,10 @@ def parse_options(args)
|
|||
puts opts
|
||||
exit(0)
|
||||
end
|
||||
|
||||
opts.on("-l FILE", "--logfile FILE", "File path to put logs") do |x|
|
||||
options[:logfile] = x
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue