mzac / unifi-video-mqtt

GNU General Public License v3.0
44 stars 21 forks source link

stops working when logfile is rotated #10

Open verterok opened 4 years ago

verterok commented 4 years ago

Hi,

First wanted to thank you for sharing this, have been using it for some time now. One issue I found is when the log file is moved/rotated the script stops seeing the changes as it's listening to the old file.

Here is a diff of what I did to support the move event, if you think this is good enough I can get a PR up.

index 40b903e..3e41778 100644
--- a/unifi-video-mqtt.sh
+++ b/unifi-video-mqtt.sh
@@ -38,6 +38,13 @@ fi
 VER_TEST=`tail -1 $UNIFI_MOTION_LOG | awk {'print $5'}`

 while inotifywait -e modify $UNIFI_MOTION_LOG; do
+  while [ 1 ]; do
+  event=$(inotifywait -q -e modify,move_self $UNIFI_MOTION_LOG | cut -d " " -f 2);
+  if [ "${event}" != "MODIFY" ];
+  then
+    sleep 2; # wait some random seconds to allow logrotation to finish
+    continue
+  fi
   LAST_MESSAGE=`tail -n1 $UNIFI_MOTION_LOG`

   if [[ $VER_TEST == "[uv.analytics.motion]" ]]; then

Cheers