Fixing Logrotate on Ubuntu Jaunty Server Edition

After about one year of having used the VPS based on Ubuntu Jaunty, recently I had the need to go look at my Apache logs. Now Apache log on my desktop machine are always nicely rotated by logrotate without me having to do anything. However on the server, I found a gigantic 1.2 GB other_vhosts_access.log staring at me with no rotation whatsoever in last 1 year.

So I began to learn about logrotate. Running logrotate by hand produced the following which was obviously not true.

abhaya@www$ sudo logrotate -d /etc/logrotate.conf
rotating pattern: /var/log/apache2/*.log weekly (52 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/apache2/access.log
log does not need rotating
considering log /var/log/apache2/error.log
log does not need rotating
considering log /var/log/apache2/other_vhosts_access.log
log does not need rotating

The contents of the status file (/var/lib/logrotate/status) which logrotate uses to determine which log files need rotating was surprisingly empty:

abhaya@www$ cat /var/lib/logrotate/status
logrotate state -- version 2

So for some reason, logrotate was not able to write to the status file and so no logs were being rotated. Following the advice in this thread, I deleted the status file and ran the logrotate again as following:

abhaya@www$ sudo logrotate -d  /etc/logrotate.conf

And again got the same result as before. Surprised, I tried the command exactly as suggested in the thread:

abhaya@www$ sudo logrotate -v  /etc/logrotate.conf

And voila:

abhaya@www$ cat /var/lib/logrotate/status
logrotate state -- version 2
"/var/log/btmp" 2010-7-6
"/var/log/wtmp" 2010-7-6
"/var/log/samba/log.nmbd" 2010-7-6
"/var/log/samba/log.smbd" 2010-7-6
"/var/log/mysql/mysql-slow.log" 2010-7-6
"/var/log/mysql/mysql.log" 2010-7-6
"/var/log/mysql.log" 2010-7-6
"/var/log/dpkg.log" 2010-7-6
"/var/log/apt/term.log" 2010-7-6
"/var/log/apache2/other_vhosts_access.log" 2010-7-6
"/var/log/apache2/error.log" 2010-7-6
"/var/log/apache2/access.log" 2010-7-6

Just one last problem remained. With this setup, logs would start rotating only next week and I did not want my Apache log files to get any bigger then they already were. So I cheated by manually editing the status file and pushing the date against the apache logs about a week earlier.

"/var/log/apache2/other_vhosts_access.log" 2010-6-28
"/var/log/apache2/error.log" 2010-6-28
"/var/log/apache2/access.log" 2010-6-28

And ran the logrotate by hand once again. The logs duly rotated and hopefully will rotate as expected in the weeks to come.


rob said…
This weird fix also helped me on my Ubuntu 9.10 (Karmic) server. Had a 12G apache log file and now all working well.

Anonymous said…
abhaya: your first two attempts didn't change anything because the "-d" option means "debug". It causes logrotate to load all configs, examine all log files, etc. but prevents any changes to log files.

abhaga said…
@Klode Thank you! you are right. Even the -v option only controls verbosity. So that one is also redundant! I should probably update the post.

Popular posts from this blog


क्या लिखूं?

बिछड़ते दोस्तों के नाम