Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
implemented locking so only one sync can be active at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
marook committed Apr 6, 2012
1 parent 6e37a93 commit 193543e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sharefs.sh
@@ -1,3 +1,5 @@
set -e

fail()
{
echo "$1" >&2
Expand Down Expand Up @@ -30,6 +32,7 @@ calcLocationVariables()
targetName=`basename "$targetDir"`
shadowDir=$targetDir/../.$targetName.sharefs
configFile=$shadowDir/config
pidFile=$shadowDir/lock.pid

dataDir=$shadowDir/data
if [ -e "$dataDir" ]
Expand Down Expand Up @@ -117,7 +120,25 @@ case "$1" in

loadConfig

if [ -e "$pidFile" ]
then
lockPid=`cat $pidFile`
fail "Process with ID $lockPid is already synchronizing"
fi

function cleanup()
{
rm -f -- "$pidFile"
}
trap cleanup 0

echo "$BASHPID" > "$pidFile"

sleep 10

rsync -az -e ssh "$dataDir" "$remoteDst"

cleanup
;;
*)
fail "Unknwon command \"$1\""
Expand Down

0 comments on commit 193543e

Please sign in to comment.