Rotate a file that's open and being written at all times

Bruno Polaco asked:

I have an linux application that continually writes logging information into a log file, eg. /var/log/application.log. As the application does not rotate the file automatically, this log file can reach a size of gigabytes in some weeks, so I want to be able to rotate this file properly

My main concern here is that to rotate a file that is opened by the application at all times, I will probably need to:

  1. Move the file to its rotated form /var/log/application.log -> /var/log/application.log.2013-01-28

  2. Create an empty /var/log/application.log. Obs: At this point the application process is still writing to /var/log/application.log.2013-01-28

  3. Change the file descriptor of the application process to point back again to /var/log/application.log

So, am I right? If so, how can i do this? (mainly the changing the file descriptor part)

If i am not, what is the correct way and how to do it?

My answer:

Most such applications respond to a signal, such as SIGHUP, and will close and reopen their log files on receipt of the signal. Check your application’s documentation for the correct signal to send.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.