Question

I see nginx and apache both have some form of reloading signal sent after their logs have been rotated. Why is this? I'm wondering because I'm setting it up for my own app and want to know if an app will hang for some reason if logs get rotated without them being updated.

Was it helpful?

Solution

There is a great answer to that question here: How to avoid apache reload when rotating logs?

They do this because when they open the log file for writing, they receive a file handle. The handle does not change when the file is moved, which means they will think they are writing to the log file, but after it's moved they are writing to the wrong log file. So they gracefully reload when the logs are rotated to make sure they are creating a new file handle that is writing to the proper file location.

If you are concerned about what will happen with your app, you should read more about logrotate, and pay special attention to prerotate and postrotate. You can make your program listen for a signal to reset the log handle whenever the log files are rotated, or you can do what the answer to the first link suggested, and just copy the file and truncate the original, so that you don't have to worry about it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top