2 # log something (basically echo it together with a timestamp)
4 # Set $PROGRAM to a string to have it added to the output.
6 local prefix=${PROGRAM:-}
7 echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${prefix}[$$]: $@"
10 # log the message using log() but then also send a mail
11 # to the address configured in MAILTO (if non-empty)
12 function log_error () {
14 if [ -z "${MAILTO}" ]; then
15 echo "$@" | mail -a "X-Debian: DAK" -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ${MAILTO}
19 # debug log, only output when DEBUG=1
21 if [ $DEBUG -eq 1 ]; then
26 # Function that only cleans tempfiles, but does not exit or otherwise
27 # care about any exit status
28 function cleantempfiles() {
30 for TEMPFILE in $TMPFILES; do
31 if [ -n "${TEMPFILE}" ] && [ -f "${TEMPFILE}" ]; then
33 elif [ -n "${TEMPFILE}" ] && [ -d "${TEMPFILE}" ]; then
34 if [ "${TEMPFILE}" != "/" ] && [ "${TEMPFILE}" != "/*" ]; then
42 function resolvetmpfiles() {
43 # If you don't understand this better not touch the script
44 for TEMPFILE in $TEMPFILES; do
45 TMPFILES="${TMPFILES} ${!TEMPFILE:-""}"
52 # Cleans up any known tempfile.
53 # Just ensure your script sets the variable
54 # TEMPFILES to the names of variables of tempfiles
55 # Or TMPFILES to the pathes of tempfiles
58 trap - ERR EXIT TERM HUP INT QUIT
64 TEMPFILES=${TEMPFILES:-""}
65 TMPFILES=${TMPFILES:-""}
67 # Timestamp. Used for dinstall stat graphs
69 echo "Archive maintenance timestamp ($1): $(date +%H:%M:%S)"
72 ########################################################################
73 ########################################################################
75 function wbtrigger() {
76 SSHOPT="-n -o BatchMode=yes -o ConnectTimeout=30 -o SetupTimeout=240"
77 if lockfile -r 3 -l 3600 "${LOCK_BUILDD}"; then
78 ssh -q -q ${SSHOPT} wbadm@buildd /srv/wanna-build/trigger.often
80 rm -f "${LOCK_BUILDD}"
83 # used by cron.dinstall *and* cron.unchecked.
84 function make_buildd_dir () {
85 # We generate straight into the static mirror location for incoming
86 dak manage-build-queues -a
87 dak generate-packages-sources2 -a build-queues
88 dak generate-releases -a build-queues >/dev/null
90 # Stick a last modified date in the page footer
91 echo "<p>Last updated: `date -u`</p>" > ${incoming}/web/README.html
93 # Tell the mirrors that we've updated
94 chronic /usr/local/bin/static-update-component incoming.debian.org
97 # Process (oldstable)-proposed-updates "NEW" queue
104 dak process-policy "${queue}" | tee -a REPORT | mail -a "X-Debian: DAK" -e -s "NEW changes in ${queue}" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" "${to}"
107 dak generate-packages-sources2 -s "${queue}"
109 STAMP=${STAMP:-$(date "+%Y%m%d%H%M")}
111 local exportdir="${qdir}/tree/${STAMP}"
112 local targetdir="${qdir}/export"
113 mkdir -p -- ${exportdir}
114 dak export -q "${queue}" -d "${exportdir}" --all
115 ln -sfT ${exportdir} ${targetdir}
116 find "${qdir}/tree" -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
119 # These versions used in dinstall
121 log "Doing automated p-u-new processing"
122 cd "${queuedir}/p-u-new"
123 punew_do "$1" "${queuedir}/p-u-new" "debian-release@lists.debian.org"
127 log "Doing automated o-p-u-new processing"
128 cd "${queuedir}/o-p-u-new"
129 punew_do "$1" "${queuedir}/o-p-u-new" "debian-release@lists.debian.org"
132 function backports_policy() {
133 local queue="backports-policy"
134 local qdir="/srv/backports-master.debian.org/queue/policy"
135 local to="backports-team@debian.org"
137 log "Doing automated ${queue} processing"
140 punew_do "${queue}" "${qdir}" "${to}"
143 # Do the unchecked processing, in case we have files.
144 function do_unchecked () {
147 changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
148 report=$queuedir/REPORT
149 timestamp=$(date "+%Y-%m-%d %H:%M")
150 UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
152 echo "$timestamp": ${changes:-"Nothing to do"} >> $report
153 dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
154 dak process-commands -d "$unchecked" >> $report
156 if [ ! -z "$changes" ]; then
162 # process NEW policy queue
164 log "Doing NEW processing"
165 (dak process-policy new; dak process-policy byhand) | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND processing" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ftpmaster@ftp-master.debian.org
167 log "Processing Backports NEW"
168 dak process-policy backports-new | mail -a "X-Debian: DAK" -e -s "NEW processing for backports-new" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" backports-team@debian.org
170 log "Cleanup NEW/Backports NEW"
171 dak clean-suites -a new,backports-new
174 function sync_debbugs () {
177 timestamp=$(date "+%Y-%m-%d-%H:%M")
178 mkdir -p $queuedir/bts_version_track_archive/${timestamp}
179 rsync -aq $queuedir/bts_version_track/ $queuedir/bts_version_track_archive/${timestamp}
180 rmdir --ignore-fail-on-non-empty $queuedir/bts_version_track_archive/${timestamp} # remove if empty.
181 rsync -aq -e "ssh -o Batchmode=yes -o ConnectTimeout=30 -o SetupTimeout=30" --remove-source-files $queuedir/bts_version_track/ bugs-sync:/srv/bugs.debian.org/versions/queue/ftp-master/ 2>/dev/null && touch $lockdir/synced_bts_version || true
183 TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
184 DIFF=$(( NOW - TSTAMP ))
185 if [ $DIFF -ge 259200 ]; then
186 log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
190 function clean_debbugs () {
191 # Delete files older than 60 days
192 find $queuedir/bts_version_track_archive/ -mtime +60 -type f -delete
193 # Delete empty directories
194 find $queuedir/bts_version_track_archive/ -empty -type d -delete
198 # Send a report on NEW/BYHAND packages
199 log "Nagging ftpteam about NEW/BYHAND packages"
200 dak queue-report | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND on $(date +%D)" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ftpmaster@ftp-master.debian.org
201 dak queue-report -d backports-new,backports-policy | mail -a "X-Debian: DAK" -e -s "NEW and POLICY on $(date +%D)" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" backports-team@debian.org
202 # and one on crufty packages
203 log "Sending information about crufty packages"
204 dak cruft-report -R > $webdir/cruft-report-daily.txt
205 dak cruft-report -R -s experimental >> $webdir/cruft-report-daily.txt
206 cat $webdir/cruft-report-daily.txt | mail -a "X-Debian: DAK" -e -s "Debian archive cruft report for $(date +%D)" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ftpmaster@ftp-master.debian.org
209 function pg_timestamp() {
210 tsname=${1:-"unknown"}
211 log "Saving postgres transaction id for ${tsname}"
212 psql -tAc 'select txid_current();' > $base/backup/txid_${tsname}_$(date +%Y.%m.%d-%H:%M:%S)
215 function get_archiveroot() {
216 local archivename="$1"
217 local query="SELECT path FROM archive WHERE name='${archivename}'"
218 local archiveroot="$(psql -tAc "${query}")"
219 if [ -z "${archiveroot}" ]; then
220 echo "get_archiveroot: couldn't get archiveroot for '${archivename}'" >&2
223 echo "${archiveroot}"
226 # Prepare the trees for buildds, then push wanna-build
227 function do_buildd() {
228 if lockfile -r3 ${LOCK_DAILY}; then
229 TMPFILES="${TMPFILES} ${LOCK_DAILY}"
235 # Cleanup policy queues
236 function cleanpolicy() {
237 dak clean-suites -a backports-policy,policy
240 # Scan new packages for contents
241 function scancontents() {
242 dak contents -l 10000 scan-binary
243 dak contents -l 1000 scan-source
246 function ddaccess() {
247 # Tell our dd accessible mirror to sync itself up. Including ftp dir.
248 log "Trigger dd accessible parts sync including ftp dir"
249 ${scriptsdir}/sync-dd dd-sync dd-sync1 dd-sync2 sync
254 ########################################################################
255 ########################################################################
256 ########################################################################
257 ########################################################################
259 # Function to save which stage we are in, so we can restart an interrupted
260 # dinstall. Or even run actions in parallel, if we dare to, by simply
261 # backgrounding the call to this function. But that should only really be
262 # done for things we don't care much about.
264 # This should be called with the first argument being an array, with the
266 # - FUNC - the function name to call
267 # - ARGS - Possible arguments to hand to the function. Can be the empty string
268 # - TIME - The timestamp name. Can be the empty string
269 # - ERR - if this is the string false, then the call will be surrounded by
270 # set +e ... set -e calls, so errors in the function do not exit
271 # dinstall. Can be the empty string, meaning true.
273 # MAKE SURE TO KEEP THIS THE LAST FUNCTION, AFTER ALL THE VARIOUS ONES
274 # ADDED FOR DINSTALL FEATURES!
279 local error=${ERR:-"true"}
283 log "########## ${PROGRAM} BEGIN: ${FUNC} ${ARGS} ##########"
284 local STAGEFILE="${stagedir}/${FUNC}_${ARGS}"
285 STAGEFILE=${STAGEFILE// /_}
286 if [ -f "${STAGEFILE}" ]; then
287 local stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}")
288 local unixtime=$(date +%s)
289 local difference=$(( $unixtime - $stamptime ))
290 if [ ${difference} -ge 14400 ]; then
291 log_error "Did already run ${FUNC}, stagefile exists, but that was ${difference} seconds ago. Please check."
293 log "Did already run ${FUNC}, not calling again..."
298 debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}"
300 # Make sure we are always at the same place. If a function wants
301 # to be elsewhere, it has to cd first!
304 # Now redirect the output into $STAGEFILE.log. In case it errors
305 # out somewhere our errorhandler trap can then mail the contents
306 # of $STAGEFILE.log only, instead of a whole ${PROGRAM} logfile.
307 # Short error mails ftw!
308 exec >> "${STAGEFILE}.log" 2>&1
310 if [ -f "${LOCK_STOP}" ]; then
311 log "${LOCK_STOP} exists, exiting immediately"
315 # Do we care about trouble in the function we call?
316 if [ "${error}" = "false" ]; then
321 # No matter what happened in the function, we make sure we have
322 # set -e default state back
325 # Make sure we are always at the same place.
328 # We always use the same umask. If a function wants to do
329 # different, fine, but we reset.
334 if [ -n "${TIME}" ]; then
338 # And the output goes back to the normal logfile
339 exec >> "${LOGFILE}" 2>&1
341 # Now we should make sure that we have a usable ${PROGRAM}.log, so
342 # append the $STAGEFILE.log to it.
343 cat "${STAGEFILE}.log" >> "${LOGFILE}"
344 rm -f "${STAGEFILE}.log"
346 log "########## ${PROGRAM} END: ${FUNC} ##########"
348 if [ -f "${LOCK_STOP}" ]; then
349 log "${LOCK_STOP} exists, exiting immediately"