views:

226

answers:

2

I have a 1GB slice from slicehost and I have 4 projects running on that box. All 4 applications are ruby on rails application. I was wondering what is the best way to ensure that log files are rotated.

I would prefer to have 4 different log files one for each app rather than having one big log file for all 4 applications.

I am running ubuntu.

I am running passenger.

+4  A: 

This is meta-programming and whether it should be on ServerFault or SO is debatable.

logrotate, a standard package for a number of operating systems, and you can apt-get install logrotate to get it if you do not already. It can be coerced into rotating whatever logs you want, using whatever schedule you want, and with differing policies a la "gzip 7 days then rm" per-file.

Investigate /etc/logrotate.d.

Jed Smith
FWIW, it seems like a perfectly valid programmER topic to me. I tend to think of SO as being for programmers and not just programming.
John Munsch
You tend to think against what the FAQ states, then. Point taken, though.
Jed Smith
+4  A: 

I also use logrotate (you'll have to install via apt-get). Create a new logrotate file in your /etc/logrotate.d/ directory. Here's an example of one of mine:

# for the rails logs
/home/apps/*/shared/log/*log {
  daily
  rotate 14
  notifempty
  missingok
  compress
  sharedscripts
  postrotate
    /usr/bin/touch /home/apps/application1/current/tmp/restart.txt
    /usr/bin/touch /home/apps/application2/current/tmp/restart.txt
  endscript
}
# for the apache logs
/home/apps/logs/*log {
  daily
  rotate 14
  notifempty
  missingok
  compress
  sharedscripts
  postrotate
    /etc/init.d/apache2 restart
  endscript
}

This rotates both rails production.log logs and the apache access/error logs (I run my apps under passenger).

Bill Turner
Thanks for providing an example, I think that's helpful. Why do you restart your apps after rotating the logs, though?
Luke Francl
If you don't restart the app (or apache for that matter), you'll have an issue with the logs not appending anymore. I could be wrong, but I know this was an issue in the past.
Bill Turner