remote_syslog 1.6.6.rc1 → 1.6.6.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  module RemoteSyslog
2
- VERSION = "1.6.6.rc1"
2
+ VERSION = "1.6.6.rc2"
3
3
  end
4
4
 
@@ -47,6 +47,22 @@ module RemoteSyslog
47
47
  super('remote_syslog', :logger => logger, :pid_file => options[:pid_file])
48
48
  end
49
49
 
50
+ def log_file=(file)
51
+ @log_file = File.expand_path(file)
52
+
53
+ level = self.logger.level
54
+ self.logger = Logger.new(file)
55
+ self.logger.level = level
56
+ end
57
+
58
+ def redirect_io!
59
+ if @log_file
60
+ STDOUT.reopen(@log_file, 'a')
61
+ STDERR.reopen(@log_file, 'a')
62
+ STDERR.sync = STDOUT.sync = true
63
+ end
64
+ end
65
+
50
66
  def files=(files)
51
67
  @files = [ @files, files ].flatten.compact.uniq
52
68
  end
@@ -118,9 +118,7 @@ module RemoteSyslog
118
118
  @agent.eventmachine_tail = v
119
119
  end
120
120
  opts.on("--debug-log FILE", "Log internal debug messages") do |v|
121
- level = @agent.logger.level
122
- @agent.logger = Logger.new(v)
123
- @agent.logger.level = level
121
+ @agent.log_file = v
124
122
  end
125
123
 
126
124
  severities = Logger::Severity.constants + Logger::Severity.constants.map { |s| s.downcase }
@@ -222,11 +220,17 @@ module RemoteSyslog
222
220
  end
223
221
 
224
222
  def run
223
+ Thread.abort_on_exception = true
224
+
225
+ if @agent.tls && !eventmachine_supports_tls?
226
+ error "TLS is not supported by eventmachine installed on this system.\nThe openssl-devel/openssl-dev package must be installed before installing eventmachine."
227
+ end
228
+
225
229
  if @no_detach
226
230
  puts "Watching #{@agent.files.length} files/paths. Sending to #{@agent.destination_host}:#{@agent.destination_port} (#{@agent.tls ? 'TCP/TLS' : 'UDP'})."
227
231
  @agent.run
228
232
  else
229
- daemon = Servolux::Daemon.new(:server => @agent)
233
+ daemon = Servolux::Daemon.new(:server => @agent, :after_fork => method(:redirect_io))
230
234
 
231
235
  if daemon.alive?
232
236
  error "Already running at #{@agent.pid_file}. To run another instance, specify a different `--pid-file`.", true
@@ -246,6 +250,42 @@ module RemoteSyslog
246
250
  exit(0)
247
251
  end
248
252
 
253
+ def redirect_io
254
+ @agent.redirect_io!
255
+ end
256
+
257
+ # This is a terrible hack due to the fact that eventmachine does not
258
+ # provide a way to detect if it has been compiled with TLS support
259
+ # and throws a C++ std::runtime_error if TLS is not available that we
260
+ # are unable to catch from ruby
261
+ def eventmachine_supports_tls?
262
+ rio, wio, = IO.pipe
263
+
264
+ pid = fork do
265
+ rio.close
266
+ STDOUT.reopen wio
267
+ STDERR.reopen wio
268
+ STDOUT.sync = STDERR.sync = true
269
+ EM.run_block { EventMachine.connect('0.0.0.0', 1) { |c| c.start_tls } }
270
+ end
271
+
272
+ wio.close
273
+ result = rio.read
274
+ _, status = Process.wait2(pid)
275
+
276
+ @agent.logger.debug "Results from eventmachine_supports_tls: #{status}: #{result}"
277
+
278
+ if status.exitstatus == 0
279
+ return true
280
+ elsif result =~ /Encryption not available/
281
+ return false
282
+ else
283
+ # We'll assume we can work if the problem wasn't related to encryption
284
+ return true
285
+ end
286
+ end
287
+
288
+
249
289
  def error(message, try_help = false)
250
290
  puts "#{program_name}: #{message}"
251
291
  if try_help
@@ -33,6 +33,8 @@ module RemoteSyslog
33
33
  @callback.call(@tag, line)
34
34
  end
35
35
  end
36
+ rescue => e
37
+ @logger.error "Unhandled FileTailReader Exception: #{e.class}: #{e.message}:\n\t#{e.backtrace.join("\n\t")}"
36
38
  end
37
39
  end
38
40
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  ## If your rubyforge_project name is different, then edit it and comment out
9
9
  ## the sub! line in the Rakefile
10
10
  s.name = 'remote_syslog'
11
- s.version = '1.6.6.rc1'
11
+ s.version = '1.6.6.rc2'
12
12
  s.date = '2012-08-13'
13
13
  s.rubyforge_project = 'remote_syslog'
14
14
 
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 6
8
8
  - 6
9
- - rc1
10
- version: 1.6.6.rc1
9
+ - rc2
10
+ version: 1.6.6.rc2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Troy Davis