logrotate, virtual hosts on Apache and 100% CPU

I got a typo in my logrotate config which pretty much killed my VPS.

My Apache server runs a lot of virtual hosts, i didn’t want to type them all out for logrotate, so i created something like this to handle it:

/var/www/*/logs/*.lo* {
        daily
        missingok
        rotate 7
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
                        /etc/init.d/apache2 reload > /dev/null
                fi
        endscript
}

Note the ending * at the first line. I didn’t know what got into me, but this caused logrotate to rotate the rotated logfiles, hence 100% CPU and hence, a broken system.

I fixed it (by replacing the ‘*’ with a ‘g’), but logrotate still didn’t work. CPU stayed at 100%, logs didn’t rotate. So i ran a strace -f logrotate and got lots of these:

stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2917, ...}) = 0
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2917, ...}) = 0
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2917, ...}) = 0

A little bit of Googling turned up this blogpost: apparently lograte‘s own log got corrupted. A simple rm /var/lib/logrotate/status did the trick and everything worked perfectly again.

One comment on “logrotate, virtual hosts on Apache and 100% CPU”

Add your comments »

  1. kranthi kumar wrote:

    Hello Dear rohs,

    I used your script it’s not working in ie8 , please help me
    http://www.peterrohs.nl/ i open this url and copy view source and past in my coding.

    please check my site http://iseofirm.net/ptest/wordpress/env2/pica-gallery/?aid=5&pid=18 click on zoom image between in facebook share and download buttons.
    its working in all browsers except IE8 . I will wait for your reply.

    Thanks in advance.

    Geplaatst op Monday 21-11-2011

Leave your comments here

» An overview of all articles can be found in the archive.

Hi! I'm Hay. I make art, do projects and blog here. Read more »

Projects

More Hay at...

Archives by month