Files
ports/Tools/portbuild/scripts/pdispatch
T
Kris Kennaway cb3b4b98c7 * Bail out if we can't claim a chroot directory in the client (e.g. if
ssh times out)

* Support new portbuild.conf settings:

    client_user = user to connect to on the client (not necessarily root)

    sudo_cmd = If ssh'ing to a non-root user, run this command to gain
               root privs (set to empty string for client_user=root,
               or sudo for !root).  Cannot require interactivity, of
               course.

Approved by:    portmgr (self)
2004-09-26 22:04:57 +00:00

131 lines
4.3 KiB
Bash
Executable File

#!/bin/sh
#
# pdispatch <arch> <branch> <command> <package.tgz> [<args> ...]
#
# Choose a random machine from ${buildroot}/ulist and dispatch the
# job to it via the ptimeout script.
pb=/var/portbuild
arch=$1
shift
. ${pb}/${arch}/portbuild.conf
. ${pb}/scripts/buildenv
# Increase timeout on slow build machines
if [ "$arch" = "alpha" -o "$arch" = "sparc64" ]; then
# wait 16 hours maximum
timeout=57600
else
# wait 80 hours maximum
timeout=288000
fi
branch=$1
command=$2
shift 2
buildenv ${pb} ${arch} ${branch}
# ssh -x doesn't work on some machines
unset DISPLAY
pkgname=$(basename $1 ${PKGSUFFIX})
if grep -qxF ${pkgname} ${pb}/${arch}/${branch}/duds; then
echo "skipping ${pkgname}"
exit 1
fi
args=${1+"$@"}
num=$(wc -w ${pb}/${arch}/ulist | awk '{print $1}')
random=$(jot -r 1 1 ${num})
mach=$(cat ${pb}/${arch}/ulist | cut -f ${random} -d ' ' )
# If ulist is empty, then all build machines are busy, so try again in 15 seconds.
if [ -z "${mach}" ]; then
echo "All machines busy, sleeping"
sleep 15
echo "Retrying build of ${pkgname}"
make ${pkgname}
exit 0
fi
set $mach
flags=""
noclean=0
if [ "x$NOCLEAN" != "x" ]; then
flags="${flags} -noclean"
noclean=1
fi
if [ "x$NO_RESTRICTED" != "x" ]; then
flags="${flags} -norestr"
fi
if [ "x$PLISTCHECK" != "x" ]; then
flags="${flags} -plistcheck"
fi
if [ "x$NODUMMY" != "x" ]; then
flags="${flags} -nodummy"
fi
if [ "x$WANT_DISTFILES" != "x" ]; then
flags="${flags} -distfiles"
fi
if [ "x$FETCH_ORIGINAL" != "x" ]; then
flags="${flags} -fetch-original"
fi
if [ "x$TRYBROKEN" != "x" ]; then
flags="${flags} -trybroken"
fi
host=$1
. ${pb}/${arch}/portbuild.${host}
while [ -z "${chroot}" ]; do
echo "Claiming a directory for ${pkgname} on ${host}"
# May still fail if ssh times out?
chroot=$(ssh -a -n ${client_user}@${host} ${sudo_cmd} ${pb}/scripts/claim-chroot ${arch} ${branch} ${pkgname})
status=$?
if [ ! ${status} ]; then
echo "!!! Exiting from claim-chroot with status ${status} (${host} ${pkgname})"
exit ${status}
fi
done
echo "--> got directory ${chroot}"
echo "dispatching: ssh -a -t -n ${client_user}@${host} ${sudo_cmd} ${command} ${arch} ${branch} ${chroot} ${flags} \"$ED\" \"$PD\" \"$FD\" \"$BD\" \"$RD\" ${args}"
${pb}/scripts/ptimeout.host $timeout ssh -a -t -n ${client_user}@${host} ${sudo_cmd} ${command} ${arch} ${branch} ${chroot} ${flags} \"$ED\" \"$PD\" \"$FD\" \"$BD\" \"$RD\" ${args}
error=$?
# Pull in the results of the build from the client
scp ${client_user}@${host}:${chroot}/tmp/${pkgname}.log ${pb}/${arch}/${branch}/logs/${pkgname}.log
(ssh -a -n ${client_user}@${host} test -f ${chroot}/tmp/work.tbz ) && scp ${client_user}@${host}:${chroot}/tmp/work.tbz ${pb}/${arch}/${branch}/wrkdirs/${pkgname}.tbz
if [ "x$WANT_DISTFILES" != "x" ]; then
mkdir -p ${pb}/${arch}/${branch}/distfiles/.pbtmp/${pkgname}
ssh -a -n ${client_user}@${host} tar -C ${chroot}/tmp/distfiles -cf - . | \
tar --unlink -C ${pb}/${arch}/${branch}/distfiles/.pbtmp/${pkgname} -xvf -
touch ${pb}/${arch}/${branch}/distfiles/.pbtmp/${pkgname}/.done
fi
if [ "${error}" = 0 ]; then
ssh -a -n ${client_user}@${host} tar -C ${chroot}/tmp -cf - packages | \
tar --unlink -C ${pb}/${arch}/${branch} -xvf -
test -f ${pb}/${arch}/${branch}/packages/All/${pkgname}${PKGSUFFIX} && \
touch ${pb}/${arch}/${branch}/packages/All/${pkgname}${PKGSUFFIX}
rm -f ${pb}/${arch}/${branch}/errors/${pkgname}.log
lockf ${pb}/${arch}/${branch}/failure.lock ${pb}/scripts/buildsuccess ${arch} ${branch} ${pkgname}
if grep -q "even though it is marked BROKEN" ${pb}/${arch}/${branch}/logs/$pkgname.log; then
echo | mail -s "${pkgname} BROKEN but built on ${arch} ${branch}" kris@FreeBSD.org
fi
else
log=${pb}/${arch}/${branch}/errors/${pkgname}.log
scp ${client_user}@${host}:${chroot}/tmp/${pkgname}.log ${log} || (echo ${chroot}@${host}; ssh -a -n ${client_user}@${host} ls -laR ${chroot}/tmp) | mail -s "${pkgname} logfile not found" kris@FreeBSD.org
if ! grep -q "even though it is marked BROKEN" ${log}; then
tail -1000 ${log} | mail -s "${pkgname} failed on ${arch} ${branch}" kris@FreeBSD.org
fi
lockf ${pb}/${arch}/${branch}/failure.lock ${pb}/scripts/buildfailure ${arch} ${branch} ${pkgname}
fi
ssh -a -n ${client_user}@${host} ${sudo_cmd} ${pb}/scripts/clean-chroot ${arch} ${branch} ${chroot} ${noclean}
exit ${error}