ubuntu and debian templates: Clean up cache if cache build is interrupted

Otherwise the next lxc-create may rsync a bad cache.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Serge Hallyn 2012-08-21 09:56:03 -05:00 committed by Stéphane Graber
parent 4a311c1241
commit f1ccde27c0
3 changed files with 36 additions and 1 deletions

View File

@ -95,6 +95,12 @@ EOF
return 0
}
cleanup()
{
rm -rf $cache/partial-$SUITE-$arch
rm -rf $cache/rootfs-$SUITE-$arch
}
download_debian()
{
packages=\
@ -111,6 +117,7 @@ openssh-server
cache=$1
arch=$2
trap cleanup EXIT SIGHUP SIGINT SIGTERM
# check the mini debian was not already downloaded
mkdir -p "$cache/partial-$SUITE-$arch"
if [ $? -ne 0 ]; then
@ -130,6 +137,10 @@ openssh-server
mv "$1/partial-$SUITE-$arch" "$1/rootfs-$SUITE-$arch"
echo "Download complete."
trap EXIT
trap SIGINT
trap SIGTERM
trap SIGHUP
return 0
}

View File

@ -253,6 +253,11 @@ fi
filename=`basename $url2`
wgetcleanup()
{
rm -f $filename
}
buildcleanup()
{
cd $rootfs
@ -271,7 +276,7 @@ build_root_tgz()
xdir=`mktemp -d -p .`
tarname=`basename $url`
imgname="$release-*-cloudimg-$arch.img"
trap buildcleanup EXIT
trap buildcleanup EXIT SIGHUP SIGINT SIGTERM
if [ $flushcache -eq 1 -o ! -f $cache/$tarname ]; then
rm -f $tarname
echo "Downloading cloud image from $url"
@ -286,6 +291,9 @@ build_root_tgz()
rmdir $xdir
echo "New cloud image cache created"
trap EXIT
trap SIGHUP
trap SIGINT
trap SIGTERM
}
mkdir -p /var/lock/subsys/
@ -298,9 +306,14 @@ mkdir -p /var/lock/subsys/
rm -f $filename
fi
trap wgetcleanup EXIT SIGHUP SIGINT SIGTERM
if [ ! -f $filename ]; then
wget $url2 || build_root_tgz $url1 $filename
fi
trap EXIT
trap SIGHUP
trap SIGINT
trap SIGTERM
echo "Extracting container rootfs"
mkdir -p $rootfs

View File

@ -146,6 +146,12 @@ EOF
fi
}
cleanup()
{
rm -rf $cache/partial-$arch
rm -rf $cache/rootfs-$arch
}
download_ubuntu()
{
cache=$1
@ -155,6 +161,7 @@ download_ubuntu()
packages=vim,ssh
echo "installing packages: $packages"
trap cleanup EXIT SIGHUP SIGINT SIGTERM
# check the mini ubuntu was not already downloaded
mkdir -p "$cache/partial-$arch"
if [ $? -ne 0 ]; then
@ -202,6 +209,10 @@ EOF
fi
mv "$1/partial-$arch" "$1/rootfs-$arch"
trap EXIT
trap SIGINT
trap SIGTERM
trap SIGHUP
echo "Download complete"
return 0
}