Categories
System Administration

Adding Rails log rotation to Dreamhost (compiling your own logrotate)

(credit goes to Joey Geiger for the original Gist)

Trying to use logrotate to rotate your Rails logs on Dreamhost?   You’ll need to roll your own copy of it.  Fortunately, the process isn’t too bad.  Let’s jump right into it.

SSH to your host and run the following commands (read my notes below if you’re not super gusty):

# create a new cron job (crontab -e) or use panel.dreamhost.com and run it daily
0 0 * * * /home/<your_account>/opt/bin/logrotate -f -s /home/<your_account>/opt/lib/logrotate.status /home/<your_account>/opt/etc/logrotate.conf
cd ~
mkdir -p opt/bin
mkdir opt/lib
mkdir opt/etc
mkdir src
cd src
wget http://www.sfr-fresh.com/unix/privat/logrotate-3.7.9.tar.gz
wget http://www.sfr-fresh.com/linux/misc/popt-1.16.tar.gz
tar xzvf logrotate-3.7.9.tar.gz
tar xzvf popt-1.16.tar.gz
cd popt-1.16
./configure --prefix=/home/<your_account>/opt/
make
make install
cd ../logrotate-3.7.9
# the first make will fail on the final compile (with 'cannot find -lpopt' message)
# some include problem, but this works so i'm not inclined to care too much
make POPT_DIR=/home/<your_account>/opt/include
# this make should complete
make POPT_DIR=/home/<your_account>/opt/lib
cp logrotate ~/opt/bin/
cd ~/opt/etc
vi logrotate.conf
# paste in the logrotate.conf file
/home/<your_account>/<your_website>/shared/log/*.log {
  daily
  missingok
  rotate 7
  compress
  delaycompress
  notifempty
  copytruncate
}


A couple of quick notes here:

    The most substantial difference from jgeiger’s post is the compiling of the popt library, so that in turn, logrotate would compile.  I really don’t know what’s messed up when you try to link to popt (which leads to the compile failing the first time around), but the workaround seems to work just fine.  If someone happens to know what magic flags are necessary to get the compile to work smoothly the first time, please fork the notes and let me know.
    Joe’s Own Editor was the default editor when I tried to edit my crontab, and it makes my brain hurt.  Edit your .bash_profile and add export EDITOR="/usr/bin/vim" to use vim instead. Logout and back in for the change to take effect.

(disclaimer: Don’t break your stuff. Or Dreamhost’s stuff.)