Logrotate httpd (apache) logs – Possible without reloading httpd after log purge?

Posted on

Logrotate httpd (apache) logs – Possible without reloading httpd after log purge? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, logrotate, , , .

Lets start with a small dump:

/var/log/httpd/*log {
    compress
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}

This is a dump of of our httpd logrotate.d file.

As you can see, after the files are rotated, apache is “reloaded”.

Is it ok to disable this?

We reverse proxy (via nginx) to our apache boxes and have noticed when this is executed (httpd reload) there is 2-5 seconds of downtime (noticed as in, via our nginx reverse proxy logs).

We would like to disable this.

Any ideas how to rotate apache logs without sending a reload once they have been rotated?

Thanks!

Solution :

You can use Apache’s piped logs. You can write the piped stream to file yourself and handle the rotation inside the script. Apache does not need to be reloaded then.

The reason for the reload is that Apache opens the log file and gets a handle to it when started or reloaded. It will then continue writing to that file handle even if the file is moved, so if you are rotating the files by moving them, you will need to do a reload so it will realise the file is missing and create a new one with a new file handle.

Like Christopher Perrin said, using piped logs is one solution. Another is to use the option

copytruncate

in your logrotate config file. Instead of the log file being moved, it will be copied to its new place and the old file will be truncated. That means that Apache can keep the same filehandle, and doesn’t need to be restarted.

Leave a Reply

Your email address will not be published.