summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/infra.gentoo.org/rsync-node')
-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