Merge pull request #91 from cloudbuilders/dt-build_kvm

Fix concurrent build_kvm.sh runs
This commit is contained in:
Jesse Andrews 2011-10-21 13:02:01 -07:00
commit f299dee29e

View file

@ -45,15 +45,15 @@ source ./stackrc
DIST_NAME=${DIST_NAME:-natty} DIST_NAME=${DIST_NAME:-natty}
IMAGE_FNAME=$DIST_NAME.raw IMAGE_FNAME=$DIST_NAME.raw
# Original version of built image
BASE_IMAGE=$KVMSTACK_DIR/images/natty.raw
# Copy of base image, which we pre-install with tasty treats
BASE_IMAGE_COPY=$IMAGES_DIR/$DIST_NAME.raw.copy
# Name of our instance, used by libvirt # Name of our instance, used by libvirt
CONTAINER_NAME=${CONTAINER_NAME:-kvmstack} CONTAINER_NAME=${CONTAINER_NAME:-kvmstack}
# Original version of built image
BASE_IMAGE=$KVMSTACK_DIR/images/$DIST_NAME.raw
# Copy of base image, which we pre-install with tasty treats
VM_IMAGE=$IMAGES_DIR/$DIST_NAME.$CONTAINER_NAME.raw
# Mop up after previous runs # Mop up after previous runs
virsh destroy $CONTAINER_NAME virsh destroy $CONTAINER_NAME
@ -70,14 +70,14 @@ mkdir -p $COPY_DIR
# Create the base image if it does not yet exist # Create the base image if it does not yet exist
if [ ! -e $IMAGES_DIR/$IMAGE_FNAME ]; then if [ ! -e $IMAGES_DIR/$IMAGE_FNAME ]; then
cd $TOOLS_DIR cd $TOOLS_DIR
./make_image.sh -m -r 5000 natty raw ./make_image.sh -m -r 5000 $DIST_NAME raw
mv natty.raw $BASE_IMAGE mv $DIST_NAME.raw $BASE_IMAGE
cd $TOP_DIR cd $TOP_DIR
fi fi
# Create a copy of the base image # Create a copy of the base image
if [ ! -e $BASE_IMAGE_COPY ]; then if [ ! -e $VM_IMAGE ]; then
cp -p $BASE_IMAGE $BASE_IMAGE_COPY cp -p $BASE_IMAGE $VM_IMAGE
fi fi
# Unmount the copied base image # Unmount the copied base image
@ -108,7 +108,7 @@ trap kill_unmount SIGINT
DEST=${DEST:-/opt/stack} DEST=${DEST:-/opt/stack}
# Mount the file system # Mount the file system
mount -o loop,offset=32256 $BASE_IMAGE_COPY $COPY_DIR mount -o loop,offset=32256 $VM_IMAGE $COPY_DIR
# git clone only if directory doesn't exist already. Since ``DEST`` might not # git clone only if directory doesn't exist already. Since ``DEST`` might not
# be owned by the installation user, we create the directory and change the # be owned by the installation user, we create the directory and change the
@ -231,7 +231,7 @@ cd $VM_DIR
rm -f $VM_DIR/disk rm -f $VM_DIR/disk
# Create our instance fs # Create our instance fs
qemu-img create -f qcow2 -b $BASE_IMAGE_COPY disk qemu-img create -f qcow2 -b $VM_IMAGE disk
sleep 5 sleep 5
@ -306,7 +306,7 @@ chmod 755 $RUN_SH
RC_LOCAL=$ROOTFS/etc/init.d/local RC_LOCAL=$ROOTFS/etc/init.d/local
cat > $RC_LOCAL <<EOF cat > $RC_LOCAL <<EOF
#!/bin/sh -e #!/bin/sh -e
# Reboot if this is our first run to enable console log on natty :( # Reboot if this is our first run to enable console log on $DIST_NAME :(
if [ ! -e /root/firstlaunch ]; then if [ ! -e /root/firstlaunch ]; then
touch /root/firstlaunch touch /root/firstlaunch
reboot -f reboot -f