2

I've configured my Rails 2.3.8 logger in the environment.rb to rotate daily:

config.logger = Logger.new("#{RAILS_ROOT}/logs/#{RAILS_ENV}.log", 'daily')

and every day in the morning I get the usual:

Error during failsafe response: Shifting failed.

Is there a decent/elegant/better solution to this?

What I've done in the past is just set up a cron job to notice when this happens and to drop a Passenger restart.txt file in the app's tmp/ directory.

Thanks.

Amy
  • 1,318
  • 3
  • 12
  • 24

2 Answers2

2

It's pretty common on UNIX/Linux to use a program named logrotate to perform log file rotation. Slicehost have a couple of nice articles on how to use it.

For a Phusion Passenger deployment you can use a configuration like the example below. Obviously adjust the directories and rotation frequency as appropriate.

/home/deploy/public_html/railsapp/shared/log/*.log {
  weekly
  missingok
  rotate 30
  compress
  delaycompress
  notifempty
  sharedscripts
  postrotate
    touch /home/deploy/public_html/railsapp/current/tmp/restart.txt
  endscript
}
John Topley
  • 113,588
  • 46
  • 195
  • 237
  • Yep. That worked! Some notes in the form of a blog post: http://blog.seqmedia.com/?p=216 – Amy Aug 03 '10 at 21:03
  • The blog post moved to: http://www.seqmedia.com/2010/08/03/kicking-rails-shifting-failed-errors-to-the-curb-logrotate/ – Amy Apr 19 '12 at 21:44
1

If you have many requests coming in simultaneously, and it is time for the Rails to rotate logs. If a stream is trying to write to a file ( the logger.rb code has a line that says : @dev.stat.size) and when the file does not exist (because it is being rotated) then it throws a fatal exception, and basically the server stops responding to requests (it doesn’t necessarily shut down, but bombs out on requests.

Kamilski81
  • 14,409
  • 33
  • 108
  • 161