]> git.decadent.org.uk Git - dak.git/blobdiff - config/debian/cron.dinstall
dinstall
[dak.git] / config / debian / cron.dinstall
index 7c3880806878c609da809e8149c75ad535fe6bef..9c9840d7c45e27213cedf62a65d7e44e443fdb0d 100755 (executable)
@@ -28,32 +28,8 @@ export SCRIPTVARS=/srv/ftp.debian.org/dak/config/debian/vars
 ########################################################################
 # Functions                                                            #
 ########################################################################
-# log something (basically echo it together with a timestamp)
-#
-# Set $PROGRAM to a string to have it added to the output.
-function log () {
-        if [ -z "${PROGRAM}" ]; then
-                echo "$(date +"%b %d %H:%M:%S") $(hostname -s) [$$] $@"
-        else
-                echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${PROGRAM}[$$]: $@"
-        fi
-}
-
-# log the message using log() but then also send a mail
-# to the address configured in MAILTO (if non-empty)
-function log_error () {
-        log "$@"
-        if [ -z "${MAILTO}" ]; then
-                echo "$@" | mail -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" ${MAILTO}
-        fi
-}
-
-# debug log, only output when DEBUG=1
-function debug () {
-    if [ $DEBUG -eq 1 ]; then
-        log "$*"
-    fi
-}
+# common functions are "outsourced"
+. "${configdir}/common"
 
 # Timestamp. Used for dinstall stat graphs
 function ts() {
@@ -67,6 +43,16 @@ function cleanup() {
        rm -f ${LOCK_ACCEPTED}
 }
 
+# If we error out this one is called, *FOLLOWED* by cleanup above
+function onerror() {
+    ERRDATE=$(date "+%Y.%m.%d-%H:%M:%S")
+    cat "$LOGFILE" | mail -s "ATTENTION ATTENTION! dinstall error at ${ERRDATE} (Be quiet, Brain, or I'll stab you with a Q-tip)" cron@ftp-master.debian.org
+}
+
+########################################################################
+# the actual dinstall functions follow                                 #
+########################################################################
+
 # Setup the notice file to tell bad mirrors they used the wrong time
 function notice() {
     rm -f "$NOTICE"
@@ -94,9 +80,20 @@ function pgdump_pre() {
 function pgdump_post() {
     log "Creating post-daily-cron-job backup of projectb database..."
     cd $base/backup
-    POSTDUMP=$base/backup/dump_$(date +%Y.%m.%d-%H:%M:%S)
-    pg_dump projectb > $POSTDUMP
-    ln -sf $POSTDUMP current
+    POSTDUMP=$(date +%Y.%m.%d-%H:%M:%S)
+    pg_dump projectb > $base/backup/dump_$POSTDUMP
+    pg_dumpall --globals-only > $base/backup/dumpall_$POSTDUMP
+    ln -sf $base/backup/dump_$POSTDUMP current
+    ln -sf $base/backup/dumpall_$POSTDUMP currentall
+}
+
+# Load the dak-dev projectb
+function pgdakdev() {
+    cd $base/backup
+    echo "drop database projectb" | psql -p 5433 template1
+       cat currentall | psql -p 5433 template1
+    createdb -p 5433 -T template0 projectb
+    fgrep -v '\connect' current | psql -p 5433 projectb
 }
 
 # Updating various files
@@ -225,7 +222,7 @@ function release() {
 
 function dakcleanup() {
     log "Cleanup old packages/files"
-    dak clean-suites
+    dak clean-suites -m 10000
     dak clean-queues
 }
 
@@ -287,9 +284,9 @@ function bts() {
 }
 
 function merkel2() {
-    # Push katie@merkel so it syncs the projectb there. Returns immediately, the sync runs detached
+    # Push dak@merkel so it syncs the projectb there. Returns immediately, the sync runs detached
     log "Trigger merkels projectb sync"
-    ssh -2 -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 -i ~/.ssh/push_merkel_projectb katie@merkel.debian.org sleep 1
+    ssh -2 -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 -i ~/.ssh/push_merkel_projectb dak@merkel.debian.org sleep 1
 }
 
 function runparts() {
@@ -340,9 +337,38 @@ function compress() {
 }
 
 function logstats() {
-    $masterdir/tools/logs.py "$LOGFILE"
+    $masterdir/tools/logs.py "$1"
+}
+
+# save timestamp when we start
+function savetimestamp() {
+       NOW=`date "+%Y.%m.%d-%H:%M:%S"`
+       echo ${NOW} > "${dbdir}/dinstallstart"
+}
+
+function maillogfile() {
+    cat "$LOGFILE" | mail -s "Log for dinstall run of ${NOW}" cron@ftp-master.debian.org
 }
 
+function renamelogfile() {
+    if [ -f "${dbdir}/dinstallstart" ]; then
+        NOW=$(cat "${dbdir}/dinstallstart")
+        maillogfile
+    mv "$LOGFILE" "$logdir/dinstall_${NOW}.log"
+        logstats "$logdir/dinstall_${NOW}.log"
+        bzip2 -9 "$logdir/dinstall_${NOW}.log"
+    else
+        error "Problem, I don't know when dinstall started, unable to do log statistics."
+        NOW=`date "+%Y.%m.%d-%H:%M:%S"`
+        maillogfile
+        mv "$LOGFILE" "$logdir/dinstall_${NOW}.log"
+        bzip2 -9 "$logdir/dinstall_${NOW}.log"
+    fi
+}
+
+function testingsourcelist() {
+    dak ls -s testing -f heidi -r .| egrep 'source$' > ${webdir}/testing.list
+}
 ########################################################################
 ########################################################################
 
@@ -384,10 +410,10 @@ function stage() {
     # it has to cd first!
     cd ${configdir}
 
-       if [ -f "${LOCK_STOP}" ]; then
-               log "${LOCK_STOP} exists, exiting immediately"
-               exit 42
-       fi
+    if [ -f "${LOCK_STOP}" ]; then
+        log "${LOCK_STOP} exists, exiting immediately"
+        exit 42
+    fi
 
     if [ "${ERR}" = "false" ]; then
         set +e
@@ -402,14 +428,14 @@ function stage() {
 
     touch "${stagedir}/${FUNC}"
 
-       if [ -f "${LOCK_STOP}" ]; then
-               log "${LOCK_STOP} exists, exiting immediately"
-               exit 42
-       fi
-
     if [ -n "${TIME}" ]; then
         ts "${TIME}"
     fi
+
+    if [ -f "${LOCK_STOP}" ]; then
+        log "${LOCK_STOP} exists, exiting immediately"
+        exit 42
+    fi
 }
 
 ########################################################################
@@ -437,8 +463,14 @@ fi
 # How many logfiles to keep
 LOGROTATE=${LOGROTATE:-400}
 
+# Marker for dinstall start
+DINSTALLSTART="${lockdir}/dinstallstart"
+# Marker for dinstall end
+DINSTALLEND="${lockdir}/dinstallend"
+
 # Timestamps start at -1. so first gets 0
 TS=-1
+touch "${DINSTALLSTART}"
 ts "startup"
 
 # Tell everyone we are doing some work
@@ -460,10 +492,19 @@ LOCK_BRITNEY="$lockdir/britney.lock"
 LOCK_STOP="$lockdir/archive.stop"
 
 lockfile -l 3600 "${LOCK_DAILY}"
-trap cleanup EXIT ERR TERM HUP INT QUIT
+trap onerror ERR
+trap cleanup EXIT TERM HUP INT QUIT
 
 touch "${LOCK_BRITNEY}"
 
+GO=(
+    FUNC="savetimestamp"
+    TIME=""
+    ARGS=""
+    ERR="false"
+)
+stage $GO
+
 GO=(
     FUNC="notice"
     TIME=""
@@ -677,7 +718,7 @@ GO=(
     FUNC="bts"
     TIME=""
     ARGS=""
-    ERR=""
+    ERR="false"
 )
 stage $GO
 
@@ -689,8 +730,6 @@ GO=(
 )
 stage $GO
 
-ulimit -m 90000 -d 90000 -s 10000 -v 200000
-
 GO=(
     FUNC="runparts"
     TIME="run-parts"
@@ -715,8 +754,24 @@ GO=(
 )
 stage $GO
 
+GO=(
+    FUNC="testingsourcelist"
+    TIME=""
+    ARGS=""
+    ERR="false"
+)
+stage $GO
+
 rm -f ${LOCK_BRITNEY}
 
+GO=(
+    FUNC="pgdakdev"
+    TIME="dak-dev db"
+    ARGS=""
+    ERR="false"
+)
+stage $GO
+
 GO=(
     FUNC="aptftpcleanup"
     TIME="apt-ftparchive cleanup"
@@ -735,20 +790,18 @@ stage $GO
 
 log "Daily cron scripts successful, all done"
 
-exec > /dev/null 2>&1
+exec > "$logdir/afterdinstall.log" 2>&1
 
 GO=(
-    FUNC="logstats"
+    FUNC="renamelogfile"
     TIME=""
     ARGS=""
-    ERR=""
+    ERR="false"
 )
 stage $GO
 
-cat "$LOGFILE" | mail -s "Log for dinstall run of ${NOW}" cron@ftp-master.debian.org
-
-savelog -c ${LOGROTATE} -j "$LOGFILE"
 
 # Now, at the very (successful) end of dinstall, make sure we remove
 # our stage files, so the next dinstall run will do it all again.
-rm -f "${stagedir}/*"
+rm -f ${stagedir}/*
+touch "${DINSTALLEND}"