Linux – Logrotate and Open Files

linuxlogrotate

How does logrotate handle open files? Can logrotate rotate files that a process has open?

Best Answer

For those applications that don't accept the signals from logrotate as Rory described, I use a couple of methods.

  1. Use the copytruncate option
  2. Add a post-rotate statement to restart the service

The decision of which one to use depends on both size of log files and necessity of seamless logs. That's going to be a risk analysis on your own part. However, to give an example, I use a post-rotate restart on certain logs where I actually should be using a copytruncate. However, the files are often several gigs and the copy could take a long enough time that losing a second or two each night was preferable.