X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=modules%2Froles%2Ffiles%2Fstatic-mirroring%2Fstatic-mirror-run;h=119d1055cb6b61fce21ac97dd0fdf44075065475;hb=a82772daaacb48fa7d88ef1d1216c731bdc15187;hp=bdcc9283fdcc97dc23149a24a0aa8a1f8137b30e;hpb=d6e20ea4c083d9978ad4c3e5eccaffa2e887698a;p=dsa-puppet.git diff --git a/modules/roles/files/static-mirroring/static-mirror-run b/modules/roles/files/static-mirroring/static-mirror-run index bdcc9283..119d1055 100755 --- a/modules/roles/files/static-mirroring/static-mirror-run +++ b/modules/roles/files/static-mirroring/static-mirror-run @@ -1,6 +1,6 @@ #!/bin/bash -# initiate a mirror staged mirror update from sync-source. +# initiate a staged mirror update from sync-source for a component. # # if we have a serial file and we got a serial on the command line, only sync if the serial is different @@ -32,7 +32,7 @@ set -u NAME="$(basename "$0")" usage() { - echo "Usage: $0 [--one-stage] []" + echo "Usage: $0 [--one-stage] []" } if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then usage; exit 0; fi @@ -57,14 +57,14 @@ while :; do esac done -BASEDIR=${1:-}; shift +COMPONENTDIR=${1:-}; shift SYNC_SOURCE=${1:-}; shift SYNC_SERIAL=${1:-}; shift || true -if [ -z "$BASEDIR" ]; then usage >&2; exit 1; fi +if [ -z "$COMPONENTDIR" ]; then usage >&2; exit 1; fi if [ -z "$SYNC_SOURCE" ]; then usage >&2; exit 1; fi RSYNC="rsync" -RSYNC_BASE_OPTIONS="-avz --delete" +RSYNC_BASE_OPTIONS="-rtvz --delete --links --hard-links --safe-links" RSYNC_SSH_OPTIONS="ssh -o AddressFamily=inet -o BatchMode=yes" LOGDIR="$HOME/logs" @@ -79,7 +79,7 @@ CNF_FILE="$HOME/etc/$NAME.conf" ! [ -e "$CNF_FILE" ] || . "$CNF_FILE" SOURCE="${SYNC_SOURCE}/" -BASEDIR="${BASEDIR}/" +COMPONENTDIR="${COMPONENTDIR}/" ############################################### @@ -106,7 +106,8 @@ log() { } lock() { - exec 200< "$BASEDIR" + mkdir -p "$COMPONENTDIR" + exec 200< "$COMPONENTDIR" if ! flock -e 200; then log "Cannot acquire lock." echo >&5 "[MSM] LOCK-ERROR" @@ -119,13 +120,15 @@ lock() { log_setup -#log "called with $* and ${SSH_ORIGINAL_COMMAND:-no ssh original command options}." log "called with $*" lock -if [ -e "${BASEDIR}${ACTIVE}" ] && [ "$(readlink "${BASEDIR}${ACTIVE}")" = "$ALPHA" ] ; then +if [ -e "${COMPONENTDIR}${ACTIVE}" ] && [ "$(readlink "${COMPONENTDIR}${ACTIVE}")" = "$ALPHA" ] ; then staging="$BRAVO" active="$ALPHA" +elif [ -e "${COMPONENTDIR}${ACTIVE}" ] && [ "$(readlink "${COMPONENTDIR}${ACTIVE}")" != "$BRAVO" ] ; then + echo >&5 "Invalid state of ${COMPONENTDIR}${ACTIVE}." + exit 1 else staging="$ALPHA" active="$BRAVO" @@ -133,8 +136,8 @@ fi log "active is $active; staging is $staging" rsync_source="${SOURCE}" -rsync_curactive="${BASEDIR}${active}/" -rsync_target="${BASEDIR}${staging}/" +rsync_curactive="${COMPONENTDIR}${active}/" +rsync_target="${COMPONENTDIR}${staging}/" if [ -e "$rsync_curactive/.serial" ] && [ -n "$SYNC_SERIAL" ] && [ "$(cat $rsync_curactive/.serial)" = "$SYNC_SERIAL" ]; then log "active is already at serial $SYNC_SERIAL. No action required." @@ -155,7 +158,7 @@ fi case "$action" in go) - ln --symbolic --force --no-target-directory "$staging" "${BASEDIR}$ACTIVE" + ln --symbolic --force --no-target-directory "$staging" "${COMPONENTDIR}$ACTIVE" rm -rf "$rsync_curactive" echo >&5 "[MSM] STAGE2-DONE" log "stage2 done"