Rotating Ruby on Rails Log Files Using Logrotate

November 13, 2009 at 6:49 pm 1 comment

Configuring logrotate

logrotate gets its configuration information from the file /etc/logrotate.conf. If you can’t find it, you can type locate logrotate.conf from the command line to see where it lives. Open up that file in a text editor (nano /etc/logrotate.conf will work) and append the following lines at the end:

1. Create a file called /etc/logrotate.d/passenger

And put the following contents in it.

/home/myapp/log/*.log {
daily
missingok
rotate 30
compress
delaycompress
sharedscripts
postrotate
touch /home/myapp/tmp/restart.txt
endscript
}

Now your logs will get rotated daily with the previous day being compressed into it’s own file. The compressed files will sit around for 30 days then be deleted. After the rotation is done, postrotate, it will touch /home/myapp/tmp/restart.txt to restart passenger.

2. Test it

Run: logrotate -f /etc/logrotate.d/passenger

After running, you should see an archived log file and a fresh new active one taking the original files place. Also, Passenger will restart so it can log to the new file.

About these ads

Entry filed under: RoR. Tags: , , , .

Server Installation For Ruby From Scratch on UBUNTU Useful links for Ruby on Rails

1 Comment Add your own

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

November 2009
M T W T F S S
« Sep   May »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Most Recent Posts


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: