29 April 2009

Setting up logrotate with capitate

How many Rails projects "forget" to set up a log rotation of their production logs and end up filling the hard disk with gigabytes of log ...

Lots ;-) And mine before I found out about logrotate.

Fortunately, there is one tool which help you to no to reinvent the wheel and set up a log rotation within minutes: capitate ;-)

Install it:

sudo gem install capitate
Add the following snippet to your conf/deploy.rb:

# See http://capitate.rubyforge.org
require 'capitate'
require 'capitate/recipes'

# Add this line but remove it afterinstalling 'cap rails:logrotate:install'
set :use_sudo, true
Run cap -T to see how many recipes you have now!

cap logrotated:install_conf

It should install a new /etc/logrotate.d/rails_yourwebsite.com

/home/youruser/public_html/yourwebsite.com/shared/log/production.log {
size 10M
rotate 7

That's it!

No comments: