X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Froles%2Ffiles%2Fstatic-mirroring%2Fstatic-mirror-run;h=eac646bb3937a43113d1746c8fb21a91dda77a95;hb=0aac917e02155dbb1b9f06d317f389feac08911d;hp=72f7aea610e7f500a05c87fa488abf9024c4001f;hpb=b762782a06b2fff4d656866def1c5267835be269;p=mirror%2Fdsa-puppet.git diff --git a/modules/roles/files/static-mirroring/static-mirror-run b/modules/roles/files/static-mirroring/static-mirror-run index 72f7aea61..eac646bb3 100755 --- a/modules/roles/files/static-mirroring/static-mirror-run +++ b/modules/roles/files/static-mirroring/static-mirror-run @@ -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,18 +57,19 @@ 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 +COMPONENT="$(basename "${COMPONENTDIR}")" RSYNC="rsync" RSYNC_BASE_OPTIONS="-rtvz --delete --links --hard-links --safe-links" RSYNC_SSH_OPTIONS="ssh -o AddressFamily=inet -o BatchMode=yes" LOGDIR="$HOME/logs" -LOGFILE="$LOGDIR/$NAME-run.log" +LOGFILE="$LOGDIR/$NAME-run-${COMPONENT}.log" ALPHA="tree-a" @@ -79,7 +80,7 @@ CNF_FILE="$HOME/etc/$NAME.conf" ! [ -e "$CNF_FILE" ] || . "$CNF_FILE" SOURCE="${SYNC_SOURCE}/" -BASEDIR="${BASEDIR}/" +COMPONENTDIR="${COMPONENTDIR}/" ############################################### @@ -106,7 +107,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" @@ -122,21 +124,21 @@ log_setup 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 "${BASEDIR}${ACTIVE}" ] && [ "$(readlink "${BASEDIR}${ACTIVE}")" = "$BRAVO" ] ; then +elif [ -e "${COMPONENTDIR}${ACTIVE}" ] && [ "$(readlink "${COMPONENTDIR}${ACTIVE}")" != "$BRAVO" ] ; then + echo >&5 "Invalid state of ${COMPONENTDIR}${ACTIVE}." + exit 1 +else staging="$ALPHA" active="$BRAVO" -else - echo >&5 "Invalid state of ${BASEDIR}${ACTIVE}." - exit 1 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." @@ -157,7 +159,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"