Run on_exit commands in FILO order

This commit is contained in:
Reto Buerki
2013-01-17 16:54:54 +01:00
committed by Tobias Brunner
parent 97265abaf0
commit 74c0839ad6
4 changed files with 11 additions and 11 deletions
+2 -3
View File
@@ -30,6 +30,7 @@ execute "qemu-img create -f qcow2 $ROOTFS ${ROOTFSSIZE}M"
log_action "Connecting image to NBD device $NBDEV" log_action "Connecting image to NBD device $NBDEV"
execute "qemu-nbd -c $NBDEV $ROOTFS" execute "qemu-nbd -c $NBDEV $ROOTFS"
do_on_exit qemu-nbd -d $NBDEV
log_action "Partitioning disk" log_action "Partitioning disk"
sfdisk /dev/nbd0 -D -uM >>$LOGFILE 2>&1 << EOF sfdisk /dev/nbd0 -D -uM >>$LOGFILE 2>&1 << EOF
@@ -49,14 +50,12 @@ execute "mkfs.ext3 $NBDPARTITION"
log_action "Mounting $NBDPARTITION to $LOOPDIR" log_action "Mounting $NBDPARTITION to $LOOPDIR"
execute "mount $NBDPARTITION $LOOPDIR" execute "mount $NBDPARTITION $LOOPDIR"
do_on_exit graceful_umount $LOOPDIR
log_action "Using $CACHEDIR as archive for apt" log_action "Using $CACHEDIR as archive for apt"
mkdir -p $APTCACHE mkdir -p $APTCACHE
execute "mount -o bind $CACHEDIR $APTCACHE" execute "mount -o bind $CACHEDIR $APTCACHE"
do_on_exit graceful_umount $APTCACHE do_on_exit graceful_umount $APTCACHE
do_on_exit graceful_umount $LOOPDIR
do_on_exit qemu-nbd -d $NBDEV
log_action "Running debootstrap ($ROOTFSSUITE, $ROOTFSARCH)" log_action "Running debootstrap ($ROOTFSSUITE, $ROOTFSARCH)"
execute "debootstrap --arch=$ROOTFSARCH --include=$PACKAGES $ROOTFSSUITE $LOOPDIR $ROOTFSMIRROR" execute "debootstrap --arch=$ROOTFSARCH --include=$PACKAGES $ROOTFSSUITE $LOOPDIR $ROOTFSMIRROR"
+1
View File
@@ -40,6 +40,7 @@ else
fi fi
# just to be sure # just to be sure
do_on_exit qemu-nbd -d $NBDEV
do_on_exit umount $LOOPDIR do_on_exit umount $LOOPDIR
for host in $HOSTS for host in $HOSTS
+3 -4
View File
@@ -37,22 +37,21 @@ execute "cp $ROOTFS $BASE"
log_action "Connecting base image to NBD device $NBDEV" log_action "Connecting base image to NBD device $NBDEV"
execute "qemu-nbd -c $NBDEV $BASE" execute "qemu-nbd -c $NBDEV $BASE"
do_on_exit qemu-nbd -d $NBDEV
partprobe $NBDEV partprobe $NBDEV
log_action "Mounting $NBDPARTITION to $LOOPDIR" log_action "Mounting $NBDPARTITION to $LOOPDIR"
execute "mount $NBDPARTITION $LOOPDIR" execute "mount $NBDPARTITION $LOOPDIR"
do_on_exit umount $LOOPDIR
log_action "Mounting proc filesystem to $LOOPDIR/proc" log_action "Mounting proc filesystem to $LOOPDIR/proc"
execute "mount -t proc none $LOOPDIR/proc" execute "mount -t proc none $LOOPDIR/proc"
do_on_exit umount $LOOPDIR/proc
mkdir -p $LOOPDIR/root/compile mkdir -p $LOOPDIR/root/compile
log_action "Mounting $ROOTFSCOMPILEDIR as /root/compile" log_action "Mounting $ROOTFSCOMPILEDIR as /root/compile"
execute "mount -o bind $ROOTFSCOMPILEDIR $LOOPDIR/root/compile" execute "mount -o bind $ROOTFSCOMPILEDIR $LOOPDIR/root/compile"
do_on_exit umount $LOOPDIR/root/compile do_on_exit umount $LOOPDIR/root/compile
do_on_exit umount $LOOPDIR/proc
do_on_exit umount $LOOPDIR
do_on_exit qemu-nbd -d $NBDEV
echo "Installing software from source" echo "Installing software from source"
RECPDIR=$TESTDIR/testing/scripts/recipes RECPDIR=$TESTDIR/testing/scripts/recipes
+5 -4
View File
@@ -97,16 +97,17 @@ declare -a on_exit_items
# perform registered actions on exit # perform registered actions on exit
on_exit() on_exit()
{ {
for i in "${on_exit_items[@]}" for ((onex=${#on_exit_items[@]}-1; onex>=0; onex--))
do do
eval $i >>$LOGFILE 2>&1 echo "On_Exit: ${on_exit_items[$onex]}" >>$LOGFILE
${on_exit_items[$onex]} >>$LOGFILE 2>&1
done done
on_exit_items="" on_exit_items=""
trap - EXIT trap - EXIT
} }
# register a command to execute when the calling script terminates. The # register a command to execute when the calling script terminates. The
# registered commands are called in FIFO order. # registered commands are called in FILO order.
# $* - command to register # $* - command to register
do_on_exit() do_on_exit()
{ {
@@ -126,7 +127,7 @@ graceful_umount()
[ ! $secs ] && secs=5 [ ! $secs ] && secs=5
let steps=$secs*100 let steps=$secs*100
for i in `seq 1 $steps` for st in `seq 1 $steps`
do do
umount $1 >>$LOGFILE 2>&1 umount $1 >>$LOGFILE 2>&1
mount | grep $1 >/dev/null 2>&1 mount | grep $1 >/dev/null 2>&1