]> git.decadent.org.uk Git - dak.git/blob - config/debian/cron.daily
Add logging to cronjobs
[dak.git] / config / debian / cron.daily
1 #! /bin/sh
2 #
3 # Executed daily via cron, out of dak's crontab.
4
5 set -e
6 export SCRIPTVARS=/srv/ftp.debian.org/dak/config/debian/vars
7 . $SCRIPTVARS
8
9 ################################################################################
10
11 # Start logging
12 NOW=`date "+%Y.%m.%d-%H:%M:%S"`
13 LOGFILE="$logdir/daily_${NOW}.log"
14 exec > "$LOGFILE" 2>&1
15
16 echo Archive maintenance started at $(date +%X)
17 TS=0
18
19 NOTICE="$ftpdir/Archive_Maintenance_In_Progress"
20 LOCKCU="$lockdir/daily.lock"
21 LOCKAC="$lockdir/unchecked.lock"
22 lockac=0
23
24 cleanup() {
25   rm -f "$NOTICE"
26   rm -f "$LOCKCU"
27   if [ "$lockac" -eq "1" ]; then
28     rm -f "$LOCKAC"
29   fi
30   echo "Cleanup"
31   rm -f "$LOGFILE"
32 }
33 lockfile -l 3600 $LOCKCU
34 trap cleanup 0
35
36 rm -f "$NOTICE"
37 cat > "$NOTICE" <<EOF
38 Packages are currently being installed and indices rebuilt.
39 Maintenance is automatic, starting at 13:52 US Central time, and
40 ending at about 15:30.  This file is then removed.
41
42 You should not mirror the archive during this period.
43 EOF
44
45 # Push merkels qa user, so the qa pages can show "dinstall is running" information
46 echo "Telling merkels QA user that we start dinstall"
47 ssh -2 -i ~dak/.ssh/push_merkel_qa  -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 qa@merkel.debian.org sleep 1
48
49 ################################################################################
50
51 echo "Creating pre-daily-cron-job backup of projectb database..."
52 pg_dump projectb > $base/backup/dump_$(date +%Y.%m.%d-%H:%M:%S)
53
54 ################################################################################
55
56 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
57 echo "Updating Bugs docu, Mirror list and mailing-lists.txt"
58 cd $configdir
59 $scriptsdir/update-bugdoctxt
60 $scriptsdir/update-mirrorlists
61 $scriptsdir/update-mailingliststxt
62
63 ################################################################################
64
65 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
66 echo "Doing automated p-u-new processing"
67 cd $queuedir/p-u-new
68 date -u -R >> REPORT
69 dak process-new -a -C COMMENTS >> REPORT
70 echo >> REPORT
71
72 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
73 echo "Doing automated o-p-u-new processing"
74 cd $queuedir/o-p-u-new
75 date -u -R >> REPORT
76 dak process-new -a -C COMMENTS >> REPORT
77 echo >> REPORT
78
79 ################################################################################
80
81 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
82 lockfile $LOCKAC
83 lockac=1
84 echo "Processing queue/accepted"
85 cd $accepted
86 rm -f REPORT
87 dak process-accepted -pa *.changes | tee REPORT | \
88      mail -s "Install for $(date +%D)" ftpmaster@ftp-master.debian.org
89 chgrp debadmin REPORT
90 chmod 664 REPORT
91
92 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
93 echo "Checking for cruft in overrides"
94 dak check-overrides
95 rm -f $LOCKAC
96 lockac=0
97
98 echo "Fixing symlinks in $ftpdir"
99 symlinks -d -r $ftpdir
100
101 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
102
103 echo "Generating suite file lists for apt-ftparchive"
104 dak make-suite-file-list
105
106 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
107
108 echo "Updating fingerprints"
109 # Update fingerprints
110 dak import-keyring -L /srv/keyring.debian.org/keyrings/debian-keyring.gpg
111
112 # Generate override files
113 echo "Writing overrides into text files"
114 cd $overridedir
115 dak make-overrides
116
117 # FIXME
118 rm -f override.sid.all3
119 for i in main contrib non-free main.debian-installer; do cat override.sid.$i >> override.sid.all3; done
120
121 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
122
123 # Generate Packages and Sources files
124 echo "Generating Packages and Sources files"
125 cd $configdir
126 apt-ftparchive generate apt.conf
127 # Generate *.diff/ incremental updates
128 echo "Generating pdiff files"
129 dak generate-index-diffs
130 # Generate Release files
131 echo "Generating Release files"
132 dak generate-releases
133
134 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
135
136 # Clean out old packages
137 echo "Cleanup old packages/files"
138 dak clean-suites
139 dak clean-queues
140
141 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
142
143 # Needs to be rebuilt, as files have moved.  Due to unaccepts, we need to
144 # update this before wanna-build is updated.
145 echo "Regenerating wanna-build/buildd information"
146 psql projectb -A -t -q -c "SELECT filename FROM queue_build WHERE suite = 5 AND queue = 0 AND in_queue = true AND filename ~ 'd(sc|eb)$'" > $dbdir/dists/unstable_accepted.list
147 symlinks -d /srv/incoming.debian.org/buildd > /dev/null
148 apt-ftparchive generate apt.conf.buildd
149
150 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
151
152 echo "Running various scripts from $scriptsdir"
153 cd $scriptsdir
154 ./mkmaintainers
155 ./copyoverrides
156 ./mklslar
157 ./mkfilesindices
158 ./mkchecksums
159 #
160 rm -f $NOTICE
161 echo "Trigger daily wanna-build run"
162 ssh buildd@buildd /org/wanna-build/trigger.daily
163
164 rm -f $LOCKCU
165 echo Archive maintenance finished at $(date +%X)
166
167 ################################################################################
168
169 echo "Creating post-daily-cron-job backup of projectb database..."
170 POSTDUMP=$base/backup/dump_$(date +%Y.%m.%d-%H:%M:%S)
171 pg_dump projectb > $POSTDUMP
172 (cd $base/backup; ln -sf $POSTDUMP current)
173
174 ################################################################################
175
176 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
177
178 echo "Expiring old database dumps..."
179 (cd $base/backup; $scriptsdir/expire_dumps -d . -p -f "dump_*")
180
181 ################################################################################
182
183 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
184
185 # Send a report on NEW/BYHAND packages
186 echo "Nagging ftpteam about NEW/BYHAND packages"
187 dak queue-report | mail -e -s "NEW and BYHAND on $(date +%D)" ftpmaster@ftp-master.debian.org
188 # and one on crufty packages
189 echo "Sending information about crufty packages"
190 dak cruft-report > $webdir/cruft-report-daily.txt
191 dak cruft-report -s experimental >> $webdir/cruft-report-daily.txt
192 cat $webdir/cruft-report-daily.txt | mail -e -s "Debian archive cruft report for $(date +%D)" ftpmaster@ftp-master.debian.org
193
194 echo "Updating DM html page"
195 $scriptsdir/dm-monitor >$webdir/dm-uploaders.html
196
197 ################################################################################
198
199 # Push katie@merkel so it syncs the projectb there. Returns immediately, the sync runs detached
200 echo "Trigger merkels projectb sync"
201 ssh -2 -i ~/.ssh/push_merkel_projectb katie@merkel.debian.org sleep 1
202
203 ################################################################################
204
205 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
206
207 ulimit -m 90000 -d 90000 -s 10000 -v 200000
208
209 echo "Using run-parts to run scripts in $base/scripts/distmnt"
210 run-parts --report $base/scripts/distmnt
211
212 echo "Daily cron scripts successful."
213
214 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
215
216 # Stats pr0n
217 echo "Updating stats data"
218 cd $configdir
219 $scriptsdir/update-ftpstats $base/log/* > $base/misc/ftpstats.data
220 R --slave --vanilla < $base/misc/ftpstats.R
221
222 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
223
224 # Clean up apt-ftparchive's databases
225 echo "Clean up apt-ftparchive's databases"
226 cd $configdir
227 apt-ftparchive -q clean apt.conf
228
229 TS=$(($TS+1)); echo Archive maintenance timestamp $TS: $(date +%X)
230
231 # Compress psql backups older than a week, but no more than 20 of them
232 echo "Compress old psql backups"
233 (cd $base/backup/
234  find -maxdepth 1 -mindepth 1 -type f -name 'dump_*' \! -name '*.bz2' \! -name '*.gz' -mtime +7 | 
235    sort | head -n20 | while read dumpname; do
236      echo "Compressing $dumpname"
237      bzip2 -9 "$dumpname"
238    done
239 )
240
241 echo "Finally, all is done, sending mail and compressing logfile"
242 exec > /dev/null 2>&1
243
244 cat "$LOGFILE" | mail -s "Log for cron.daily run of $(date +%Y.%m.%d)" cron@ftp-master.debian.org
245 bzip2 -9 "$LOGFILE"
246
247 ################################################################################