Author Topic: Setting up Tomcat logrotation on CentOS  (Read 9002 times)

emilec

  • Newbie
  • *
  • Posts: 43
  • Karma: 4
    • View Profile
    • Email
Setting up Tomcat logrotation on CentOS
« on: February 23, 2012, 14:20:37 »
This details my attempts at setting up logrotation on CentOS 5 for Tomcat when installed from the Loway repo. I believe this is an oversight in the Loway Tomcat deployment and I have created a feature request for this.

If you would like to setup Tomcat logrotation you can do the following:
# vi /etc/logrotate.d/qm-tomcat6
Code: [Select]
/usr/local/queuemetrics/tomcat/logs/*.log {
    notifempty
    copytruncate
    daily
    size=+1024k   
    rotate 10
    compress
    missingok
}

/usr/local/queuemetrics/tomcat/logs/catalina.out {
    notifempty
    copytruncate
    dateext
    daily
    size=+1024k   
    rotate 10
    compress
    missingok
}

If you want to get fancy you can make it take care of cleaning out temp files as well (or just do it from cron as you would normally)
Code: [Select]
/usr/local/queuemetrics/tomcat/logs/catalina.out {
    notifempty
    copytruncate
    dateext
    daily
    size=+1024k
    rotate 10
    compress
    missingok
postrotate
       /bin/nice /usr/bin/find /usr/local/queuemetrics/tomcat/temp -type f -mtime +10 -exec /bin/rm {} \; > /dev/null
    endscript
}

UPDATE: I have subsequently added size=+1024k to my suggestion as this seems to get past the logrotate.conf issues of only rotating logs weekly so you no longer have to follow the steps below (unless you want all your other system logs to rotate daily as well).

I also took some time to delve into the CentOS logrotation settings and would suggest some of the following changes depending on your needs. I found that even if I set the rotation to daily in qm-tomcat6 logrotate.conf overrides it to weekly.
# vi /etc/logrotate.conf
Set weekly to daily
Code: [Select]
# rotate log files daily
daily

Change the backlogs from 4 week to 14 days
Code: [Select]
# keep 14 days worth of backlogs
rotate 14

I like compressed logs
Code: [Select]
# uncomment this if you want your log files compressed
compress

By default logrotation runs at 4am. You can change this by editing /etc/crontab
Set it to 02:02
Code: [Select]
02 2 * * * root run-parts /etc/cron.daily
Additional reading:
http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-centos-part-1
http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-centos-part-2

Comments, suggestions and improvements welcome!  ;D
« Last Edit: May 31, 2012, 09:01:06 by emilec »

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: Setting up Tomcat logrotation on CentOS
« Reply #1 on: February 24, 2012, 10:27:32 »
That's very nice, can we add this to the QueueMetrics Advanced Configuration Manual?
 ;D

emilec

  • Newbie
  • *
  • Posts: 43
  • Karma: 4
    • View Profile
    • Email
Re: Setting up Tomcat logrotation on CentOS
« Reply #2 on: February 24, 2012, 16:26:27 »
Sure!  Just remember the karma  :P
« Last Edit: February 24, 2012, 16:30:50 by emilec »

emilec

  • Newbie
  • *
  • Posts: 43
  • Karma: 4
    • View Profile
    • Email
Re: Setting up Tomcat logrotation on CentOS
« Reply #3 on: May 31, 2012, 09:00:44 »
I have found that setting size=+1024k means you don't have to modify logrotate.conf (first post updated).

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: Setting up Tomcat logrotation on CentOS
« Reply #4 on: June 05, 2012, 11:05:25 »
+1  ;)