From: Joerg Jaspert Date: Mon, 23 Feb 2009 22:46:41 +0000 (+0100) Subject: dinstall / reboot X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=74cf3b9ed589b4845048f51a96b3d6f50cca94f8;p=dak.git dinstall / reboot add a first pass of a script intended to restart dinstall after a reboot, in case it was running right before. Signed-off-by: Joerg Jaspert --- diff --git a/config/debian/common b/config/debian/common new file mode 100644 index 00000000..ad10ea6c --- /dev/null +++ b/config/debian/common @@ -0,0 +1,26 @@ +# 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 +} diff --git a/config/debian/cron.dinstall b/config/debian/cron.dinstall index 3401fb27..383ba334 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() { @@ -426,14 +402,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 } ######################################################################## @@ -461,8 +437,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 @@ -782,4 +764,5 @@ stage $GO # 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}" diff --git a/config/debian/cron.reboot b/config/debian/cron.reboot new file mode 100755 index 00000000..b3c0b09a --- /dev/null +++ b/config/debian/cron.reboot @@ -0,0 +1,72 @@ +#!/bin/bash +# No way I try to deal with a crippled sh just for POSIX foo. + +# Copyright (C) 2009 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 +# published by the Free Software Foundation; version 2. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# exit on errors +set -e +# make sure to only use defined variables +set -u + +# import the general variable set. +export SCRIPTVARS=/srv/ftp.debian.org/dak/config/debian/vars +. $SCRIPTVARS + +# common functions are "outsourced" +. "${configdir}/common" + +# usually we are not using debug logs. Set to 1 if you want them. +DEBUG=0 + +# our name +PROGRAM="dinstall_reboot" + +# where do we want mails to go? For example log entries made with error() +if [ "x$(hostname -s)x" != "xriesx" ]; then + # Not our ftpmaster host + MAILTO=${MAILTO:-"root"} +else + # Yay, ftpmaster + MAILTO=${MAILTO:-"ftpmaster@debian.org"} +fi + +# Marker for dinstall start +DINSTALLSTART="${lockdir}/dinstallstart" +# Marker for dinstall end +DINSTALLEND="${lockdir}/dinstallend" + +set +e +starttime=$(/usr/bin/stat -c %Z "${DINSTALLSTART}") +endtime=$(/usr/bin/stat -c %Z "${DINSTALLEND}") +set -e + +if [ ${endtime} -gt ${starttime} ]; then + # Great, last dinstall run did seem to end without trouble, no need to rerun + log "Last dinstall run did end without trouble, not rerunning" + exit 0 +else + # Hrm, it looks like we did not successfully end the last run. + # This either means dinstall did abort due to an error, or we had a reboot + # No way to tell, so lets restart and see what happens. + + # Make sure we are not fooled by some random touching of the files, only + # really restart if we have the first stage stampfile there, indicating that + # dinstall got started + if [ -f "${stagedir}/savetimestamp" ]; then + log "Seems we have to restart a dinstall run after reboot" + ${configdir}/cron.dinstall + fi +fi