Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Anthony Young | 3ee09ec | 2011-10-19 20:35:04 -0700 | [diff] [blame^] | 3 | # Make sure that we have the proper version of ubuntu |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 4 | UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'` |
| 5 | if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then |
Anthony Young | 3ee09ec | 2011-10-19 20:35:04 -0700 | [diff] [blame^] | 6 | if [ ! "natty" = "$UBUNTU_VERSION" ]; then |
| 7 | echo "This script only works with oneiric and natty" |
| 8 | exit 1 |
| 9 | fi |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 10 | fi |
| 11 | |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 12 | # Echo commands |
| 13 | set -o xtrace |
| 14 | |
| 15 | # Keep track of the current directory |
| 16 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 17 | TOP_DIR=$TOOLS_DIR/.. |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 18 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 19 | # Configure the root password of the vm |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 20 | ROOT_PASSWORD=${ROOT_PASSWORD:password} |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 21 | |
| 22 | # Where to store files and instances |
| 23 | KVMSTACK_DIR=${KVMSTACK_DIR:-/opt/kvmstack} |
| 24 | |
| 25 | # Where to store images |
| 26 | IMAGES_DIR=$KVMSTACK_DIR/images |
| 27 | |
| 28 | # Create images dir |
| 29 | mkdir -p $IMAGES_DIR |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 30 | |
| 31 | # Move to top devstack dir |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 32 | cd $TOP_DIR |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 33 | |
| 34 | # Abort if localrc is not set |
| 35 | if [ ! -e ./localrc ]; then |
| 36 | echo "You must have a localrc with ALL necessary passwords defined before proceeding." |
| 37 | echo "See stack.sh for required passwords." |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | # Source params |
| 42 | source ./stackrc |
| 43 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 44 | # Base image (natty by default) |
| 45 | DIST_NAME=${DIST_NAME:-natty} |
| 46 | IMAGE_FNAME=$DIST_NAME.raw |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 47 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 48 | # Original version of built image |
| 49 | BASE_IMAGE=$KVMSTACK_DIR/images/natty.raw |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 50 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 51 | # Copy of base image, which we pre-install with tasty treats |
| 52 | BASE_IMAGE_COPY=$IMAGES_DIR/$DIST_NAME.raw.copy |
| 53 | |
| 54 | # Name of our instance, used by libvirt |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 55 | VM_NAME=${VM_NAME:-kvmstack} |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 56 | |
| 57 | # Mop up after previous runs |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 58 | virsh destroy $VM_NAME |
| 59 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 60 | # Where this vm is stored |
| 61 | VM_DIR=$KVMSTACK_DIR/instances/$VM_NAME |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 62 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 63 | # Create vm dir |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 64 | mkdir -p $VM_DIR |
| 65 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 66 | # Mount point into copied base image |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 67 | COPY_DIR=$VM_DIR/copy |
| 68 | mkdir -p $COPY_DIR |
| 69 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 70 | # Create the base image if it does not yet exist |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 71 | if [ ! -e $IMAGES_DIR/$IMAGE_FNAME ]; then |
| 72 | cd $TOOLS_DIR |
| 73 | ./make_image.sh -m -r 5000 natty raw |
| 74 | mv natty.raw $BASE_IMAGE |
| 75 | cd $TOP_DIR |
| 76 | fi |
| 77 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 78 | # Create a copy of the base image |
| 79 | if [ ! -e $BASE_IMAGE_COPY ]; then |
| 80 | cp -p $BASE_IMAGE $BASE_IMAGE_COPY |
| 81 | fi |
| 82 | |
| 83 | # Unmount the copied base image |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 84 | function unmount_images() { |
| 85 | # unmount the filesystem |
| 86 | while df | grep -q $COPY_DIR; do |
| 87 | umount $COPY_DIR || echo 'ok' |
| 88 | sleep 1 |
| 89 | done |
| 90 | } |
| 91 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 92 | # Unmount from failed runs |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 93 | unmount_images |
| 94 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 95 | # Ctrl-c catcher |
| 96 | function kill_unmount() { |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 97 | unmount_images |
| 98 | exit 1 |
| 99 | } |
| 100 | |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 101 | # Install deps |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 102 | apt-get install -y --force-yes kvm libvirt-bin kpartx |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 103 | |
| 104 | # Let Ctrl-c kill tail and exit |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 105 | trap kill_unmount SIGINT |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 106 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 107 | # Where Openstack code will live in image |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 108 | DEST=${DEST:-/opt/stack} |
| 109 | |
| 110 | # Mount the file system |
| 111 | mount -o loop,offset=32256 $BASE_IMAGE_COPY $COPY_DIR |
| 112 | |
| 113 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 114 | # be owned by the installation user, we create the directory and change the |
| 115 | # ownership to the proper user. |
| 116 | function git_clone { |
| 117 | if [ ! -d $2 ]; then |
| 118 | sudo mkdir $2 |
| 119 | sudo chown `whoami` $2 |
| 120 | git clone $1 $2 |
| 121 | cd $2 |
| 122 | # This checkout syntax works for both branches and tags |
| 123 | git checkout $3 |
| 124 | fi |
| 125 | } |
| 126 | |
| 127 | # Make sure that base requirements are installed |
| 128 | cp /etc/resolv.conf $COPY_DIR/etc/resolv.conf |
| 129 | chroot $COPY_DIR apt-get update |
| 130 | chroot $COPY_DIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
| 131 | chroot $COPY_DIR apt-get install -y --download-only rabbitmq-server libvirt-bin mysql-server |
| 132 | chroot $COPY_DIR pip install `cat files/pips/*` |
| 133 | |
| 134 | # Clean out code repos if directed to do so |
| 135 | if [ "$CLEAN" = "1" ]; then |
| 136 | rm -rf $COPY_DIR/$DEST |
| 137 | fi |
| 138 | |
| 139 | # Cache openstack code |
| 140 | mkdir -p $COPY_DIR/$DEST |
| 141 | git_clone $NOVA_REPO $COPY_DIR/$DEST/nova $NOVA_BRANCH |
| 142 | git_clone $GLANCE_REPO $COPY_DIR/$DEST/glance $GLANCE_BRANCH |
| 143 | git_clone $KEYSTONE_REPO $COPY_DIR/$DESTkeystone $KEYSTONE_BRANCH |
| 144 | git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH |
| 145 | git_clone $DASH_REPO $COPY_DIR/$DEST/dash $DASH_BRANCH $DASH_TAG |
| 146 | git_clone $NOVACLIENT_REPO $COPY_DIR/$DEST/python-novaclient $NOVACLIENT_BRANCH |
| 147 | git_clone $OPENSTACKX_REPO $COPY_DIR/$DEST/openstackx $OPENSTACKX_BRANCH |
| 148 | git_clone $KEYSTONE_REPO $COPY_DIR/$DEST/keystone $KEYSTONE_BRANCH |
| 149 | git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH |
| 150 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 151 | # Back to devstack |
| 152 | cd $TOP_DIR |
| 153 | |
| 154 | # Unmount the filesystems |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 155 | unmount_images |
| 156 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 157 | # Clean up old runs |
| 158 | cd $VM_DIR |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 159 | rm -f $VM_DIR/disk |
| 160 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 161 | # Clean up old instance data |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 162 | qemu-img create -f qcow2 -b $BASE_IMAGE_COPY disk |
| 163 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 164 | # Network configuration variables |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 165 | BRIDGE=${BRIDGE:-br0} |
| 166 | CONTAINER=${CONTAINER:-STACK} |
| 167 | CONTAINER_IP=${CONTAINER_IP:-192.168.1.50} |
| 168 | CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24} |
| 169 | CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0} |
| 170 | CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1} |
| 171 | CONTAINER_MAC=${CONTAINER_MAC:-02:16:3e:07:70:d7} |
| 172 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 173 | # libvirt.xml configuration |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 174 | LIBVIRT_XML=libvirt.xml |
| 175 | cat > $LIBVIRT_XML <<EOF |
| 176 | <domain type='kvm'> |
| 177 | <name>$VM_NAME</name> |
| 178 | <memory>1524288</memory> |
| 179 | <os> |
Anthony Young | d51812d | 2011-10-19 20:09:43 -0700 | [diff] [blame] | 180 | <type>hvm</type> |
| 181 | <bootmenu enable='yes'/> |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 182 | </os> |
| 183 | <features> |
| 184 | <acpi/> |
| 185 | </features> |
| 186 | <vcpu>1</vcpu> |
| 187 | <devices> |
| 188 | <disk type='file'> |
| 189 | <driver type='qcow2'/> |
| 190 | <source file='$VM_DIR/disk'/> |
| 191 | <target dev='vda' bus='virtio'/> |
| 192 | </disk> |
| 193 | |
| 194 | <interface type='bridge'> |
| 195 | <source bridge='$BRIDGE'/> |
| 196 | <mac address='$CONTAINER_MAC'/> |
| 197 | </interface> |
| 198 | |
| 199 | <!-- The order is significant here. File must be defined first --> |
| 200 | <serial type="file"> |
| 201 | <source path='$VM_DIR/console.log'/> |
| 202 | <target port='1'/> |
| 203 | </serial> |
| 204 | |
| 205 | <console type='pty' tty='/dev/pts/2'> |
| 206 | <source path='/dev/pts/2'/> |
| 207 | <target port='0'/> |
| 208 | </console> |
| 209 | |
| 210 | <serial type='pty'> |
| 211 | <source path='/dev/pts/2'/> |
| 212 | <target port='0'/> |
| 213 | </serial> |
| 214 | |
| 215 | <graphics type='vnc' port='-1' autoport='yes' keymap='en-us' listen='0.0.0.0'/> |
| 216 | </devices> |
| 217 | </domain> |
| 218 | EOF |
| 219 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 220 | # Mount point for instance fs |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 221 | ROOTFS=$VM_DIR/root |
| 222 | mkdir -p $ROOTFS |
| 223 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 224 | # Make sure we have nbd-ness |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 225 | modprobe nbd max_part=63 |
| 226 | |
Anthony Young | 9c0fdd7 | 2011-10-19 20:22:32 -0700 | [diff] [blame] | 227 | # Which NBD device to use? |
| 228 | NBD=${NBD:-/dev/nbd5} |
| 229 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 230 | # Clean up from previous runs |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 231 | umount $ROOTFS || echo 'ok' |
Anthony Young | 9c0fdd7 | 2011-10-19 20:22:32 -0700 | [diff] [blame] | 232 | qemu-nbd -d $NBD || echo 'ok' |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 233 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 234 | # Mount the instance |
Anthony Young | 9c0fdd7 | 2011-10-19 20:22:32 -0700 | [diff] [blame] | 235 | qemu-nbd -c $NBD disk |
| 236 | mount $NBD $ROOTFS -o offset=32256 -t ext4 |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 237 | |
| 238 | # Configure instance network |
| 239 | INTERFACES=$ROOTFS/etc/network/interfaces |
| 240 | cat > $INTERFACES <<EOF |
| 241 | auto lo |
| 242 | iface lo inet loopback |
| 243 | |
| 244 | auto eth0 |
| 245 | iface eth0 inet static |
| 246 | address $CONTAINER_IP |
| 247 | netmask $CONTAINER_NETMASK |
| 248 | gateway $CONTAINER_GATEWAY |
| 249 | EOF |
| 250 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 251 | # User configuration for the instance |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 252 | chroot $ROOTFS groupadd libvirtd |
| 253 | chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd |
| 254 | cp -pr $TOOLS_DIR/.. $ROOTFS/$DEST/devstack |
| 255 | echo "root:$ROOT_PASSWORD" | chroot $ROOTFS chpasswd |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 256 | echo "stack:pass" | chroot $ROOTFS chpasswd |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 257 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers |
| 258 | |
| 259 | # Gracefully cp only if source file/dir exists |
| 260 | function cp_it { |
| 261 | if [ -e $1 ] || [ -d $1 ]; then |
| 262 | cp -pRL $1 $2 |
| 263 | fi |
| 264 | } |
| 265 | |
| 266 | # Copy over your ssh keys and env if desired |
| 267 | COPYENV=${COPYENV:-1} |
| 268 | if [ "$COPYENV" = "1" ]; then |
| 269 | cp_it ~/.ssh $ROOTFS/$DEST/.ssh |
| 270 | cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys |
| 271 | cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig |
| 272 | cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc |
| 273 | cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc |
| 274 | fi |
| 275 | |
| 276 | # Configure the runner |
| 277 | RUN_SH=$ROOTFS/$DEST/run.sh |
| 278 | cat > $RUN_SH <<EOF |
| 279 | #!/usr/bin/env bash |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 280 | |
| 281 | # Kill any existing screens |
| 282 | killall screen |
| 283 | |
| 284 | # Install and run stack.sh |
| 285 | sudo apt-get update |
| 286 | sudo apt-get -y --force-yes install git-core vim-nox sudo |
| 287 | if [ ! -d "$DEST/devstack" ]; then |
| 288 | git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack |
| 289 | fi |
| 290 | cd $DEST/devstack && $STACKSH_PARAMS FORCE=yes ./stack.sh > /$DEST/run.sh.log |
| 291 | echo >> /$DEST/run.sh.log |
| 292 | echo >> /$DEST/run.sh.log |
| 293 | echo "All done! Time to start clicking." >> /$DEST/run.sh.log |
Anthony Young | d51812d | 2011-10-19 20:09:43 -0700 | [diff] [blame] | 294 | cat $DEST/run.sh.log |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 295 | EOF |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 296 | chmod 755 $RUN_SH |
| 297 | |
| 298 | # Make runner launch on boot |
| 299 | RC_LOCAL=$ROOTFS/etc/init.d/local |
| 300 | cat > $RC_LOCAL <<EOF |
| 301 | #!/bin/sh -e |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 302 | # Reboot if this is our first run to enable console log on natty :( |
| 303 | if [ ! -e /root/firstlaunch ]; then |
| 304 | touch /root/firstlaunch |
Anthony Young | d51812d | 2011-10-19 20:09:43 -0700 | [diff] [blame] | 305 | reboot -f |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 306 | exit 0 |
| 307 | fi |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 308 | su -c "$DEST/run.sh" stack |
| 309 | EOF |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 310 | chmod +x $RC_LOCAL |
| 311 | chroot $ROOTFS sudo update-rc.d local defaults 80 |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 312 | |
| 313 | # Make our ip address hostnames look nice at the command prompt |
| 314 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc |
| 315 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile |
| 316 | |
| 317 | # Give stack ownership over $DEST so it may do the work needed |
| 318 | chroot $ROOTFS chown -R stack $DEST |
| 319 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 320 | # Change boot params so that we get a console log |
Anthony Young | f6f5227 | 2011-10-19 02:58:18 -0700 | [diff] [blame] | 321 | sudo sed -e "s/quiet splash/splash console=ttyS0 console=ttyS1,19200n8/g" -i $ROOTFS/boot/grub/menu.lst |
Anthony Young | d51812d | 2011-10-19 20:09:43 -0700 | [diff] [blame] | 322 | sudo sed -e "s/^hiddenmenu//g" -i $ROOTFS/boot/grub/menu.lst |
| 323 | #chroot $ROOTFS grub-install /dev/vda |
Anthony Young | f6f5227 | 2011-10-19 02:58:18 -0700 | [diff] [blame] | 324 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 325 | # Unmount |
| 326 | umount $ROOTFS || echo 'ok' |
Anthony Young | 9c0fdd7 | 2011-10-19 20:22:32 -0700 | [diff] [blame] | 327 | qemu-nbd -d $NBD |
Anthony Young | 1b7a42e | 2011-10-19 02:34:06 -0700 | [diff] [blame] | 328 | |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 329 | # Create the instance |
| 330 | cd $VM_DIR && virsh create libvirt.xml |
| 331 | |
| 332 | # Tail the console log till we are done |
Anthony Young | d51812d | 2011-10-19 20:09:43 -0700 | [diff] [blame] | 333 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 334 | if [ "$WAIT_TILL_LAUNCH" = "1" ]; then |
| 335 | # Done creating the container, let's tail the log |
| 336 | echo |
| 337 | echo "=============================================================" |
| 338 | echo " -- YAY! --" |
| 339 | echo "=============================================================" |
| 340 | echo |
| 341 | echo "We're done launching the vm, about to start tailing the" |
| 342 | echo "stack.sh log. It will take a second or two to start." |
| 343 | echo |
| 344 | echo "Just CTRL-C at any time to stop tailing." |
| 345 | |
| 346 | while [ ! -e "$VM_DIR/console.log" ]; do |
| 347 | sleep 1 |
| 348 | done |
| 349 | |
| 350 | tail -F $VM_DIR/console.log & |
| 351 | |
| 352 | TAIL_PID=$! |
| 353 | |
| 354 | function kill_tail() { |
| 355 | kill $TAIL_PID |
| 356 | exit 1 |
| 357 | } |
| 358 | |
| 359 | # Let Ctrl-c kill tail and exit |
| 360 | trap kill_tail SIGINT |
| 361 | |
| 362 | echo "Waiting stack.sh to finish..." |
Anthony Young | d51812d | 2011-10-19 20:09:43 -0700 | [diff] [blame] | 363 | while ! cat $VM_DIR/console.log | grep -q 'All done' ; do |
Anthony Young | fa4b5eb | 2011-10-19 11:27:02 -0700 | [diff] [blame] | 364 | sleep 5 |
| 365 | done |
| 366 | |
| 367 | kill $TAIL_PID |
| 368 | echo "" |
| 369 | echo "Finished - Zip-a-dee Doo-dah!" |
| 370 | fi |