I am currently looking at the file size of my Apache logs as they became huge. In my logrotate configuration, 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 configuration:
/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
}
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.
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.
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.Hrm, in this case, probably, as Apache keeps the logs open.
One thing you can try is the
rotatelogs
script. It's part of theapache2-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.