alexvollmer/daemon-spawn

Option to force reopen of log file.

Closed this issue · 3 comments

When running logrotate to rotate logs generated by daemon-spawn I need to restart the daemon in the postrotate script of logrotate. This works ok but it can take a long time since my daemons load the rails environment each time they start.

Is there a simple way (maybe a signal) that would tell daemon-spawn to reopen it's log file. This would be far more efficient that reloading the whole rails environment on each logrotate.

I haven't looked at the code in a while, but I don't believe daemon-spawn has such a capability. However I think what you're asking for is a pretty trivial fix. Do you have a patch for this? I'm up to my eyeballs in other projects so it's unlikely I'll get to this anytime soon.

After some attempts to implement this I realized this is not really something daemon-spawn should handle. Now I implement my workers so they take care of logging instead of writing to STDOUT and relying on daemon-spawn to handle it.

Using ruby Logger my workers can take care of their own log rotation.
Using syslogger I can send the logs to a remote log server and handle rotation via logrotate there.
Using rsyslog copytruncate option can also handle the problem.
The best solution I use now is cronolog that handles this problem even better.

http://blogs.helion-prime.com/2009/11/19/log-rotation-in-ruby-on-rails-applications.html

I'm glad you found a workable solution.