--- /dev/null
+# 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
+}
########################################################################
# 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() {
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
}
########################################################################
# 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
# 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}"
--- /dev/null
+#!/bin/bash
+# No way I try to deal with a crippled sh just for POSIX foo.
+
+# Copyright (C) 2009 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
+# 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