Permalink
Browse files

fixed so that when cron runs it checks for already running instances, if

it finds them that means that updates are being synced, it exits. This
should close some race condition bugs.
  • Loading branch information...
1 parent 83ecf9c commit b4fbf4092ec9ec0da31d61bdec1408400fd0aea7 @philcryer committed Jun 17, 2011
Showing with 13 additions and 0 deletions.
  1. +13 −0 bin/lipsync
View
@@ -10,6 +10,8 @@ if [ -e $CONF_FILE ]; then
. $CONF_FILE
fi
+LOG_FILE="/home/$USER_NAME/.lipsyncd/lipsyncd.log"
+
###############
# this from http://code.google.com/p/lsyncd/wiki/HowToExecAfter
# execute rsync just like it would have been done directly,
@@ -18,6 +20,17 @@ fi
IFS=
err=0
+###############
+# prevent data loss if there is a running rsync launched by lsyncd
+###############
+echo "`date "+%a %b %d %T %Y"` Cron: checking for running lipsync processes" >> $LOG_FILE
+eval NB_RSYNC_PROCESS=`ps aux | grep rsync | grep "$REMOTE_HOST" | grep -v rsyncssh | grep -cv grep`
+echo "`date "+%a %b %d %T %Y"` Cron: found $NB_RSYNC_PROCESS running lipsync processes" >> $LOG_FILE
+if [ $NB_RSYNC_PROCESS -ne 0 ]; then
+ echo "`date "+%a %b %d %T %Y"` Cron: not running lipsync, another process already running" >> $LOG_FILE
+ exit 0
+fi
+
###############
# run the rsync command to check server for updated files
###############

0 comments on commit b4fbf40

Please sign in to comment.