2

(Hope I have the right SE site for this question, apologies if not.)

I have a Ruby-on-Rails application that is deployed using Apache+mod_rails (passenger). It uses MySQL for the database backend. I'm using SyslogLogger to send the RoR log to syslog and using logrotate via a daily cron job to rotate the logs.

What I've found is that the RoR app hangs if it is in the middle of something when the logs are rotated. I've tried putting copytruncate in the logrotate configuration, but it appears that this also affects the apache logs (maybe because the RoR error logs go to the error.log file of apache) and - possibly - also the MySQL logs (maybe - it's sometimes hard to correlate exactly which log causes the crash).

Searching on the internet turns up some different solutions on log rotation, one is to use the copytruncate key, another is to use cronolog, but I've yet to find one that directly addresses the issue I'm seeing.

So is there a known solution for this? What is the "right way" to rotate logs on a RoR application (using apache and mod_rails for deployment)? Should I just put copytruncate in every logrotate configuration file that is vaguely related with the application?

2 Answers2

2

Instead of 'copytruncate', these lines worked for me in the logrotate file for my rails app:

  postrotate
    touch /your-rails-directory/tmp/restart.txt
  endscript
Ribena
  • 121
  • 4
-1

I wouldn't bother sending your Rails app's logs to syslog. Have you tried your logrotate config when letting Rails write its own log files?

nickh
  • 196
  • 1
  • 4
  • 3
    I use syslog to keep the log files in a reasonable order. Since I'm running rails via passenger, I can have several copies of the rails program writing to the same log file. Syslog nicely deals with these, adding process IDs and other useful information. The default rails logger just shoves it all in the same file with no extra information. I'm not a rails programmer, so I found it easier to use syslog to add the extra information than try to dig deep in the code to fix that. – Andrew Stacey Dec 05 '10 at 19:27