An application keeps writing to the same open descriptor and cannot reopen its log.
Accept a short race window and copy then truncate the active file.
Which logrotate directive is appropriate?
copytruncate copies the active log and truncates the same file, preserving the descriptor but allowing a small loss window.
Detailed explanation
createIncorrect. create is used after rename and does not solve a process that keeps the old descriptor.
Incorrect. create is used after rename and does not solve a process that keeps the old descriptor.
delaycompressIncorrect. delaycompress postpones compression by one rotation.
Incorrect. delaycompress postpones compression by one rotation.
missingokIncorrect. missingok suppresses an error when the file is absent.
Incorrect. missingok suppresses an error when the file is absent.
copytruncateCorrect. copytruncate works without requiring the process to reopen the file.
Correct. copytruncate works without requiring the process to reopen the file.
Try it yourself
An example you can run in a temporary verification environment.
logrotate --help 2>&1 | head -n 5Expected result
logrotateのusage/help(導入環境)Key points
- Preserve descriptor
- Copy then truncate
- Possible race loss
Notes
- Environment: logrotate helpの読取のみ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.