X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=config%2Fdebian%2Fcron.dinstall;h=195b47fb153fbba856b01defe98ab8d91945788d;hb=1798c52350ce339118397db01f720fb772f63f8a;hp=c730a116c28120978e8bc040f79ec574150de43b;hpb=33d037eb9d2d0ee3c45bc9ae4998e02a797b312b;p=dak.git diff --git a/config/debian/cron.dinstall b/config/debian/cron.dinstall index c730a116..195b47fb 100755 --- a/config/debian/cron.dinstall +++ b/config/debian/cron.dinstall @@ -16,10 +16,23 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Homer: Are you saying you're never going to eat any animal again? What +# about bacon? +# Lisa: No. +# Homer: Ham? +# Lisa: No. +# Homer: Pork chops? +# Lisa: Dad, those all come from the same animal. +# Homer: Heh heh heh. Ooh, yeah, right, Lisa. A wonderful, magical animal. + # exit on errors set -e # make sure to only use defined variables set -u +# ERR traps should be inherited from functions too. (And command +# substitutions and subshells and whatnot, but for us the functions is +# the important part here) +set -E # import the general variable set. export SCRIPTVARS=/srv/ftp.debian.org/dak/config/debian/vars @@ -33,8 +46,7 @@ export SCRIPTVARS=/srv/ftp.debian.org/dak/config/debian/vars # Timestamp. Used for dinstall stat graphs function ts() { - TS=$(($TS+1)); - echo "Archive maintenance timestamp $TS ($1): $(date +%H:%M:%S)" + echo "Archive maintenance timestamp ($1): $(date +%H:%M:%S)" } # Cleanup actions @@ -46,25 +58,22 @@ function cleanup() { # If we error out this one is called, *FOLLOWED* by cleanup above function onerror() { ERRDATE=$(date "+%Y.%m.%d-%H:%M:%S") - cat "$LOGFILE" | mail -s "ATTENTION ATTENTION! dinstall error at ${ERRDATE} (Be quiet, Brain, or I'll stab you with a Q-tip)" cron@ftp-master.debian.org + + subject="ATTENTION ATTENTION!" + if [ "${error}" = "false" ]; then + subject="${subject} (continued)" + else + subject="${subject} (interrupted)" + fi + subject="${subject} dinstall error at ${ERRDATE} in ${STAGEFILE} - (Be quiet, Brain, or I'll stab you with a Q-tip)" + + cat "${STAGEFILE}.log" | mail -s "${subject}" -a "X-Debian: DAK" cron@ftp-master.debian.org } ######################################################################## # the actual dinstall functions follow # ######################################################################## -# Setup the notice file to tell bad mirrors they used the wrong time -function notice() { - rm -f "$NOTICE" - cat > "$NOTICE" <"${OUTFILE}" + + if [ -s "${OUTFILE}" ]; then + /usr/sbin/sendmail -odq -oi -t -f envelope@ftp-master.debian.org < +To: +Subject: Debian Maintainers Keyring changes +Content-Type: text/plain; charset=utf-8 +MIME-Version: 1.0 + +The following changes to the debian-maintainers keyring have just been activated: + +$(cat $OUTFILE) + +Debian distribution maintenance software, +on behalf of the Keyring maintainers + +EOF + fi + rm -f "$OUTFILE" } function overrides() { @@ -207,6 +235,7 @@ function mpfm() { function packages() { log "Generating Packages and Sources files" cd $configdir + GZIP='--rsyncable' ; export GZIP apt-ftparchive generate apt.conf } @@ -242,13 +271,187 @@ function buildd_dir() { make_buildd_dir } +function mklslar() { + cd $ftpdir + + FILENAME=ls-lR + + log "Removing any core files ..." + find -type f -name core -print0 | xargs -0r rm -v + + log "Checking permissions on files in the FTP tree ..." + find -type f \( \! -perm -444 -o -perm +002 \) -ls + find -type d \( \! -perm -555 -o -perm +002 \) -ls + + log "Checking symlinks ..." + symlinks -rd . + + log "Creating recursive directory listing ... " + rm -f .${FILENAME}.new + TZ=UTC ls -lR > .${FILENAME}.new + + if [ -r ${FILENAME}.gz ] ; then + mv -f ${FILENAME}.gz ${FILENAME}.old.gz + mv -f .${FILENAME}.new ${FILENAME} + rm -f ${FILENAME}.patch.gz + zcat ${FILENAME}.old.gz | diff -u - ${FILENAME} | gzip --rsyncable -9cfn - >${FILENAME}.patch.gz + rm -f ${FILENAME}.old.gz + else + mv -f .${FILENAME}.new ${FILENAME} + fi + + gzip --rsyncable -9cfN ${FILENAME} >${FILENAME}.gz + rm -f ${FILENAME} +} + +function mkmaintainers() { + log -n 'Creating Maintainers index ... ' + + cd $indices + dak make-maintainers ${scriptdir}/masterfiles/pseudo-packages.maintainers | \ + sed -e "s/~[^ ]*\([ ]\)/\1/" | awk '{printf "%-20s ", $1; for (i=2; i<=NF; i++) printf "%s ", $i; printf "\n";}' > .new-maintainers + + set +e + cmp .new-maintainers Maintainers >/dev/null + rc=$? + set -e + if [ $rc = 1 ] || [ ! -f Maintainers ] ; then + log -n "installing Maintainers ... " + mv -f .new-maintainers Maintainers + gzip --rsyncable -9v .new-maintainers.gz + mv -f .new-maintainers.gz Maintainers.gz + elif [ $rc = 0 ] ; then + log '(same as before)' + rm -f .new-maintainers + else + log cmp returned $rc + false + fi +} + +function copyoverrides() { + log 'Copying override files into public view ...' + + for f in $copyoverrides ; do + cd $overridedir + chmod g+w override.$f + + cd $indices + rm -f .newover-$f.gz + pc="`gzip 2>&1 -9nv <$overridedir/override.$f >.newover-$f.gz`" + set +e + nf=override.$f.gz + cmp -s .newover-$f.gz $nf + rc=$? + set -e + if [ $rc = 0 ]; then + rm -f .newover-$f.gz + elif [ $rc = 1 -o ! -f $nf ]; then + echo " installing new $nf $pc" + mv -f .newover-$f.gz $nf + chmod g+w $nf + else + echo $? $pc + exit 1 + fi + done +} + +function mkfilesindices() { + umask 002 + cd $base/ftp/indices/files/components + + ARCHLIST=$(tempfile) + + echo "Querying projectb..." + echo 'SELECT l.path, f.filename, a.arch_string FROM location l JOIN files f ON (f.location = l.id) LEFT OUTER JOIN (binaries b JOIN architecture a ON (b.architecture = a.id)) ON (f.id = b.file)' | psql projectb -At | sed 's/|//;s,^/srv/ftp.debian.org/ftp,.,' | sort >$ARCHLIST + + includedirs () { + perl -ne 'print; while (m,/[^/]+$,) { $_=$`; print $_ . "\n" unless $d{$_}++; }' + } + poolfirst () { + perl -e '@nonpool=(); while (<>) { if (m,^\./pool/,) { print; } else { push @nonpool, $_; } } print for (@nonpool);' + } + + echo "Generating sources list..." + ( + sed -n 's/|$//p' $ARCHLIST + cd $base/ftp + find ./dists -maxdepth 1 \! -type d + find ./dists \! -type d | grep "/source/" + ) | sort -u | gzip --rsyncable -9 > source.list.gz + + echo "Generating arch lists..." + + ARCHES=$( (<$ARCHLIST sed -n 's/^.*|//p'; echo amd64) | grep . | grep -v all | sort -u) + for a in $ARCHES; do + (sed -n "s/|$a$//p" $ARCHLIST + sed -n 's/|all$//p' $ARCHLIST + + cd $base/ftp + find ./dists -maxdepth 1 \! -type d + find ./dists \! -type d | grep -E "(proposed-updates.*_$a.changes$|/main/disks-$a/|/main/installer-$a/|/Contents-$a|/binary-$a/)" + ) | sort -u | gzip --rsyncable -9 > arch-$a.list.gz + done + + echo "Generating suite lists..." + + suite_list () { + printf 'SELECT DISTINCT l.path, f.filename FROM (SELECT sa.source AS source FROM src_associations sa WHERE sa.suite = %d UNION SELECT b.source AS source FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) WHERE ba.suite = %d) s JOIN dsc_files df ON (s.source = df.source) JOIN files f ON (df.file = f.id) JOIN location l ON (f.location = l.id)\n' $1 $1 | psql -F' ' -A -t projectb + + printf 'SELECT l.path, f.filename FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) JOIN files f ON (b.file = f.id) JOIN location l ON (f.location = l.id) WHERE ba.suite = %d\n' $1 | psql -F' ' -A -t projectb + } + + printf 'SELECT id, suite_name FROM suite\n' | psql -F' ' -At projectb | + while read id suite; do + [ -e $base/ftp/dists/$suite ] || continue + ( + (cd $base/ftp + distname=$(cd dists; readlink $suite || echo $suite) + find ./dists/$distname \! -type d + for distdir in ./dists/*; do + [ "$(readlink $distdir)" != "$distname" ] || echo $distdir + done + ) + suite_list $id | tr -d ' ' | sed 's,^/srv/ftp.debian.org/ftp,.,' + ) | sort -u | gzip --rsyncable -9 > suite-${suite}.list.gz + done + + echo "Finding everything on the ftp site to generate sundries $(date +"%X")..." + + (cd $base/ftp; find . \! -type d \! -name 'Archive_Maintenance_In_Progress' | sort) >$ARCHLIST + + rm -f sundries.list + zcat *.list.gz | cat - *.list | sort -u | + diff - $ARCHLIST | sed -n 's/^> //p' > sundries.list + + echo "Generating files list $(date +"%X")..." + + for a in $ARCHES; do + (echo ./project/trace; zcat arch-$a.list.gz source.list.gz) | + cat - sundries.list dists.list project.list docs.list indices.list | + sort -u | poolfirst > ../arch-$a.files + done + + (cd $base/ftp/ + for dist in sid squeeze; do + find ./dists/$dist/main/i18n/ \! -type d | sort -u | gzip --rsyncable -9 > $base/ftp/indices/files/components/translation-$dist.list.gz + done + ) + + (cat ../arch-i386.files ../arch-amd64.files; zcat suite-oldstable.list.gz suite-proposed-updates.list.gz ; zcat translation-sid.list.gz ; zcat translation-squeeze.list.gz) | + sort -u | poolfirst > ../typical.files + + rm -f $ARCHLIST + echo "Done!" +} function scripts() { log "Running various scripts from $scriptsdir" cd $scriptsdir - ./mkmaintainers - ./copyoverrides - ./mklslar - ./mkfilesindices + mkmaintainers + copyoverrides + mklslar + mkfilesindices ./mkchecksums } @@ -269,6 +472,12 @@ function expire() { $scriptsdir/expire_dumps -d . -p -f "dump_*" } +function transitionsclean() { + log "Removing out of date transitions..." + cd $base + dak transitions -c -a +} + function reports() { # Send a report on NEW/BYHAND packages log "Nagging ftpteam about NEW/BYHAND packages" @@ -292,8 +501,10 @@ function bts() { function merkel2() { # Push dak@merkel so it syncs the projectb there. Returns immediately, the sync runs detached - log "Trigger merkels projectb sync" + log "Trigger merkel/flotows projectb sync" ssh -2 -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 -i ~/.ssh/push_merkel_projectb dak@merkel.debian.org sleep 1 + # Also trigger flotow, the ftpmaster test box + ssh -2 -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 -i ~/.ssh/push_flotow_projectb dak@flotow.debconf.org sleep 1 } function merkel3() { @@ -302,9 +513,12 @@ function merkel3() { ssh -2 -o BatchMode=yes -o SetupTimeOut=30 -o ConnectTimeout=30 -i ~/.ssh/push_merkel_ddaccess dak@merkel.debian.org sleep 1 } -function runparts() { - log "Using run-parts to run scripts in $base/scripts/distmnt" - run-parts --report $base/scripts/distmnt +function mirrorpush() { + log "Starting the mirrorpush" + date -u > /srv/ftp.debian.org/web/mirrorstart + echo "Using dak v1" >> /srv/ftp.debian.org/web/mirrorstart + echo "Running on host $(hostname -f)" >> /srv/ftp.debian.org/web/mirrorstart + sudo -H -u archvsync /home/archvsync/runmirrors > ~dak/runmirrors.log 2>&1 & } function i18n2() { @@ -316,7 +530,7 @@ function i18n2() { dak control-suite -l testing > squeeze dak control-suite -l unstable > sid echo "${STAMP}" > timestamp - gpg --secret-keyring /srv/ftp.debian.org/s3kr1t/dot-gnupg/secring.gpg --keyring /srv/ftp.debian.org/s3kr1t/dot-gnupg/pubring.gpg --no-options --batch --no-tty --armour --default-key 6070D3A1 --detach-sign -o timestamp.gpg timestamp + gpg --secret-keyring /srv/ftp.debian.org/s3kr1t/dot-gnupg/secring.gpg --keyring /srv/ftp.debian.org/s3kr1t/dot-gnupg/pubring.gpg --no-options --batch --no-tty --armour --default-key 55BE302B --detach-sign -o timestamp.gpg timestamp rm -f md5sum md5sum * > md5sum cd ${webdir}/ @@ -346,15 +560,15 @@ function compress() { cd $base/backup/ find -maxdepth 1 -mindepth 1 -type f -name 'dump_pre_*' -mtime +2 -print0 | xargs -0 --no-run-if-empty rm - find -maxdepth 1 -mindepth 1 -type f -name 'dump_*' \! -name '*.bz2' \! -name '*.gz' -mmin 720 | + find -maxdepth 1 -mindepth 1 -type f -name 'dump_*' \! -name '*.bz2' \! -name '*.gz' -mmin +720 | while read dumpname; do echo "Compressing $dumpname" - bzip2 -9v "$dumpname" + bzip2 -9fv "$dumpname" done - find -maxdepth 1 -mindepth 1 -type f -name "dumpall_*" \! -name '*.bz2' \! -name '*.gz' -mmin 720 | + find -maxdepth 1 -mindepth 1 -type f -name "dumpall_*" \! -name '*.bz2' \! -name '*.gz' -mmin +720 | while read dumpname; do echo "Compressing $dumpname" - bzip2 -9v "$dumpname" + bzip2 -9fv "$dumpname" done finddup -l -d $base/backup } @@ -376,14 +590,14 @@ function maillogfile() { function renamelogfile() { if [ -f "${dbdir}/dinstallstart" ]; then NOW=$(cat "${dbdir}/dinstallstart") - maillogfile - mv "$LOGFILE" "$logdir/dinstall_${NOW}.log" +# maillogfile + mv "$LOGFILE" "$logdir/dinstall_${NOW}.log" logstats "$logdir/dinstall_${NOW}.log" bzip2 -9 "$logdir/dinstall_${NOW}.log" else error "Problem, I don't know when dinstall started, unable to do log statistics." NOW=`date "+%Y.%m.%d-%H:%M:%S"` - maillogfile +# maillogfile mv "$LOGFILE" "$logdir/dinstall_${NOW}.log" bzip2 -9 "$logdir/dinstall_${NOW}.log" fi @@ -392,19 +606,29 @@ function renamelogfile() { function testingsourcelist() { dak ls -s testing -f heidi -r .| egrep 'source$' > ${webdir}/testing.list } + +# do a last run of process-unchecked before dinstall is on. +function process_unchecked() { + log "Processing the unchecked queue" + acceptnew + UNCHECKED_WITHOUT_LOCK="-p" + do_unchecked + sync_debbugs +} + ######################################################################## ######################################################################## # Function to save which stage we are in, so we can restart an interrupted # dinstall. Or even run actions in parallel, if we dare to, by simply # backgrounding the call to this function. But that should only really be -# done for things we dont care much about. +# done for things we don't care much about. # # This should be called with the first argument being an array, with the # members # - FUNC - the function name to call # - ARGS - Possible arguments to hand to the function. Can be the empty string -# - TS - The timestamp name. Can be the empty string +# - TIME - The timestamp name. Can be the empty string # - ERR - if this is the string false, then the call will be surrounded by # set +e ... set -e calls, so errors in the function do not exit # dinstall. Can be the empty string, meaning true. @@ -415,8 +639,11 @@ function stage() { ARGS='GO[@]' local "${!ARGS}" - if [ -f "${stagedir}/${FUNC}" ]; then - stamptime=$(/usr/bin/stat -c %Z "${stagedir}/${FUNC}") + error=${ERR:-"true"} + + STAGEFILE="${stagedir}/${FUNC}" + if [ -f "${STAGEFILE}" ]; then + stamptime=$(/usr/bin/stat -c %Z "${STAGEFILE}") unixtime=$(date +%s) difference=$(( $unixtime - $stamptime )) if [ ${difference} -ge 14400 ]; then @@ -427,18 +654,23 @@ function stage() { return fi - debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TS}" + debug "Now calling function ${FUNC}. Arguments: ${ARGS}. Timestamp: ${TIME}" # Make sure we are always at the same place. If a function wants to be elsewhere, # it has to cd first! cd ${configdir} + # Now redirect the output into $STAGEFILE.log. In case it errors out somewhere our + # errorhandler trap can then mail the contents of $STAGEFILE.log only, instead of a whole + # dinstall logfile. Short error mails ftw! + exec >> "${STAGEFILE}.log" 2>&1 + if [ -f "${LOCK_STOP}" ]; then log "${LOCK_STOP} exists, exiting immediately" exit 42 fi - if [ "${ERR}" = "false" ]; then + if [ "${error}" = "false" ]; then set +e fi ${FUNC} ${ARGS} @@ -449,12 +681,23 @@ function stage() { # Make sure we are always at the same place. cd ${configdir} - touch "${stagedir}/${FUNC}" + # We always use the same umask. If a function wants to do different, fine, but we reset. + umask 022 + + touch "${STAGEFILE}" if [ -n "${TIME}" ]; then ts "${TIME}" fi + # And the output goes back to the normal logfile + exec >> "$LOGFILE" 2>&1 + + # Now we should make sure that we have a usable dinstall.log, so append the $STAGEFILE.log + # to it. + cat "${STAGEFILE}.log" >> "${LOGFILE}" + rm -f "${STAGEFILE}.log" + if [ -f "${LOCK_STOP}" ]; then log "${LOCK_STOP} exists, exiting immediately" exit 42 @@ -483,6 +726,13 @@ else MAILTO=${MAILTO:-"ftpmaster@debian.org"} fi +# Make sure we start out with a sane umask setting +umask 022 + +# And use one locale, no matter what the caller has set +export LANG=C +export LC_ALL=C + # How many logfiles to keep LOGROTATE=${LOGROTATE:-400} @@ -491,20 +741,18 @@ 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 -NOTICE="$ftpdir/Archive_Maintenance_In_Progress" - # lock cron.unchecked (it immediately exits when this exists) LOCK_DAILY="$lockdir/daily.lock" -# Lock process-new and cron.unchecked from doing work +# Lock cron.unchecked from doing work LOCK_ACCEPTED="$lockdir/unchecked.lock" +# Lock process-new from doing work +LOCK_NEW="$lockdir/processnew.lock" + # This file is simply used to indicate to britney whether or not # the Packages file updates completed sucessfully. It's not a lock # from our point of view @@ -542,7 +790,7 @@ GO=( ARGS="" ERR="false" ) -stage $GO +stage $GO & GO=( FUNC="pgdump_pre" @@ -558,7 +806,7 @@ GO=( ARGS="" ERR="false" ) -stage $GO +stage $GO & GO=( FUNC="punew" @@ -582,9 +830,19 @@ GO=( ARGS="" ERR="false" ) -stage $GO +stage $GO & lockfile "$LOCK_ACCEPTED" +lockfile "$LOCK_NEW" + +GO=( + FUNC="process_unchecked" + TIME="" + ARGS="" + ERR="" +) +stage $GO + GO=( FUNC="accepted" @@ -611,6 +869,7 @@ GO=( stage $GO rm -f "$LOCK_ACCEPTED" +rm -f "$LOCK_NEW" GO=( FUNC="msfl" @@ -626,7 +885,7 @@ GO=( ARGS="" ERR="false" ) -stage $GO +stage $GO & GO=( FUNC="overrides" @@ -706,9 +965,8 @@ GO=( ARGS="" ERR="" ) -stage $GO +stage $GO & -rm -f "${NOTICE}" rm -f "${LOCK_DAILY}" ts "locked part finished" @@ -719,7 +977,7 @@ GO=( ARGS="" ERR="" ) -stage $GO +stage $GO & GO=( FUNC="expire" @@ -727,7 +985,15 @@ GO=( ARGS="" ERR="" ) -stage $GO +stage $GO & + +GO=( + FUNC="transitionsclean" + TIME="transitionsclean" + ARGS="" + ERR="" +) +stage $GO & GO=( FUNC="reports" @@ -735,7 +1001,7 @@ GO=( ARGS="" ERR="" ) -stage $GO +stage $GO & GO=( FUNC="dm" @@ -743,7 +1009,7 @@ GO=( ARGS="" ERR="" ) -stage $GO +stage $GO & GO=( FUNC="bts" @@ -751,7 +1017,7 @@ GO=( ARGS="" ERR="false" ) -stage $GO +stage $GO & GO=( FUNC="merkel2" @@ -759,11 +1025,11 @@ GO=( ARGS="" ERR="false" ) -stage $GO +stage $GO & GO=( - FUNC="runparts" - TIME="run-parts" + FUNC="mirrorpush" + TIME="mirrorpush" ARGS="" ERR="false" ) @@ -783,7 +1049,7 @@ GO=( ARGS="" ERR="false" ) -stage $GO +stage $GO & GO=( FUNC="testingsourcelist" @@ -801,15 +1067,7 @@ GO=( ARGS="" ERR="false" ) -stage $GO - -GO=( - FUNC="aptftpcleanup" - TIME="apt-ftparchive cleanup" - ARGS="" - ERR="" -) -stage $GO +stage $GO & GO=( FUNC="merkel3" @@ -817,7 +1075,7 @@ GO=( ARGS="" ERR="false" ) -stage $GO +stage $GO & GO=( FUNC="compress" @@ -825,6 +1083,14 @@ GO=( ARGS="" ERR="" ) +stage $GO & + +GO=( + FUNC="aptftpcleanup" + TIME="apt-ftparchive cleanup" + ARGS="" + ERR="false" +) stage $GO log "Daily cron scripts successful, all done"