Results for the above:
In one window loop every 10 seconds and perform an lsof of /var/lib/docker grepping for test-json (a file I will create.)
Significant events are highlighted with comments. The commands used to create and delete files are below. this block.
myhost ~ # while true; do date; lsof /var/lib/docker 2>/dev/null | grep test-json; sleep 10; done
Mon Jul 9 17:19:57 UTC 2018
Mon Jul 9 17:20:07 UTC 2018
Mon Jul 9 17:20:17 UTC 2018
Mon Jul 9 17:20:28 UTC 2018
# Test file is created and filebeat has opened it.
# Note the filehandle (11r)
Mon Jul 9 17:20:38 UTC 2018
filebeat 37201 root 11r REG 202,240 18 19923130 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:20:48 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:20:58 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:21:09 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log
# Test file has been deleted and recreated. We are now writing to the new file not the deleted file.
# Note the filehandle of the deleted file is the same as the original.
# Note the filehandle of the new file is different (18r.)
# Note the seventh column over which is the file size. The deleted file is 30 bytes, the new file is 6.
Mon Jul 9 17:21:19 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 6 19923131 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:21:29 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 6 19923131 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:21:39 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 6 19923131 /var/lib/docker/containers/test/test-json.log
# Note that the new file (filehandle 18r) is growing but the original (11r) is not being written to.
Mon Jul 9 17:21:49 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 12 19923131 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:22:00 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 12 19923131 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:22:10 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 12 19923131 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:22:20 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 18 19923131 /var/lib/docker/containers/test/test-json.log
<trunkated for brevity>
Mon Jul 9 17:25:24 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 54 19923131 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:25:34 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 54 19923131 /var/lib/docker/containers/test/test-json.log
Mon Jul 9 17:25:45 UTC 2018
filebeat 37201 root 11r REG 202,240 30 19923130 /var/lib/docker/containers/test/test-json.log (deleted)
filebeat 37201 root 18r REG 202,240 60 19923131 /var/lib/docker/containers/test/test-json.log
# Five minutes have passed and the original file (filehandle 11r) is now finally closed.
Mon Jul 9 17:25:55 UTC 2018
filebeat 37201 root 18r REG 202,240 60 19923131 /var/lib/docker/containers/test/test-json.log
In a second session create a file /var/lib/docker/containers/test/test-json.log and write a message to it every 20 seconds. We kill this once filebeat opens the file for reading.
myhost test # date ; while true; do echo "stuff" >> test-json.log ; sleep 5; done
Mon Jul 9 17:20:31 UTC 2018
Once filebeat has opened the file for reading delete that file, immediately create a new one with the exact same name then write to the new file every 20 seconds like we are logging normally.
myhost test # date ; rm test-json.log && touch test-json.log ;while true; do echo "stuff" >> test-json.log; sleep 30; done
Mon Jul 9 17:21:11 UTC 2018