Log Rotation Frustration
In the past, when I would configure log rotation I would try to run it manually so that I could verify that it actually works. What made it difficult is that it normally logs the file in the log rotation status file and then the next time it runs, it then compares the file needing rotation against the timestamp in the log rotation status file. What this means is that it could take more than 24 hours to get the file rotated. This can be extremely frustrating because the reason you are configuring the log rotation in the first place is that you need them rotated now!
Here’s a trick that I learned to force rotation using logrotate.
Before I understood how it worked, I would get frustrated with the logrotate daemon. It never worked the first night and I could not figure out why. Now I know. The first time that it runs, it creates an entry for the file needing rotation in the file below:
/var/lib/logrotate.status (centos)
or
/var/lib/logrotate/status (ubuntu)
This file specifies the files that it knows about and when they were last rotated. The first time, it assumes that the files do not need rotation, but adds them to the list. The next night, if they are set to daily, it will logrotate that night. If you want to force log rotation immediately after configuring the files in the /etc/logrotate.d directory, run the log rotation manually:
logrotate -v /etc/logrotate.conf |
This will make an entry in the log rotate status file (see above for ubuntu and CentOS locations).
Next, edit the /var/lib/logrotate status file listed above for your OS, change the date for that specific file to be one in the past. Then run the logrotate command again manually:
logrotate -v /etc/logrotate.conf |
Now go and check and the file will have rotated. From this point on, whenever I add a new file or directory of files to rotate, I am forcing log rotation using these steps to get past the frustration!
Latest posts by Jeff Staten (see all)
- Configure Your HP Procurve Switch with SNTP - May 5, 2015
- Configuring HP Procurve 2920 Switches - May 1, 2015
- Troubleshooting Sendmail - November 28, 2014