summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Warner <antarus@gentoo.org>2018-12-09 07:57:09 -0500
committerAlec Warner <antarus@gentoo.org>2018-12-09 07:57:09 -0500
commit60ff1f4e41dbc765cfb973a718a04a75d470a9fa (patch)
tree24c7a3f31f9336652d9e6506ca97a19a8554ba0d
parentEnsure WORKDIR exists. (diff)
downloadantarus-60ff1f4e41dbc765cfb973a718a04a75d470a9fa.tar.gz
antarus-60ff1f4e41dbc765cfb973a718a04a75d470a9fa.tar.bz2
antarus-60ff1f4e41dbc765cfb973a718a04a75d470a9fa.zip
Try to get more atomic syncing for serving content.
Signed-off-by: Alec Warner <antarus@gentoo.org>
-rwxr-xr-xsrc/infra.gentoo.org/rsync-node/wrap_rsync.sh30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/infra.gentoo.org/rsync-node/wrap_rsync.sh b/src/infra.gentoo.org/rsync-node/wrap_rsync.sh
index f92934c..b4a6857 100755
--- a/src/infra.gentoo.org/rsync-node/wrap_rsync.sh
+++ b/src/infra.gentoo.org/rsync-node/wrap_rsync.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -x
# On container start, run an rsync to get a good copy of the tree.
# Then execute rsyncd; we will start serving once the sync completes.
@@ -22,22 +22,28 @@ function sync() {
logger -t rsync "re-rsyncing the gentoo-portage tree"
/usr/bin/rsync ${OPTS[@]} "${SRC}" "${DST}" >> $0.log 2>&1
echo "End: "$(date) >> $0.log 2>&1
+ return 0
}
-sync "${DEST_DIR}/serving" "${SOURCE_MIRROR}" # this is synchronous.
+tmp=$(mktemp -d -p "${DEST_DIR}" XXXXXX)
+sync "${tmp}" "${SOURCE_MIRROR}" # this is synchronous.
-# Then launch rsyncd; it will detach into the background.
+# We serve out of ${DEST_DIR}/serving
+ln -s "${tmp}" "serving"
+
+# Then launch rsyncd; it will detach into the background and serve from serving.
rsync --daemon --config="/opt/rsync/rsyncd.conf"
while true
do
- sleep "${WAIT_TIME}"
- tmp=$(mktemp -d -p "${DEST_DIR}" XXXXXX)
- # If we fail to sync, just try again.
- if ! sync "${tmp}" "${SOURCE_MIRROR}"; then
- rm -rf "${tmp}"
- continue
- fi
- # Atomically rename
- mv -f "${tmp}" "${DEST_DIR}/serving"
+ sleep "${WAIT_TIME}"
+ tmp=$(mktemp -d -p "${DEST_DIR}" XXXXXX)
+ # If we fail to sync, just try again.
+ if ! sync "${tmp}" "${SOURCE_MIRROR}"; then
+ rm -rf "${tmp}"
+ continue
+ fi
+ # Atomically rename
+ ln -sf "${tmp}" "staging" && \
+ mv -fT "${DEST_DIR}/staging" "${DEST_DIR}/serving"
done