You may need tail -F instead (upper case -F), even if the file is deleted, renamed, etc.
tail -F my.log
tail -f (lowercase) uses only a file descriptor that does not care about what the file name is. tail -F uses the file name, so if you delete or rename the original and put a new one in place, it will write a new file.
As for logrotate, it works differently. By default, it moves (renames) the source file to the side and creates a new empty file. In this case, the file descriptor is maintained for the logging process until it closes and opens, and it receives a new file.
If you use the logrotate "copytruncate" parameter, both the file and the file descriptor are supported, and the logrotate copies all the data to a new file, truncates the original file and leaves the original file in place. Some processes do not close their log file, so using copytruncate is necessary. Without it, the process will continue to write to the file under a new name.
This design behavior is that on UNIX, the file descriptor for an open file is not performed using rename or delete operations.
codenheim
source share