logrotate not working

I want to set up daily logrotate for my Tomcat server’ catalina.out log file but it’s not working – I haven’t seen the rotated log files created.
To troubleshoot, I ran logrotate -d /etc/logrotate.conf and got the following:

rotating pattern: /usr/local/tomcat/logs/catalina.out  5242880 bytes (7 rotations)
empty log files are rotated, old logs are removed
considering log /usr/local/tomcat/logs/catalina.out
  log needs rotating
rotating log /usr/local/tomcat/logs/catalina.out, log->rotateCount is 7
dateext suffix '-20151223'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
copying /usr/local/tomcat/logs/catalina.out to /usr/local/tomcat/logs/catalina.out-20151223
truncating /usr/local/tomcat/logs/catalina.out
compressing log with: /bin/gzip 

It seems like everything is working without any error. However, there is no results:

[root@gec logrotate.d]# ls -lrth /usr/local/tomcat/logs/cata*
-rw-r--r-- 1 root root  398 Dec  4 17:48 /usr/local/tomcat/logs/catalina.2015-12-04.log
-rw-r--r-- 1 root root 109M Dec 23 17:21 /usr/local/tomcat/logs/catalina.out 

My /etc/logrotate.conf:


rotate 7

# create new (empty) log files after rotating old ones

# use date as a suffix of the rotated file

# uncomment this if you want your log files compressed

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d 

My /etc/logrotate.d/tomcat:

/usr/local/tomcat/logs/catalina.out {
    rotate 7
    size 5M

What is wrong?


Interestingly, running logrotate -f /etc/logrotate.conf creates the rotation gzip files!

[root@gec logrotate.d]# ls -lrth /usr/local/tomcat/logs/cata*
-rw-r--r-- 1 root root  398 Dec  4 17:48 /usr/local/tomcat/logs/catalina.2015-12-04.log
-rw-r--r-- 1 root root 1.1M Dec 23 17:26 /usr/local/tomcat/logs/catalina.out-20151223.gz
-rw-r--r-- 1 root root 109K Dec 23 17:27 /usr/local/tomcat/logs/catalina.out

However, how do I know whether the daily cron job will work?

Asked By: ericn


In /etc/logrotate.d/tomcat try notifempty

Answered By: Ashish Karpe

You are running logrotate -d /etc/logrotate.conf with -d argument.

The -d argument is debug mode, you can say kind of “dry-run”. It will only give you info if the logrotate will work but will not rotate the logs.

The logrotate -f worked since the -f argument specifies logrotate to force the logrotate.

Quoting from the manual of logrotate:

  • -d, –debug

    Turns on debug mode and implies -v. In debug mode, no changes will be made to the logs or to the logrotate state file.

  • -f, –force
    Tells logrotate to force the rotation, even if it doesn’t think this is necessary. Sometimes this is useful after adding new
    entries to a logrotate config file, or if old log files have been
    removed by hand, as the new files will be created, and logging
    will continue correctly.

If the logrotate -d /etc/logrotate.conf gave you output that the log will be rotate and compressed then it will surely rotate it when logrotate will go through your configuration file.

Answered By: Kheshav Sewnundun

There is another question that links to this one as a claimed duplicate, but actually has a very different answer.

The answers to this question will only work if Tomcat is run as user "root", which is poor security practice. If Tomcat runs, according to best practices, as user tomcat:tomcat, the catalina.out file will also be owned by tomcat:tomcat. In that case, logrotate will not rotate catalina.out.

To fix that, you have to specify the user and group name in the logrotate configuration. So in that case, your /etc/logrotate.d/tomcat should be modified to look like this:

/usr/local/tomcat/logs/catalina.out {
    su tomcat tomcat
    rotate 7
    size 5M
Answered By: Kevin Keane
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.