Rails logging error: “Error during failsafe response: Shifting failed.” … is there an elegant solution to this?

StackOverflow https://stackoverflow.com/questions/9116736

Question

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.

Was it helpful?

Solution

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
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top