- Timeout old sessions
- Send notifications on application errors
- Roll log files
I am using the activerecord store for my session data and hence, I need to delete some "timed out" session rows in the "sessions" table. This is easily done using this cronjob line:
00 02 * * * bash -c "cd $RAILS_APP_DIR && script/runner -e production \"CGI::Session::ActiveRecordStore::Session.delete_all(['updated_at < ?', 12.hours.ago])\""
If you are using the file based store (default) you can use a find with some -ctime parameters or something.
Send notifications on application errors
To be able to be notified by email when and application error occurs, I simply installed and configured the exception_notification plugin.
ruby script/plugin install exception_notification
Inserted in ApplicationController:
ExceptionNotifier.exception_recipients = %w(email@example.com)
ExceptionNotifier.sender_address = %("Application Error"
ExceptionNotifier.email_prefix = "[MYAPP ERROR] "
Roll log files
It seems to be the advice not to let the log implementation in rails log the files, if one has multiple mongrel instances (they share the log files). So, I opt for a rails-external solution. Luckily, on linux we have something called logrotate.
In my linux setup /etc/logrotate.conf already contained the line "include /etc/logrotate.d", which makes adding more log rotation as easy as adding a file to the logrotate.d dir. I added a file shown below, which is fine for my setup:
Shit, that was easy. Gotta love deploying on linux :-)