[Qa-jenkins-scm] [jenkins.debian.net] 03/04: make 'apt-get install' more robust against network failures

Holger Levsen holger at moszumanska.debian.org
Wed Sep 9 06:51:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch master
in repository jenkins.debian.net.

commit a28f0c2826bc37feea328666c469cd63eb98736b
Author: Holger Levsen <holger at layer-acht.org>
Date:   Wed Sep 9 08:48:36 2015 +0200

    make 'apt-get install' more robust against network failures
---
 bin/schroot-create.sh | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/bin/schroot-create.sh b/bin/schroot-create.sh
index 8e902cd..93648e3 100755
--- a/bin/schroot-create.sh
+++ b/bin/schroot-create.sh
@@ -110,6 +110,20 @@ robust_chroot_apt_update() {
 	rm -f $TMPLOG
 }
 
+robust_chroot_apt_install() {
+	set +e
+	sudo chroot $CHROOT_TARGET apt-get install $@ | tee $TMPLOG
+	RESULT=$(egrep 'Failed to fetch.*(Unable to connect to|Connection failed|Size mismatch|Cannot initiate the connection to|Bad Gateway)' $TMPLOG)
+	set -e
+	if [ -z "$RESULT" ] ; then
+		echo "$(date -u) - apt-get install failed, sleeping 5min before retrying..."
+		sleep 5m
+		sudo chroot $CHROOT_TARGET apt-get install $@
+	fi
+	rm -f $TMPLOG
+}
+
+
 bootstrap() {
 	mkdir -p "$CHROOT_TARGET/etc/dpkg/dpkg.cfg.d"
 	echo force-unsafe-io > "$CHROOT_TARGET/etc/dpkg/dpkg.cfg.d/02dpkg-unsafe-io"
@@ -152,12 +166,12 @@ bootstrap() {
 		done
 		set -x
 		robust_chroot_apt_update
-		# install diffoscope with all recommends...
+		# first, (if), install diffoscope with all recommends...
 		if [ "$1" = "diffoscope" ] ; then
-			sudo chroot $CHROOT_TARGET apt-get install -y --install-recommends diffoscope
+			robust_chroot_apt_install -y --install-recommends diffoscope
 		fi
-		sudo chroot $CHROOT_TARGET apt-get install -y --no-install-recommends "$@"
-		# always use diffoscope from unstable
+		robust_chroot_apt_install -y --no-install-recommends "$@"
+		# always try to use diffoscope from unstable
 		if [ "$SUITE" = "testing" ] && [ "$1" = "diffoscope" ] ; then
 			echo "deb $MIRROR unstable main"        | sudo tee -a $CHROOT_TARGET/etc/apt/sources.list > /dev/null
 			robust_chroot_apt_update

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/qa/jenkins.debian.net.git



More information about the Qa-jenkins-scm mailing list