logrotate does not rotate a log file, while logs accumulate in file with timestamp.

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

Conditions:

- A log file remains empty.
- A log file with the same base name with timestamp added keeps growing, remains active and is never rotated.

In the following example, the file to rotate is /var/log/messages.

# ls -ltr /var/log/messages*
-rw-------  1 root    root    205K Sep  3  2023 messages-20230903.gz
-rw-------  1 root    root    181K Sep 10  2023 messages-20230910.gz
-rw-------  1 root    root       0 Sep 17  2023 messages
-rw-------  1 root    root    109M Jul 11 07:26 messages-20230917

In the above example, the last successful rotation of messages was done on the 10th September 2023: messages-20230910.gz.
/var/log/messages was created one week later, on 17th September 2023, but remains empty.
Meanwhile, messages-20230917 remains the active file as of July 2024, keeps growing and is never successfully rotated.

For debugging purposes, let's try logrotate with the --debug option:

# logrotate --debug /etc/logrotate.conf

// ... partial output:
rotating pattern: /var/log/messages  weekly (4 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/messages
  Now: 2024-07-11 07:27
  Last rotated at 2023-09-17 03:05
  log does not need rotating (log is empty)
not running postrotate script, since no logs were rotated

The debug output above shows that messages being empty, is then never rotated.

The main problem is that for some as yet unexplained reasons, the system logger uses messages-20230917 as the active logging file.

The fix is simple: restart the system logger:

# service syslog-ng restart
* WARNING: you are stopping a boot service
* Stopping syslog-ng ...                                          [ ok ]
* Checking your configfile (/etc/syslog-ng/syslog-ng.conf) ...    [ ok ]
* Starting syslog-ng ...                                          [ ok ]

# ls -ltr /var/log/messages*
-rw------- 1 root root   233192 Aug 27  2023 /var/log/messages-20230827.gz
-rw------- 1 root root   209248 Sep  3  2023 /var/log/messages-20230903.gz
-rw------- 1 root root   185077 Sep 10  2023 /var/log/messages-20230910.gz
-rw-r--r-- 1 root root 10465512 Jul 11 07:33 /var/log/messages-20230917.gz
-rw------- 1 root root     4046 Jul 11 07:53 /var/log/messages

Solved.