0

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!

anonymous-one
  • 1,018
  • 7
  • 27
  • 43

2 Answers2

5

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.

Christopher Perrin
  • 4,811
  • 19
  • 33
5

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.

Jenny D
  • 27,780
  • 21
  • 75
  • 114