logrotate won't rotate my logs automatically
I had a similar issue but crontab
was working and for some of the log directories logrotate
worked but for some it didn't. When I tried to run the logrotate manually, I got some error messages.
user@server:/var/log/apache2$ sudo /usr/sbin/logrotate -f /etc/logrotate.conf
error: error creating output file /var/log/apache2/access.log.1.gz: File exists
error: error creating output file /var/log/apache2/error.log.1.gz: File exists
...
All of the *.1.gz
files had a size of 0. I manually deleted all of the files mentioned in the error message, ran sudo /usr/sbin/logrotate -f /etc/logrotate.conf
again and it worked.
I just though I should share this alternate solution here as well, since this was the first search result that came up for me when I was searching for the problem but the suggested solution didn't work for me. Maybe this helps others as well who are in the same situation as I am.
Check that your logrotate is being run by cron.
Edit:
From the comment discussion - it appears that cron is not working correctly. I had a cronjob in my crontab without user but this only come to light when I restarted the cron daemon
My ubuntu and centos systems have an /etc/cron.daily/logrotate
file the contents of which are
#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf
My /etc/crontab has the following line to run the daily jobs
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily
I know I know. 5 year-old thread.
Just thought if it still comes up quite high in the searches, I'll contribute and give my solution to the problem I encountered. My logrotate jobs were not handled automatically on one of my servers. Forcing the rotation worked fine. I came up with a solution after I ran the daily rotation command by hand:
( cd / && run-parts --report /etc/cron.daily )
Then I saw the error that stopped logrorate jobs from firing:
/etc/cron.daily/logrotate:
error: iptraf-ng:2 duplicate log entry for /var/log/iptraf/*.log
Yes, as simple as that. I had two files defining the same logs to rotate (iptraf and iptraf-ng). Just removing one of the conflicting logrotate definitions for iptraf did the trick.
rm /etc/logrotate.d/iptraf
Another problem might be a botched /etc/crontab file. Meaning double or triple check the syntax on that file as it doesn't provide any output I could find if syntax is wrong. Quietly exits after failed syntax validation.
Hope this saves someone some time.