How to avoid apache reload when rotating logs?
The reason that apache needs a reload is that once it's opened a file, it gets a filehandle to it, and it will keep writing to that filehandle. When you move the file, it doesn't see that, it just keeps writing to the same handle. When you do a reload, it'll open the file again and get a new handle.
To avoid the reload, instead of moving the file, you can copy it and empty the old file. That way apache can keep writing to the same filehandle. You do this by adding the option "copytruncate" to the logrotate config file, like this:
/apache/*log {
copytruncate
compress
dateext
rotate 365
size=+300M
olddir /log/old/apache
notifempty
missingok
}
I recommend you to use http://cronolog.org/
This is how I use it:
CustomLog "|/usr/local/sbin/cronolog -S /var/log/httpd/t3.CCC.eu-access_log -P /var/log/httpd/t3.CCC.eu-access_log.prev /var/log/httpd/t3.CCC.eu-%Y.log" combined