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

6,764

Solution 1

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.

Solution 2

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.

Share:
6,764

Related videos on Youtube

محمّد محسن احمدی
Author by

محمّد محسن احمدی

Updated on September 18, 2022

Comments

  • محمّد محسن احمدی
    محمّد محسن احمدی almost 2 years

    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!