X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=config%2Fdebian%2Fcron.dinstall;h=708f49bb9c206506652ffe5e5ed9d380eae04dd8;hb=e8886b409b2824c6dfd2eb806c3a2f59c335642b;hp=9ee1781cc83f9ad994a860c4db45a7843066b0b7;hpb=722e5d1fce306b22b998e60d409366f11a7fc35c;p=dak.git diff --git a/config/debian/cron.dinstall b/config/debian/cron.dinstall index 9ee1781c..708f49bb 100755 --- a/config/debian/cron.dinstall +++ b/config/debian/cron.dinstall @@ -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,10 @@ function cleanup() { rm -f ${LOCK_ACCEPTED} } +######################################################################## +# 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 +74,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' `cat current` | psql -p 5433 projectb } # Updating various files @@ -169,9 +160,9 @@ function accepted() { log "Processing queue/accepted" rm -f "$accepted/REPORT" dak process-accepted -pa -d "$accepted" > "$accepted/REPORT" - cat REPORT | mail -s "Install for $(date +"%D - %R")" ftpmaster@ftp-master.debian.org - chgrp debadmin REPORT - chmod 664 REPORT + cat "$accepted/REPORT" | mail -s "Install for $(date +"%D - %R")" ftpmaster@ftp-master.debian.org + chgrp debadmin "$accepted/REPORT" + chmod 664 "$accepted/REPORT" } function cruft() { @@ -340,7 +331,27 @@ 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 renamelogfile() { + if [ -f "${dbdir}/dinstallstart" ]; then + RENAMETO=$(cat "${dbdir}/dinstallstart") + mv "$LOGFILE" "$logdir/dinstall_${RENAMETO}.log" + logstats "$logdir/dinstall_${RENAMETO}.log" + bzip2 -9 "$logdir/dinstall_${RENAMETO}.log" + else + error "Problem, I don't know when dinstall started, unable to do log statistics." + NOW=`date "+%Y.%m.%d-%H:%M:%S"` + mv "$LOGFILE" "$logdir/dinstall_${NOW}.log" + bzip2 -9 "$logdir/dinstall_${NOW}.log" + fi } ######################################################################## @@ -402,14 +413,14 @@ function stage() { touch "${stagedir}/${FUNC}" + if [ -n "${TIME}" ]; then + ts "${TIME}" + fi + if [ -f "${LOCK_STOP}" ]; then log "${LOCK_STOP} exists, exiting immediately" exit 42 fi - - if [ -n "${TIME}" ]; then - ts "${TIME}" - fi } ######################################################################## @@ -437,8 +448,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 @@ -464,6 +481,14 @@ trap cleanup EXIT ERR TERM HUP INT QUIT touch "${LOCK_BRITNEY}" +GO=( + FUNC="savetimestamp" + TIME="" + ARGS="" + ERR="false" +) +stage $GO + GO=( FUNC="notice" TIME="" @@ -649,6 +674,14 @@ GO=( ) stage $GO +GO=( + FUNC="pgdakdev" + TIME="dak-dev db" + ARGS="" + ERR="false" +) +stage $GO + GO=( FUNC="expire" TIME="expire_dumps" @@ -735,20 +768,20 @@ stage $GO log "Daily cron scripts successful, all done" -exec > /dev/null 2>&1 +exec > "$logdir/afterdinstall.log" 2>&1 + +cat "$LOGFILE" | mail -s "Log for dinstall run of ${NOW}" cron@ftp-master.debian.org 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}"