lib/remote_syslog/cli.rb in remote_syslog-1.6.6.rc1 vs lib/remote_syslog/cli.rb in remote_syslog-1.6.6.rc2
- old
+ new
@@ -116,13 +116,11 @@
opts.on("--[no-]eventmachine-tail", "Enable or disable using eventmachine-tail") do |v|
@agent.eventmachine_tail = v
end
opts.on("--debug-log FILE", "Log internal debug messages") do |v|
- level = @agent.logger.level
- @agent.logger = Logger.new(v)
- @agent.logger.level = level
+ @agent.log_file = v
end
severities = Logger::Severity.constants + Logger::Severity.constants.map { |s| s.downcase }
opts.on("--debug-level LEVEL", severities, "Log internal debug messages at level") do |v|
@agent.logger.level = Logger::Severity.const_get(v.upcase)
@@ -220,15 +218,21 @@
@agent.exclude_pattern = Regexp.new(config['exclude_patterns'].map { |r| "(#{r})" }.join('|'))
end
end
def run
+ Thread.abort_on_exception = true
+
+ if @agent.tls && !eventmachine_supports_tls?
+ error "TLS is not supported by eventmachine installed on this system.\nThe openssl-devel/openssl-dev package must be installed before installing eventmachine."
+ end
+
if @no_detach
puts "Watching #{@agent.files.length} files/paths. Sending to #{@agent.destination_host}:#{@agent.destination_port} (#{@agent.tls ? 'TCP/TLS' : 'UDP'})."
@agent.run
else
- daemon = Servolux::Daemon.new(:server => @agent)
+ daemon = Servolux::Daemon.new(:server => @agent, :after_fork => method(:redirect_io))
if daemon.alive?
error "Already running at #{@agent.pid_file}. To run another instance, specify a different `--pid-file`.", true
end
@@ -243,9 +247,45 @@
error message
end
rescue Interrupt
exit(0)
end
+
+ def redirect_io
+ @agent.redirect_io!
+ end
+
+ # This is a terrible hack due to the fact that eventmachine does not
+ # provide a way to detect if it has been compiled with TLS support
+ # and throws a C++ std::runtime_error if TLS is not available that we
+ # are unable to catch from ruby
+ def eventmachine_supports_tls?
+ rio, wio, = IO.pipe
+
+ pid = fork do
+ rio.close
+ STDOUT.reopen wio
+ STDERR.reopen wio
+ STDOUT.sync = STDERR.sync = true
+ EM.run_block { EventMachine.connect('0.0.0.0', 1) { |c| c.start_tls } }
+ end
+
+ wio.close
+ result = rio.read
+ _, status = Process.wait2(pid)
+
+ @agent.logger.debug "Results from eventmachine_supports_tls: #{status}: #{result}"
+
+ if status.exitstatus == 0
+ return true
+ elsif result =~ /Encryption not available/
+ return false
+ else
+ # We'll assume we can work if the problem wasn't related to encryption
+ return true
+ end
+ end
+
def error(message, try_help = false)
puts "#{program_name}: #{message}"
if try_help
puts "Try `#{program_name} --help' for more information."