X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=modules%2Froles%2Ffiles%2Fstatic-mirroring%2Fstatic-master-ssh-wrap;h=0fe7c7377c931b4add448d014b4a8dc0f6cd690b;hb=c6452873f2c07bf513ac9446ca7abc717051063c;hp=06ab715f4d95460222b43da34d858f997878b34c;hpb=f42cb0499ff05950c567b58393e81ffe77292b49;p=dsa-puppet.git diff --git a/modules/roles/files/static-mirroring/static-master-ssh-wrap b/modules/roles/files/static-mirroring/static-master-ssh-wrap index 06ab715f..0fe7c737 100755 --- a/modules/roles/files/static-mirroring/static-master-ssh-wrap +++ b/modules/roles/files/static-mirroring/static-master-ssh-wrap @@ -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 -vltrze.iLsf --safe-links ." - if [ "$*" = "$args -new-/" ] ; then - local path="$BASEDIR/current-push" - info "serving $remote_host with $path" - rsync $args "$path/." - elif [ "$*" = "$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 + local args="--server --sender -vlHtrze.iLsf --safe-links ." + + 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() { @@ -97,7 +86,23 @@ do_update_component() { component="$1" shift - hit="$(awk -v component="$component" -v host="$remote_host" '$1 == component && $2 == host {print $3; exit}' "$COMPONENTLIST")" + hit="$( + 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($5,extra,",") + for (i in extra) { + if (host == extra[i]) { + printf "%s:%s\n", $3, $4 + exit + } + } + exit + }' "$COMPONENTLIST" + )" if [ -n "$hit" ]; then exec static-master-update-component "$component" echo >&2 "Exec failed"