]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - modules/roles/files/static-mirroring/static-master-ssh-wrap
rename static-mirror-run's basedir to componentdir, as that's what it is now
[dsa-puppet.git] / modules / roles / files / static-mirroring / static-master-ssh-wrap
index 625d3d9b5df10229db79bf5637f68714f5784b8d..0fe7c7377c931b4add448d014b4a8dc0f6cd690b 100755 (executable)
@@ -51,43 +51,32 @@ 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 ."
-       if [ "$*" = "$args -new-/" ] || [ "$*" = "$args ./-new-/" ] ; then
-               local path="$BASEDIR/current-push"
-               info "serving $remote_host with $path"
-               rsync $args "$path/."
-       elif [ "$*" = "$args . -live-/" ] || [ "$*" = "$args . ./-live-/" ] ; then
-               local path="$BASEDIR/current-live"
-               info "host $remote_host wants $path, acquiring lock"
-               lock 200 "$path" 0
-               rsync $args "$path/."
-       else
-               info "NOT allowed for $remote_host: rsync $*"
-               echo >&2 "This rsync command ($@) not allowed."
-               exit 1
-       fi
+
+       for component in $(awk -v this_host="$(hostname -f)" '$1 == this_host {print $2}' $COMPONENTLIST); do
+         if [ "$*" = "$args $component/-new-/" ] || [ "$*" = "$args ./$component/-new-/" ] ; then
+                 local path="$BASEDIR/master/$component-current-push"
+                 info "serving $remote_host with $path"
+                 rsync $args "$path/."
+                 return
+         elif [ "$*" = "$args $component/-live-/" ] || [ "$*" = "$args ./$component/-live-/" ] ; then
+                 local path="$BASEDIR/master/$component-current-live"
+                 info "host $remote_host wants $path, acquiring lock"
+                 exec 200< "$path"
+                 if ! flock -s -w 0 200; then
+                       echo >&2 "Cannot acquire shared lock on $path - this should mean an update is already underway anyway."
+                       exit 1
+                 fi
+                 rsync $args "$path/."
+                 return
+         fi
+       done
+
+       info "NOT allowed for $remote_host: rsync $*"
+       echo >&2 "This rsync command ($@) not allowed."
+       exit 1
 }
 
 do_update_component() {
@@ -98,16 +87,16 @@ do_update_component() {
        shift
 
        hit="$(
-               awk -v component="$component" -v host="$remote_host" '
-                 $1 == component {
-                         if ($2 == host) {
-                                 print $3
+               awk -v this_host="$(hostname -f)" -v component="$component" -v host="$remote_host" '
+                 $1 == this_host && $2 == component {
+                         if ($3 == host) {
+                                 print $4
                                  exit
                          }
-                         split($4,extra,",")
+                         split($5,extra,",")
                          for (i in extra) {
                                  if (host == extra[i]) {
-                                         printf "%s:%s\n", $2, $3
+                                         printf "%s:%s\n", $3, $4
                                          exit
                                  }
                          }