]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.reboot
Proper timestamps in the logs
[dak.git] / config / debian / cron.reboot
1 #!/bin/bash
2 # No way I try to deal with a crippled sh just for POSIX foo.
3
4 # Copyright (C) 2009 Joerg Jaspert <joerg@debian.org>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # exit on errors
20 set -e
21 set -o pipefail
22 # make sure to only use defined variables
23 set -u
24 # ERR traps should be inherited from functions too. (And command
25 # substitutions and subshells and whatnot, but for us the functions is
26 # the important part here)
27 set -E
28
29 # We sleep a while here, as cron - and as such @reboot jobs like this
30 # one - are started pretty early during boot. With parts of the system
31 # still missing, most noticable for us is a not-yet-started postgres...
32 sleep 75
33
34 # import the general variable set.
35 export SCRIPTVARS=/srv/ftp-master.debian.org/dak/config/debian/vars
36 . $SCRIPTVARS
37
38 # common functions are "outsourced"
39 . "${configdir}/common"
40
41 # usually we are not using debug logs. Set to 1 if you want them.
42 DEBUG=0
43
44 # our name
45 PROGRAM="dinstall_reboot"
46
47 # where do we want mails to go? For example log entries made with error()
48 if [[ ${HOSTNAME} != franck ]]; then
49     # Not our ftpmaster host
50     MAILTO=${MAILTO:-"root"}
51 else
52     # Yay, ftpmaster
53     MAILTO=${MAILTO:-"ftpmaster@debian.org"}
54 fi
55
56 # Marker for dinstall start
57 DINSTALLSTART="${lockdir}/dinstallstart"
58 # Marker for dinstall end
59 DINSTALLEND="${lockdir}/dinstallend"
60
61 set +e
62 starttime=$(/usr/bin/stat -c %Z "${DINSTALLSTART}")
63 endtime=$(/usr/bin/stat -c %Z "${DINSTALLEND}")
64 set -e
65
66 if [ ${endtime} -gt ${starttime} ]; then
67         # Great, last dinstall run did seem to end without trouble, no need to rerun
68         log "Last dinstall run did end without trouble, not rerunning"
69         exit 0
70 else
71         # Hrm, it looks like we did not successfully end the last run.
72         # This either means dinstall did abort due to an error, or we had a reboot
73         # No way to tell, so lets restart and see what happens.
74
75         # Make sure we are not fooled by some random touching of the files, only
76         # really restart if we have the first stage stampfile there, indicating that
77         # dinstall got started
78         if [ -f "${stagedir}/savetimestamp" ]; then
79                 log "Seems we have to restart a dinstall run after reboot"
80                 ${configdir}/cron.dinstall
81         fi
82 fi