thuehlinger / daemons

Ruby daemons gem official repository
MIT License
648 stars 71 forks source link

Use syslog if log_output is not set #43

Closed lzap closed 8 years ago

lzap commented 9 years ago

When using daemons with SELinux confined domain, there is a file descriptor leak when daemon output is redirected to a file which is a good practice. This patch tries to redirect stdout/err to syslog if it's available in case log_output is not set, then it falls back to /dev/null. It uses a small gem syslogio for the IO wrapper, if you don't like new dep we could pull this in the project.

Also the patch changes usage of STD* constants in favor of global variables, which is the preferred way of redirecting. This code is untested, let's discuss how you like this.

lzap commented 9 years ago

Oh the https://github.com/phemmer/ruby-syslogio is not actually a gem, pulled that in, need to clarify the license tho.

lzap commented 9 years ago

Some tests fail because of new development gem incompatibility tho.

lzap commented 9 years ago

Also alternatively, there is a trick to use Syslog::Logger (Ruby 2.0+ only) as an IO object:

  require 'syslog/logger'
  ::Syslog::Logger.class_eval { alias_method :write, :info }
phemmer commented 8 years ago

I added MIT license to phemmer/ruby-syslogio. MIT license is compatible with BSD license. So you're good to do with it as you like :-)

lzap commented 8 years ago

Thanks. @thuehlinger do you like this and should I finish the code?

thuehlinger commented 8 years ago

I'm fine with it. @lzap please go on.

lzap commented 8 years ago

Pushed my prototype, let's see how tests goes first.

thuehlinger commented 8 years ago

Seems to look fine, apart from the tests that fail because of missing byebug. Right?

lzap commented 8 years ago

Sorry for the delay, it was on my radar, thanks!