X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=config%2Fdebian%2Fcronscript;h=9a561ab063844a13da6f8a6a73f76181b2a462bd;hb=29905ba008ec799882f9e00ddc8a8eb16aa7c1a6;hp=b9cdf25296d47fa7849884e4caaca7067e6a781a;hpb=eeba442951dc24ca07de612d33d4be4d5813bd9b;p=dak.git diff --git a/config/debian/cronscript b/config/debian/cronscript index b9cdf252..9a561ab0 100755 --- a/config/debian/cronscript +++ b/config/debian/cronscript @@ -1,7 +1,7 @@ #!/bin/bash # No way I try to deal with a crippled sh just for POSIX foo. -# Copyright (C) 2009-2015 Joerg Jaspert +# Copyright (C) 2009-2016 Joerg Jaspert # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -38,18 +38,22 @@ set -u # the important part here) set -E -# The extglob shell option is enabled using the shopt builtin, several -# extended pattern matching operators are recognized. We use it for -# the POSSIBLEARGS and the first case ${ARGS} matching +# If the extglob shell option is enabled using the shopt builtin, +# several extended pattern matching operators are recognized. We use +# it for the POSSIBLEARGS and the first case ${ARGS} matching. shopt -s extglob # And use one locale, no matter what the caller has set export LANG=C.UTF-8 export LC_ALL=C.UTF-8 -# import the general variable set. -export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars -. $SCRIPTVARS +# If run from crontab, CONFIGDIR will point to the correct dir +# where we find the vars file +configdir=${configdir:-"/srv/ftp-master.debian.org/dak/config/debian"} +# import the general variable set. (This will overwrite configdir, but +# it is expected to have the same value) +export SCRIPTVARS=${configdir}/vars +. ${SCRIPTVARS} # One arg please declare -lr ARG=${1:-"meh"} @@ -57,9 +61,6 @@ declare -lr ARG=${1:-"meh"} # program name is the (lower cased) first argument. PROGRAM="${ARG}" -# And the following types of cronscripts exists -declare -lr POSSIBLEARGS='+(unchecked|dinstall|hourly|daily|weekly|monthly|yearly)' - # set DEBUG if you want to see a little more logs (needs to be used more) DEBUG=${DEBUG:-0} @@ -70,18 +71,17 @@ case ${ARG} in ${POSSIBLEARGS}) # Only one of me should ever run. FLOCKER=${FLOCKER:-""} - [ "${FLOCKER}" != "${configdir}/${PROGRAM}.tasks" ] && exec env FLOCKER="${configdir}/${PROGRAM}.tasks" flock -E 0 -en "${configdir}/${PROGRAM}.tasks" "$0" "$@" || : + [[ ${FLOCKER} != ${configdir}/${PROGRAM}.tasks ]] && exec env FLOCKER="${configdir}/${PROGRAM}.tasks" flock -E 0 -en "${configdir}/${PROGRAM}.tasks" "$0" "$@" || : ;; *) cat - < /dev/null; then - # log "aborting cron.unchecked because $LOCK_UNCHECKED has already been locked" - exit 0 - fi - TMPFILES="${TMPFILES} ${LOCK_UNCHECKED}" - ;; - dinstall) - ;; - hourly) - ;; - daily) - ;; - weekly) - ;; - monthly) - ;; - yearly) - ;; - *) - error "Unknown arg ${ARG}" - exit 42 - ;; - esac + # If there is a precronscript function, we run it. + prefunc=$(type -t precronscript || echo "") + if [[ -n ${prefunc} ]] && [[ ${prefunc} = function ]]; then + precronscript + fi # An easy access by name for the current log ln -sf ${LOGFILE} ${logdir}/${PROGRAM} @@ -232,32 +207,17 @@ esac # we need to wait for the background processes before the end of the cron script wait - # Common to all cron scripts log "Cron script successful, all done" # Redirect output to another file, as we want to compress our logfile # and ensure its no longer used exec > "$logdir/after${PROGRAM}.log" 2>&1 - case ${ARG} in - unchecked) - ;; - dinstall) - logstats ${LOGFILE} - state "all done" - touch "${DINSTALLEND}" - ;; - hourly) - ;; - daily) - ;; - weekly) - ;; - monthly) - ;; - yearly) - ;; - esac + # If there is a postcronscript function, we run it. + postfunc=$(type -t postcronscript || echo "") + if [[ -n ${postfunc} ]] && [[ ${postfunc} = function ]]; then + postcronscript + fi # Now, at the very (successful) end of this run, make sure we remove # our stage files, so the next dinstall run will do it all again.