]> git.donarmstrong.com Git - dsa-puppet.git/commitdiff
Try to fix a deadlock
authorPeter Palfrader <peter@palfrader.org>
Thu, 25 Apr 2013 13:53:15 +0000 (15:53 +0200)
committerPeter Palfrader <peter@palfrader.org>
Thu, 25 Apr 2013 13:53:15 +0000 (15:53 +0200)
modules/roles/files/static-mirroring/static-master-ssh-wrap

index d66f282fe5fb9c12a90f44a2f91e2ee54471d326..54c6f3459038994ec3116b79c9106802065b5207 100755 (executable)
@@ -51,25 +51,6 @@ croak() {
        exit 1
 }
 
-lock() {
-  local fd="$1"; shift
-  local path="$1"; shift
-  local exclusive="$1"; shift
-
-  eval "exec $fd< '$path'"
-
-  if [ "$exclusive" -gt 0 ]; then
-    locktype="-e"
-  else
-    locktype="-s"
-  fi
-
-  if ! flock "$locktype" "$fd"; then
-    echo >&2 "$0: Cannot acquire lock on $base (flock $locktype failed) - Very bad, we should have waited!"
-    exit 1
-  fi
-}
-
 do_rsync() {
        local remote_host="$1"; shift
        local args="--server --sender -vlHtrze.iLsf --safe-links ."
@@ -83,7 +64,11 @@ do_rsync() {
          elif [ "$*" = "$args $component/-live-/" ] || [ "$*" = "$args ./$component/-live-/" ] ; then
                  local path="$BASEDIR/master/$component-current-live"
                  info "host $remote_host wants $path, acquiring lock"
-                 lock 200 "$path" 0
+                 exec 200< "$path"
+                 if ! flock -s -w 0 200; then
+                       echo >&2 "Cannot acquire shared lock on $path - this means an update is already underway anyway (probably)."
+                       exit 1
+                 fi
                  rsync $args "$path/."
                  return
          fi