Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am currently looking at the file size of my Apache logs as they became huge. In my logrotate conf, I have delaycompress enabled. Does Apache really need this (as the logrotate documentation says that some programs still write in the old file) or is it safe to disable delaycompress?

Here is my logrotate config:

/var/log/apache2/*.log {
    weekly
    missingok
    rotate 26 
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
            if [ -f /var/run/apache2.pid ]; then
                    /etc/init.d/apache2 restart > /dev/null
            fi
    endscript
}

Best regards,

Jonas

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

If you're doing an Apache restart (or even 'graceful') it will close open file handles and open them again. You shouldn't need delaycompress because the file will have been closed and re-opened as part of your postrotate restart.

rotate access_log -> access_log.1 (rename action, no INDOE change)
apache still writing to access_log.1 (same open FD on same INODE)
apache restart (close FD, release INODE writing)
apache writing to access_log (new FD to a new INODE)

A restart is kind of a bad idea - what if the config file accidentally changed and is no longer valid? Your apache won't start back up. Instead send a HUP to the parent process which tells it to close/re-open file handles.

postrotate
  /bin/kill -HUP `cat /var/run/apache2.pid 2>/dev/null` 2>/dev/null || true
endscript

cat will fail if the PID is missing (or empty, or invalid) causing kill to also fail so you don't need the if..then block around it.

share|improve this answer
    
YMMV but I find this a nice answer –  asdmin Jun 23 '10 at 8:50
add comment

Hrm, in this case, probably, as Apache keeps the logs open.

One thing you can try is the rotatelogs script. It's part of the apache2-utils package, at least here on my Ubuntu workstation. Another approach would be to rotate them daily instead of weekly, so you're buffering less before compression.

share|improve this answer
    
Probably should have added my logrotate config in the above question - as postrotate I have set up a restart of apache2. –  j0nes Jun 14 '10 at 13:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.