diff --git a/templates/lxc-debian.in b/templates/lxc-debian.in index 68404e31f..9f200f1c8 100644 --- a/templates/lxc-debian.in +++ b/templates/lxc-debian.in @@ -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 } diff --git a/templates/lxc-ubuntu-cloud.in b/templates/lxc-ubuntu-cloud.in index 8cd3410eb..8bd2b1b73 100644 --- a/templates/lxc-ubuntu-cloud.in +++ b/templates/lxc-ubuntu-cloud.in @@ -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 diff --git a/templates/lxc-ubuntu.in b/templates/lxc-ubuntu.in index a0337c5bd..9a4447d3d 100644 --- a/templates/lxc-ubuntu.in +++ b/templates/lxc-ubuntu.in @@ -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 }