X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Froles%2Ffiles%2Fstatic-mirroring%2Fstatic-master-update-component;h=64836ba2bc0172601a8222d26e74a96bf4fc092e;hb=7f7434750332a872d97581f5970edbb2222fbc74;hp=2f1742bec4815fc7395b81e1bd67590abbce3a2d;hpb=5a0eade9f4a8531e7394b19ddaad072e8f38692d;p=mirror%2Fdsa-puppet.git diff --git a/modules/roles/files/static-mirroring/static-master-update-component b/modules/roles/files/static-mirroring/static-master-update-component index 2f1742bec..64836ba2b 100755 --- a/modules/roles/files/static-mirroring/static-master-update-component +++ b/modules/roles/files/static-mirroring/static-master-update-component @@ -35,6 +35,10 @@ base=/home/staticsync/static-master/master set -e set -u +if [ "`id -u`" != "`stat -c %u "$base"`" ]; then + echo >&2 "You are probably running this as the wrong user." + exit 1 +fi lock() { local fd="$1"; shift @@ -50,7 +54,7 @@ lock() { fi if ! flock "$locktype" "$fd"; then - echo >&2 "$0: Cannot acquire lock on $base (flock $locktype failed) - Very bad, we should have waited!" + echo >&2 "$0: Cannot acquire lock on $path (flock $locktype failed) - Very bad, we should have waited!" exit 1 fi } @@ -77,16 +81,16 @@ if [ "${component%/*}" != "$component" ] ; then exit 1 fi -srchost="$(awk -v component="$component" '$1 == component {print $2; exit}' "$componentlist")" -srcdir="$(awk -v component="$component" '$1 == component {print $3; exit}' "$componentlist")" +srchost="$(awk -v this_host="$(hostname -f)" -v component="$component" '!/^ *(#|$)/ && $1 == this_host && $2 == component {print $3; exit}' "$componentlist")" +srcdir="$(awk -v this_host="$(hostname -f)" -v component="$component" '!/^ *(#|$)/ && $1 == this_host && $2 == component {print $4; exit}' "$componentlist")" if [ -z "$srchost" ] || [ -z "$srcdir" ]; then echo >&2 "$0: Invalid component: $component (not found in $componentlist)"; exit 1 fi tgt="$base/$component" if ! [ -d "$tgt" ]; then - echo >&2 "$0: Invalid component: $component ($tgt does not exist)"; - exit 1 + echo "$0: Creating $tgt for $component"; + mkdir "$tgt" fi if [ "$srchost" = "`hostname -f`" ]; then @@ -96,11 +100,10 @@ else fi echo "$0: Acquiring locks..." -lock 200 "$base" 0 lock 201 "$tgt" 1 -tmpdir_new="$(mktemp -d --tmpdir="$base" "${component}.new-XXXXXX")" -tmpdir_old="$(mktemp -d --tmpdir="$base" "${component}.old-XXXXXX")" +tmpdir_new="$(mktemp -d --tmpdir="$base" "${component}-updating.incoming-XXXXXX")" +tmpdir_old="$(mktemp -d --tmpdir="$base" "${component}-updating.removing-XXXXXX")" trap "rm -rf '$tmpdir_new' '$tmpdir_old'" EXIT chmod 0755 "$tmpdir_new" @@ -109,8 +112,10 @@ echo "$0: Got them." echo "$0: Updating master copy of $component..." rsync --delete \ - -tr \ + -trz \ + --links --hard-links --safe-links \ --link-dest="$tgt" \ + --exclude='/.serial' \ "$src/." "$tmpdir_new/." echo "$0: Done. Committing." @@ -119,18 +124,18 @@ if ! mv "$tmpdir_new" "$tgt"; then echo >&2 "$0: WARNING: could not move $tmpdir_new to $tgt. Trying to recover" rm -rf "$tgt" mv "$tmpdir_old/old" "$tgt" - echo >&2 "$0: Rolled back to old tree maybe successfully." + echo >&2 "$0: Rolled back to old tree, maybe even successfully." exit 1 fi rm -rf "$tmpdir_new" "$tmpdir_old" trap - EXIT -date '+%s' > "$base/.serial" +date '+%s' > "$tgt/.serial" unlock 201 -unlock 200 +unlock 202 echo "$0: Triggering mirror runs..." -exec static-master-run +exec static-master-run "$component" # vim:set et: # vim:set ts=2: