From 3b9222cab7c7b115d0e3d93a29b8ee4936c0e0f3 Mon Sep 17 00:00:00 2001 From: Joerg Jaspert Date: Sun, 28 Sep 2008 11:01:14 +0200 Subject: Hooks and DELAY implement hooks run at various places. Allow a delay between two mirrors. Signed-off-by: Joerg Jaspert --- bin/runmirrors | 55 ++++++++++++++++++++++++++++++++++++++++----------- etc/runmirrors.conf | 9 +++++++++ etc/runmirrors.mirror | 6 +++++- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/bin/runmirrors b/bin/runmirrors index c877de2..5c311de 100755 --- a/bin/runmirrors +++ b/bin/runmirrors @@ -21,6 +21,12 @@ set -e # Read our config file NAME="`basename $0`" + +# In case we are called with an argument we look for a different configuration. +if [ -n $1 ]; + NAME="${NAME}-$1" +fi + . ${HOME}/etc/${NAME}.conf # Make sure some variables are always in the environment @@ -30,12 +36,18 @@ export HOME LOGNAME USER PATH . ${HOME}/etc/common # Set sane defaults if the configfile didn't do that for us. +# The directory for our logfiles LOGDIR=${LOGDIR:-"${HOME}/log"} -LOG=${LOG:-"${LOGDIR}/$0.log"} +# Our own logfile +LOG=${LOG:-"${LOGDIR}/${NAME}.log"} +# How to rotate the log SAVELOG=${SAVELOG:-"savelog -t -c 14"} +# Amount of delay between mirrors if the mirror file contains a DELAY +DELAY=${DELAY:-"60"} +# Our mirrorfile +MIRRORS=${MIRRORS:-"${HOME}/etc/${NAME}.mirror"} # used by log() -PROGRAM=${PROGRAM:-"ftpsync-$(hostname -s)"} - +PROGRAM=${PROGRAM:-"${NAME}-$(hostname -s)"} # Make sure we have our log directory mkdir -p ${LOG} @@ -51,12 +63,11 @@ exec >"${LOG}/runmirrors" 2>&1 log "Pushing leaf mirrors" -# Set the HOOKSCRIPT variable in the config file if you want to run an -# extra script right before the mirrors get pushed -if [ -n ${HOOKSCRIPT} ]; then - log "Running hook ${HOOKSCRIPT}" - ${HOOKSCRIPT} - log "Hook finished with errorcode $?" +if [ -n ${HOOK1} ]; then + log "Running hook1: ${HOOK1}" + ${HOOK1} + result=$? + log "Back from hook1, got returncode ${result}" fi # From here on we do *NOT* want to exit on errors. We don't want to @@ -64,9 +75,15 @@ fi set +e # 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. -egrep -v '^[[:space:]]*(#|$)' ${HOME}/etc/runmirrors.mirror | +# 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 + # We should wait a bit. + sleep ${DELAY} + continue + fi + # Process the two options that can be left blank in the config if [ -z ${MPROTO} ]; then MPROTO=2 @@ -81,9 +98,23 @@ while read MLNAME MHOSTNAME MUSER MPROTO MKEYFILE; do continue fi - # And finally, push the mirrors + # And finally, push the mirror log "Trigger ${MLNAME}" signal ${MLNAME} ${MHOSTNAME} ${MUSER} ${MPROTO} ${MKEYFILE} + log "Trigger for ${MLNAME} done" + if [ -n ${HOOK2} ]; then + log "Running hook2: ${HOOK2}" + ${HOOK1} + result=$? + log "Back from hook2, got returncode ${result}" + fi done +if [ -n ${HOOK3} ]; then + log "Running hook3: ${HOOK3}" + ${HOOK3} + result=$? + log "Back from hook3, got returncode ${result}" +fi + exit 0 diff --git a/etc/runmirrors.conf b/etc/runmirrors.conf index da7404d..dc53cdc 100644 --- a/etc/runmirrors.conf +++ b/etc/runmirrors.conf @@ -6,3 +6,12 @@ PATH="/bin:/usr/bin:$HOME" HOOKSCRIPT= KEYFILE=${HOME}/.ssh/pushmirror LOG=${HOME}/log/ + +# Hook scripts can be run at various places. +# Leave them blank if you don't want any +# Hook1: After reading config, before doing the first real action +# Hook2: Between two hosts to push +# Hook3: When everything is done +HOOK1= +HOOK2= +HOOK3= diff --git a/etc/runmirrors.mirror b/etc/runmirrors.mirror index 7fa7a38..33f30c8 100644 --- a/etc/runmirrors.mirror +++ b/etc/runmirrors.mirror @@ -14,4 +14,8 @@ # eu.puccini puccini.debian.org archvsync 2 ~/.ssh/push_puccini # # will push puccini.debian.org, user archvsync, using ssh protocol 2 and the specified ssh key. - +# +# One special value is allowed: DELAY +# This word has to be on a line itself, nothing else, not even +# whitespace. It will trigger a pause of $DELAY seconds between the two +# mirrors. Per default DELAY is set to 60. -- cgit v1.2.3