How to debug logrotate warnings or errors when logrotate is not running correctly

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) all versions

Issue

How to debug logrotate warnings or errors when logrotate is not running correctly

Resolution

Check the logrotate.status file

Check your logrotate.status file to see which files rotated:

# cat /var/lib/logrotate/logrotate.status

Run logrotate in a debug mode

Run the logrotate command manually in a debug mode and check for errors:

# /usr/sbin/logrotate -d /etc/logrotate.conf

Identify a configuration file causing the issue

Depending on the errors reported in the debug output, fix configuration issues in /etc/logrotate.conf, in configuration files in /etc/logrotate.d/, or other issues reported in the debug output.

Re-run logrotate in the debug mode

# /usr/sbin/logrotate -d /etc/logrotate.conf

If no errors appear, logrotate should work properly.

Root Cause

In this example, the root cause is a missing directory /var/log/conman.old. Creating the directory solves the issue:

# mkdir /var/log/conman.old

Diagnostic Steps

Sometimes some warnings or errors are created in the /var/log/messsages file. For example:

logrotate: ALERT exited abnormally with [1]

The logrotate command has an argument -d, which turns on a debug mode. In the debug mode, no changes will be made to the logs or to the logrotate state file. If needed, the debugging output can be redirected into a file (e.g. /tmp/logrotate.debug), which may be very useful for debugging:

# /usr/sbin/logrotate -d /etc/logrotate.conf 2> /tmp/logrotate.debug

Example of a debugging output:

reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file acpid
reading config info for /var/log/acpid 
reading config file conman
reading config info for /var/log/conman/* 
olddir is now /var/log/conman.old/
error: conman:21 error verifying olddir path /var/log/conman.old/: No such file or directory

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

3 Comments

What if the ALERT entries are present in /var/log/messages but running logrotate in debug mode produces no errors?

It is then helpful to look at the email cron sent, to see the underlying reason:

Date: Tue, 7 Apr 2020 03:21:04 +0100 (BST)
From: Anacron <root@test.localdomain>
To: root@test.localdomain
Subject: Anacron job 'cron.daily' on test

/etc/cron.daily/logrotate:

error: stat of /opt/prog/dir/file.log failed: Permission denied

Not sure about RHEL6 and earlier, but the logrotate.status file is one directory deeper than this document indicates for RHEL7 and RHEL8:

cat /var/lib/logrotate/logrotate.status