summaryrefslogtreecommitdiff
path: root/bin/runmirrors
diff options
context:
space:
mode:
authorJoerg Jaspert <joerg@debian.org>2008-10-19 18:18:00 +0200
committerJoerg Jaspert <joerg@debian.org>2008-10-19 18:18:00 +0200
commit376a61632ec63f4013b47def9708df12acc6cf79 (patch)
treecd6582b931d150455def8b5901cce8b2cb5df587 /bin/runmirrors
parent13573445af7712f556a873266da7529b0016ea2e (diff)
runmirrors
first code for a 2stage sync trigger. Signed-off-by: Joerg Jaspert <joerg@debian.org>
Diffstat (limited to 'bin/runmirrors')
-rwxr-xr-xbin/runmirrors39
1 files changed, 32 insertions, 7 deletions
diff --git a/bin/runmirrors b/bin/runmirrors
index 50014da..06423be 100755
--- a/bin/runmirrors
+++ b/bin/runmirrors
@@ -1,11 +1,14 @@
#! /bin/bash
set -e
+set -u
# runmirrors script for Debian
# Based losely on existing scripts, written by an unknown number of
# different people over the years.
#
+# Copyright (C) 2008 Joerg Jaspert <joerg@debian.org>
+#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 2.
@@ -44,6 +47,8 @@ export HOME LOGNAME USER PATH BASEDIR
LOGDIR=${LOGDIR:-"${BASEDIR}/log"}
# Our own logfile
LOG=${LOG:-"${LOGDIR}/${NAME}.log"}
+# Our lockfile directory
+LOCKDIR=${LOCKDIR:-"${BASEDIR}/locks"}
# How to rotate the log
SAVELOG=${SAVELOG:-"savelog -t -c 14"}
# Amount of delay between mirrors if the mirror file contains a DELAY
@@ -55,13 +60,14 @@ PROGRAM=${PROGRAM:-"${NAME}-$(hostname -s)"}
# extra ssh options we might want hostwide
SSH_OPTS=${SSH_OPTS:-""}
-# Make sure we have our log directory
-mkdir -p ${LOGDIR}
-
# Some sane defaults
cd ${BASEDIR}
umask 002
+# Make sure we have our log and lock directories
+mkdir -p ${LOGDIR}
+mkdir -p ${LOCKDIR}
+
trap 'log "Mirrorpush done" >> ${LOG}; ${SAVELOG} "${LOG}" > /dev/null' EXIT
log "Pushing leaf mirrors" >> ${LOG}
@@ -74,14 +80,21 @@ if [ -n "${HOOK1}" ]; then
fi
# From here on we do *NOT* want to exit on errors. We don't want to
-# stop pushing mirrors just because we can't reach one atm.
+# stop pushing mirrors just because we can't reach one of them.
set +e
+# Built up our list of 2-stage mirrors.
+PUSHLOCKS=""
+egrep '^staged' ${MIRRORS} |
+while read MTYPE MLNAME MHOSTNAME MUSER MPROTO MKEYFILE; do
+ PUSHLOCKS="${PUSHLOCKS} ${LOCKDIR}/${MLNAME}.stage1"
+done
+
# Now read our mirrorfile and push the mirrors defined in there.
# We use grep to easily sort out all lines having a # in front of them or are empty.
egrep -v '^[[:space:]]*(#|$)' ${MIRRORS} |
-while read MLNAME MHOSTNAME MUSER MPROTO MKEYFILE; do
- if [ "x${MLNAME}x" = "xDELAYx" ]; then
+while read MTYPE MLNAME MHOSTNAME MUSER MPROTO MKEYFILE; do
+ if [ "x${MTYPE}x" = "xDELAYx" ]; then
# We should wait a bit.
log "Delay of ${DELAY} seconds requested, sleeping" >> ${LOG}
sleep ${DELAY}
@@ -102,10 +115,22 @@ while read MLNAME MHOSTNAME MUSER MPROTO MKEYFILE; do
continue
fi
+ # Built our array
+ SIGNAL_OPTS=(
+ MIRROR="${MLNAME}"
+ HOSTNAME="${MHOSTNAME}"
+ USERNAME="${MUSER}"
+ SSHPROTO="${MPROTO}"
+ SSHKEY="${MKEYFILE}"
+ PUSHLOCKOWN="${LOCKDIR}/${MLNAME}.stage1"
+ PUSHTYPE="${MTYPE}"
+ )
+
# And finally, push the mirror
log "Trigger ${MLNAME}" >> ${LOG}
- signal ${MLNAME} ${MHOSTNAME} ${MUSER} ${MPROTO} ${MKEYFILE} "${SSH_OPTS}"
+ signal "${SIGNAL_OPTS}" &
log "Trigger for ${MLNAME} done" >> ${LOG}
+
if [ -n "${HOOK2}" ]; then
log "Running hook2: ${HOOK2}" >> ${LOG}
${HOOK1}