[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Entirely make cronscript magic



There is no longer a defined list of arguments it can handle.
Instead the arguments are defined in the var file, whose location
defaults to the FTPMaster location - but can be overriden using an
environment variable.

To be able to have specific types of cronscripts run pre/post actions,
we now check for the existance of preconscript and postcronscript
functions, and if they exist, they are run as the first/last thing
before/after anything listed in the .task file
---
 config/debian/cronscript          | 82 +++++++++------------------------------
 config/debian/dinstall.functions  |  6 +++
 config/debian/unchecked.functions | 14 +++++++
 config/debian/vars                |  3 ++
 4 files changed, 42 insertions(+), 63 deletions(-)
 create mode 100644 config/debian/unchecked.functions

diff --git a/config/debian/cronscript b/config/debian/cronscript
index 2418d79..595c6b6 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 <joerg@debian.org>
+# Copyright (C) 2009-2016 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
@@ -38,9 +38,9 @@ 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
@@ -61,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}
 
@@ -78,14 +75,13 @@ case ${ARG} in
         ;;
     *)
         cat - <<EOF
-This is the FTPMaster cronscript. It needs an argument or it won't do
-anything for you.
+This is the cronscript. It needs an argument or it won't do anything
+for you.
 
-Currently accepted Arguments:
+Currently accepted Arguments: ${POSSIBLEARGS}
 
-   unchecked - Process the unchecked queue
-   dinstall  - Run a dinstall
-   yearly, hourly, daily, weekly - Run that part
+To see what they do, you want to look at the files
+\$ARGUMENT.{tasks,functions,variables} in ${configdir}.
 
 EOF
         exit 0
@@ -126,36 +122,11 @@ esac
     # Get rid of tempfiles at the end
     trap cleanup EXIT TERM HUP INT QUIT
 
-    case ${ARG} in
-        unchecked)
-            # Do not run during dinstall
-            if [[ -e ${LOCK_DAILY} ]]; then
-                exit 0;
-            fi
-            # only run one cron.unchecked and also lock against hourly (newoverview)
-            if ! lockfile -r8 ${LOCK_UNCHECKED} 2> /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}
@@ -236,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.
diff --git a/config/debian/dinstall.functions b/config/debian/dinstall.functions
index acfbee4..2ee713c 100644
--- a/config/debian/dinstall.functions
+++ b/config/debian/dinstall.functions
@@ -716,3 +716,9 @@ function startup() {
     touch "${LOCK_BRITNEY}"
     TMPFILES="${TMPFILES} ${LOCK_DAILY} ${LOCK_BRITNEY}"
 }
+
+function postcronscript() {
+    logstats ${LOGFILE}
+    state "all done"
+    touch "${DINSTALLEND}"
+}
\ No newline at end of file
diff --git a/config/debian/unchecked.functions b/config/debian/unchecked.functions
new file mode 100644
index 0000000..87fbda0
--- /dev/null
+++ b/config/debian/unchecked.functions
@@ -0,0 +1,14 @@
+# -*- mode:sh -*-
+
+function precronscript() {
+    # Do not run during dinstall
+    if [[ -e ${LOCK_DAILY} ]]; then
+        exit 0;
+    fi
+    # only run one cron.unchecked and also lock against hourly (newoverview)
+    if ! lockfile -r8 ${LOCK_UNCHECKED} 2> /dev/null; then
+        # log "aborting cron.unchecked because $LOCK_UNCHECKED has already been locked"
+        exit 0
+    fi
+    TMPFILES="${TMPFILES} ${LOCK_UNCHECKED}"
+}
\ No newline at end of file
diff --git a/config/debian/vars b/config/debian/vars
index a2bc5bd..eb24057 100644
--- a/config/debian/vars
+++ b/config/debian/vars
@@ -44,6 +44,9 @@ LOCK_DAILY="${lockdir}/daily.lock"
 LOCK_UNCHECKED="${lockdir}/unchecked.lock"
 LOCK_STOP="${lockdir}/archive.stop"
 
+# And the following types of cronscripts exists
+declare -lr POSSIBLEARGS='+(unchecked|dinstall|hourly|daily|weekly|monthly|yearly)'
+
 archs=$(dak admin a list | tr '\n' ' ')
 
 # Set the database variables
-- 
2.1.4


Reply to: