Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # exit on error to stop unexpected errors |
| 4 | set -o errexit |
| 5 | |
| 6 | # Make sure that we have the proper version of ubuntu |
| 7 | UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'` |
| 8 | if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then |
| 9 | if [ ! "natty" = "$UBUNTU_VERSION" ]; then |
| 10 | echo "This script only works with oneiric and natty" |
| 11 | exit 1 |
| 12 | fi |
| 13 | fi |
| 14 | |
Dean Troyer | 55c0273 | 2011-11-01 17:44:03 -0500 | [diff] [blame] | 15 | # Clean up any resources that may be in use |
| 16 | cleanup() { |
| 17 | set +o errexit |
| 18 | unmount_images |
| 19 | |
| 20 | if [ -n "$ROOTFS" ]; then |
| 21 | umount $ROOTFS/dev |
| 22 | umount $ROOTFS |
| 23 | fi |
| 24 | |
| 25 | # Release NBD devices |
| 26 | if [ -n "$NBD" ]; then |
| 27 | qemu-nbd -d $NBD |
| 28 | fi |
| 29 | |
| 30 | # Kill ourselves to signal any calling process |
| 31 | trap 2; kill -2 $$ |
| 32 | } |
| 33 | |
| 34 | trap cleanup SIGHUP SIGINT SIGTERM |
| 35 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 36 | # Echo commands |
| 37 | set -o xtrace |
| 38 | |
| 39 | # Keep track of the current directory |
| 40 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
Jesse Andrews | 3198974 | 2011-10-30 18:56:05 -0700 | [diff] [blame] | 41 | TOP_DIR=`cd $TOOLS_DIR/..; pwd` |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 42 | |
| 43 | # Where to store files and instances |
Jesse Andrews | b0559b2 | 2011-10-30 19:46:54 -0700 | [diff] [blame] | 44 | WORK_DIR=${WORK_DIR:-/opt/kvmstack} |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 45 | |
| 46 | # Where to store images |
| 47 | IMAGES_DIR=$WORK_DIR/images |
| 48 | |
| 49 | # Create images dir |
| 50 | mkdir -p $IMAGES_DIR |
| 51 | |
| 52 | # Abort if localrc is not set |
| 53 | if [ ! -e $TOP_DIR/localrc ]; then |
| 54 | echo "You must have a localrc with ALL necessary passwords defined before proceeding." |
| 55 | echo "See stack.sh for required passwords." |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
Jesse Andrews | 7fa5613 | 2011-10-30 18:43:54 -0700 | [diff] [blame] | 59 | cd $TOP_DIR |
| 60 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 61 | # Source params |
| 62 | source ./stackrc |
| 63 | |
| 64 | # Configure the root password of the vm to be the same as ``ADMIN_PASSWORD`` |
| 65 | ROOT_PASSWORD=${ADMIN_PASSWORD:-password} |
| 66 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 67 | # Base image (natty by default) |
| 68 | DIST_NAME=${DIST_NAME:-natty} |
| 69 | IMAGE_FNAME=$DIST_NAME.raw |
| 70 | |
| 71 | # Name of our instance, used by libvirt |
| 72 | GUEST_NAME=${GUEST_NAME:-devstack} |
| 73 | |
| 74 | # Original version of built image |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 75 | BASE_IMAGE=$IMAGES_DIR/$DIST_NAME.raw |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 76 | |
| 77 | # Copy of base image, which we pre-install with tasty treats |
| 78 | VM_IMAGE=$IMAGES_DIR/$DIST_NAME.$GUEST_NAME.raw |
| 79 | |
| 80 | # Mop up after previous runs |
| 81 | virsh destroy $GUEST_NAME || true |
| 82 | |
| 83 | # Where this vm is stored |
| 84 | VM_DIR=$WORK_DIR/instances/$GUEST_NAME |
| 85 | |
| 86 | # Create vm dir |
| 87 | mkdir -p $VM_DIR |
| 88 | |
| 89 | # Mount point into copied base image |
| 90 | COPY_DIR=$VM_DIR/copy |
| 91 | mkdir -p $COPY_DIR |
| 92 | |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 93 | # Get the base image if it does not yet exist |
| 94 | if [ ! -e $BASE_IMAGE ]; then |
| 95 | $TOOLS_DIR/get_uec_image.sh -f raw -r 5000 $DIST_NAME $BASE_IMAGE |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 96 | fi |
| 97 | |
| 98 | # Create a copy of the base image |
| 99 | if [ ! -e $VM_IMAGE ]; then |
| 100 | cp -p $BASE_IMAGE $VM_IMAGE |
| 101 | fi |
| 102 | |
| 103 | # Unmount the copied base image |
| 104 | function unmount_images() { |
| 105 | # unmount the filesystem |
| 106 | while df | grep -q $COPY_DIR; do |
| 107 | umount $COPY_DIR || echo 'ok' |
| 108 | sleep 1 |
| 109 | done |
| 110 | } |
| 111 | |
| 112 | # Unmount from failed runs |
| 113 | unmount_images |
| 114 | |
| 115 | # Ctrl-c catcher |
| 116 | function kill_unmount() { |
| 117 | unmount_images |
| 118 | exit 1 |
| 119 | } |
| 120 | |
| 121 | # Install deps if needed |
| 122 | dpkg -l kvm libvirt-bin kpartx || apt-get install -y --force-yes kvm libvirt-bin kpartx |
| 123 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 124 | # Where Openstack code will live in image |
| 125 | DEST=${DEST:-/opt/stack} |
| 126 | |
| 127 | # Mount the file system |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 128 | # For some reason, UEC-based images want 255 heads * 63 sectors * 512 byte sectors = 8225280 |
| 129 | mount -t ext4 -o loop,offset=8225280 $VM_IMAGE $COPY_DIR |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 130 | |
| 131 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 132 | # be owned by the installation user, we create the directory and change the |
| 133 | # ownership to the proper user. |
| 134 | function git_clone { |
| 135 | if [ ! -d $2 ]; then |
| 136 | sudo mkdir $2 |
| 137 | sudo chown `whoami` $2 |
| 138 | git clone $1 $2 |
| 139 | cd $2 |
| 140 | # This checkout syntax works for both branches and tags |
| 141 | git checkout $3 |
| 142 | fi |
| 143 | } |
| 144 | |
| 145 | # Make sure that base requirements are installed |
| 146 | cp /etc/resolv.conf $COPY_DIR/etc/resolv.conf |
| 147 | chroot $COPY_DIR apt-get update |
| 148 | chroot $COPY_DIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
| 149 | chroot $COPY_DIR apt-get install -y --download-only rabbitmq-server libvirt-bin mysql-server |
| 150 | chroot $COPY_DIR pip install `cat files/pips/*` |
| 151 | |
| 152 | # Clean out code repos if directed to do so |
| 153 | if [ "$CLEAN" = "1" ]; then |
| 154 | rm -rf $COPY_DIR/$DEST |
| 155 | fi |
| 156 | |
| 157 | # Cache openstack code |
| 158 | mkdir -p $COPY_DIR/$DEST |
| 159 | git_clone $NOVA_REPO $COPY_DIR/$DEST/nova $NOVA_BRANCH |
| 160 | git_clone $GLANCE_REPO $COPY_DIR/$DEST/glance $GLANCE_BRANCH |
| 161 | git_clone $KEYSTONE_REPO $COPY_DIR/$DESTkeystone $KEYSTONE_BRANCH |
| 162 | git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH |
| 163 | git_clone $HORIZON_REPO $COPY_DIR/$DEST/horizon $HORIZON_BRANCH $HORIZON_TAG |
| 164 | git_clone $NOVACLIENT_REPO $COPY_DIR/$DEST/python-novaclient $NOVACLIENT_BRANCH |
| 165 | git_clone $OPENSTACKX_REPO $COPY_DIR/$DEST/openstackx $OPENSTACKX_BRANCH |
| 166 | git_clone $KEYSTONE_REPO $COPY_DIR/$DEST/keystone $KEYSTONE_BRANCH |
| 167 | git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH |
| 168 | |
| 169 | # Back to devstack |
| 170 | cd $TOP_DIR |
| 171 | |
| 172 | # Unmount the filesystems |
| 173 | unmount_images |
| 174 | |
| 175 | # Network configuration variables |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 176 | GUEST_NETWORK=${GUEST_NETWORK:-1} |
Jesse Andrews | 1d1dda1 | 2011-11-01 19:46:17 -0700 | [diff] [blame] | 177 | GUEST_RECREATE_NET=${GUEST_RECREATE_NET:-yes} |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 178 | |
| 179 | GUEST_IP=${GUEST_IP:-192.168.$GUEST_NETWORK.50} |
| 180 | GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24} |
| 181 | GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0} |
| 182 | GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.$GUEST_NETWORK.1} |
| 183 | GUEST_MAC=${GUEST_MAC:-"02:16:3e:07:69:`printf '%02X' $GUEST_NETWORK`"} |
| 184 | GUEST_RAM=${GUEST_RAM:-1524288} |
| 185 | GUEST_CORES=${GUEST_CORES:-1} |
| 186 | |
| 187 | # libvirt.xml configuration |
| 188 | NET_XML=$VM_DIR/net.xml |
| 189 | cat > $NET_XML <<EOF |
| 190 | <network> |
| 191 | <name>devstack-$GUEST_NETWORK</name> |
| 192 | <bridge name="stackbr%d" /> |
| 193 | <forward/> |
| 194 | <ip address="$GUEST_GATEWAY" netmask="$GUEST_NETMASK" /> |
| 195 | </network> |
| 196 | EOF |
| 197 | |
Jesse Andrews | 1d1dda1 | 2011-11-01 19:46:17 -0700 | [diff] [blame] | 198 | if [[ "$GUEST_RECREATE_NET" == "yes" ]]; then |
| 199 | virsh net-destroy devstack-$GUEST_NETWORK || true |
| 200 | virsh net-create $VM_DIR/net.xml |
| 201 | fi |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 202 | |
| 203 | # libvirt.xml configuration |
| 204 | LIBVIRT_XML=$VM_DIR/libvirt.xml |
| 205 | cat > $LIBVIRT_XML <<EOF |
| 206 | <domain type='kvm'> |
| 207 | <name>$GUEST_NAME</name> |
| 208 | <memory>$GUEST_RAM</memory> |
| 209 | <os> |
| 210 | <type>hvm</type> |
| 211 | <bootmenu enable='yes'/> |
| 212 | </os> |
| 213 | <features> |
| 214 | <acpi/> |
| 215 | </features> |
| 216 | <vcpu>$GUEST_CORES</vcpu> |
| 217 | <devices> |
| 218 | <disk type='file'> |
| 219 | <driver type='qcow2'/> |
| 220 | <source file='$VM_DIR/disk'/> |
| 221 | <target dev='vda' bus='virtio'/> |
| 222 | </disk> |
| 223 | |
| 224 | <interface type='network'> |
| 225 | <source network='devstack-$GUEST_NETWORK'/> |
| 226 | </interface> |
| 227 | |
| 228 | <!-- The order is significant here. File must be defined first --> |
| 229 | <serial type="file"> |
| 230 | <source path='$VM_DIR/console.log'/> |
| 231 | <target port='1'/> |
| 232 | </serial> |
| 233 | |
| 234 | <console type='pty' tty='/dev/pts/2'> |
| 235 | <source path='/dev/pts/2'/> |
| 236 | <target port='0'/> |
| 237 | </console> |
| 238 | |
| 239 | <serial type='pty'> |
| 240 | <source path='/dev/pts/2'/> |
| 241 | <target port='0'/> |
| 242 | </serial> |
| 243 | |
| 244 | <graphics type='vnc' port='-1' autoport='yes' keymap='en-us' listen='0.0.0.0'/> |
| 245 | </devices> |
| 246 | </domain> |
| 247 | EOF |
| 248 | |
| 249 | # Mount point for instance fs |
| 250 | ROOTFS=$VM_DIR/root |
| 251 | mkdir -p $ROOTFS |
| 252 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 253 | # Clean up from previous runs |
| 254 | umount $ROOTFS || echo 'ok' |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 255 | |
| 256 | # Clean up old runs |
| 257 | cd $VM_DIR |
| 258 | rm -f $VM_DIR/disk |
| 259 | |
| 260 | # Create our instance fs |
| 261 | qemu-img create -f qcow2 -b $VM_IMAGE disk |
| 262 | |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 263 | # Finds the next available NBD device |
| 264 | # Exits script if error connecting or none free |
| 265 | # map_nbd image |
| 266 | # returns full nbd device path |
| 267 | function map_nbd { |
| 268 | for i in `seq 0 15`; do |
| 269 | if [ ! -e /sys/block/nbd$i/pid ]; then |
| 270 | NBD=/dev/nbd$i |
| 271 | # Connect to nbd and wait till it is ready |
| 272 | qemu-nbd -c $NBD $1 |
| 273 | if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then |
| 274 | echo "Couldn't connect $NBD" |
| 275 | exit 1 |
| 276 | fi |
| 277 | break |
| 278 | fi |
| 279 | done |
| 280 | if [ -z "$NBD" ]; then |
| 281 | echo "No free NBD slots" |
| 282 | exit 1 |
| 283 | fi |
| 284 | echo $NBD |
| 285 | } |
| 286 | |
Dean Troyer | 7a56973 | 2011-10-31 17:34:29 -0500 | [diff] [blame] | 287 | # Make sure we have nbd-ness |
| 288 | modprobe nbd max_part=63 |
| 289 | |
| 290 | # Set up nbd |
Dean Troyer | dccd6b9 | 2011-11-01 15:46:14 -0500 | [diff] [blame] | 291 | NBD=`map_nbd disk` |
Dean Troyer | 7a56973 | 2011-10-31 17:34:29 -0500 | [diff] [blame] | 292 | NBD_DEV=`basename $NBD` |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 293 | |
| 294 | # Mount the instance |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 295 | mount ${NBD}p1 $ROOTFS |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 296 | |
| 297 | # Configure instance network |
| 298 | INTERFACES=$ROOTFS/etc/network/interfaces |
| 299 | cat > $INTERFACES <<EOF |
| 300 | auto lo |
| 301 | iface lo inet loopback |
| 302 | |
| 303 | auto eth0 |
| 304 | iface eth0 inet static |
| 305 | address $GUEST_IP |
| 306 | netmask $GUEST_NETMASK |
| 307 | gateway $GUEST_GATEWAY |
| 308 | EOF |
| 309 | |
| 310 | # User configuration for the instance |
| 311 | chroot $ROOTFS groupadd libvirtd || true |
| 312 | chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd |
Jesse Andrews | 5f894cd | 2011-10-30 19:52:50 -0700 | [diff] [blame] | 313 | cp -pr $TOP_DIR $ROOTFS/$DEST/devstack |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 314 | echo "root:$ROOT_PASSWORD" | chroot $ROOTFS chpasswd |
| 315 | echo "stack:pass" | chroot $ROOTFS chpasswd |
| 316 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers |
| 317 | |
| 318 | # Gracefully cp only if source file/dir exists |
| 319 | function cp_it { |
| 320 | if [ -e $1 ] || [ -d $1 ]; then |
| 321 | cp -pRL $1 $2 |
| 322 | fi |
| 323 | } |
| 324 | |
| 325 | # Copy over your ssh keys and env if desired |
| 326 | COPYENV=${COPYENV:-1} |
| 327 | if [ "$COPYENV" = "1" ]; then |
| 328 | cp_it ~/.ssh $ROOTFS/$DEST/.ssh |
| 329 | cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys |
| 330 | cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig |
| 331 | cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc |
| 332 | cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc |
| 333 | fi |
| 334 | |
| 335 | # pre-cache uec images |
| 336 | for image_url in ${IMAGE_URLS//,/ }; do |
| 337 | IMAGE_FNAME=`basename "$image_url"` |
| 338 | if [ ! -f $IMAGES_DIR/$IMAGE_FNAME ]; then |
| 339 | wget -c $image_url -O $IMAGES_DIR/$IMAGE_FNAME |
| 340 | fi |
| 341 | cp $IMAGES_DIR/$IMAGE_FNAME $ROOTFS/$DEST/devstack/files |
| 342 | done |
| 343 | |
| 344 | # Configure the runner |
| 345 | RUN_SH=$ROOTFS/$DEST/run.sh |
| 346 | cat > $RUN_SH <<EOF |
| 347 | #!/usr/bin/env bash |
| 348 | |
| 349 | # Kill any existing screens |
| 350 | killall screen |
| 351 | |
| 352 | # Install and run stack.sh |
| 353 | sudo apt-get update |
| 354 | sudo apt-get -y --force-yes install git-core vim-nox sudo |
| 355 | if [ ! -d "$DEST/devstack" ]; then |
| 356 | git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack |
| 357 | fi |
| 358 | cd $DEST/devstack && $STACKSH_PARAMS FORCE=yes ./stack.sh > /$DEST/run.sh.log |
| 359 | echo >> /$DEST/run.sh.log |
| 360 | echo >> /$DEST/run.sh.log |
| 361 | echo "All done! Time to start clicking." >> /$DEST/run.sh.log |
| 362 | cat $DEST/run.sh.log |
| 363 | EOF |
| 364 | chmod 755 $RUN_SH |
| 365 | |
| 366 | # Make runner launch on boot |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 367 | RC_LOCAL=$ROOTFS/etc/init.d/zlocal |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 368 | cat > $RC_LOCAL <<EOF |
| 369 | #!/bin/sh -e |
Jesse Andrews | ddcc36d | 2011-10-30 22:41:23 -0700 | [diff] [blame] | 370 | # cloud-init overwrites the hostname with ubuntuhost |
| 371 | echo $GUEST_NAME > /etc/hostname |
| 372 | hostname $GUEST_NAME |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 373 | su -c "$DEST/run.sh" stack |
| 374 | EOF |
| 375 | chmod +x $RC_LOCAL |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 376 | chroot $ROOTFS sudo update-rc.d zlocal defaults 99 |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 377 | |
| 378 | # Make our ip address hostnames look nice at the command prompt |
| 379 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc |
| 380 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile |
| 381 | |
| 382 | # Give stack ownership over $DEST so it may do the work needed |
| 383 | chroot $ROOTFS chown -R stack $DEST |
| 384 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 385 | # Set the hostname |
| 386 | echo $GUEST_NAME > $ROOTFS/etc/hostname |
| 387 | |
| 388 | # We need the hostname to resolve for rabbit to launch |
| 389 | if ! grep -q $GUEST_NAME $ROOTFS/etc/hosts; then |
| 390 | echo "$GUEST_IP $GUEST_NAME" >> $ROOTFS/etc/hosts |
| 391 | fi |
| 392 | |
Dean Troyer | 6fe687b | 2011-10-31 20:30:04 -0500 | [diff] [blame] | 393 | # GRUB 2 wants to see /dev |
| 394 | mount -o bind /dev $ROOTFS/dev |
| 395 | |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 396 | # Change boot params so that we get a console log |
| 397 | G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1` |
| 398 | sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub |
Jesse Andrews | 2c5201b | 2011-10-30 20:44:26 -0700 | [diff] [blame] | 399 | sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass\",g" -i $ROOTFS/etc/default/grub |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 400 | sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub |
| 401 | echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub |
| 402 | echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub |
| 403 | echo "GRUB_DEVICE_UUID=$G_DEV_UUID" >>$ROOTFS/etc/default/grub |
| 404 | |
| 405 | chroot $ROOTFS update-grub |
| 406 | umount $ROOTFS/dev |
| 407 | |
| 408 | # Pre-generate ssh host keys and allow password login |
| 409 | chroot $ROOTFS dpkg-reconfigure openssh-server |
| 410 | sed -e 's/^PasswordAuthentication.*$/PasswordAuthentication yes/' -i $ROOTFS/etc/ssh/sshd_config |
| 411 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 412 | # Unmount |
| 413 | umount $ROOTFS || echo 'ok' |
Dean Troyer | 55c0273 | 2011-11-01 17:44:03 -0500 | [diff] [blame] | 414 | ROOTFS="" |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 415 | qemu-nbd -d $NBD |
Dean Troyer | 55c0273 | 2011-11-01 17:44:03 -0500 | [diff] [blame] | 416 | NBD="" |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 417 | |
| 418 | # Create the instance |
| 419 | cd $VM_DIR && virsh create libvirt.xml |
| 420 | |
| 421 | # Tail the console log till we are done |
| 422 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
| 423 | if [ "$WAIT_TILL_LAUNCH" = "1" ]; then |
| 424 | # Done creating the container, let's tail the log |
| 425 | echo |
| 426 | echo "=============================================================" |
| 427 | echo " -- YAY! --" |
| 428 | echo "=============================================================" |
| 429 | echo |
| 430 | echo "We're done launching the vm, about to start tailing the" |
| 431 | echo "stack.sh log. It will take a second or two to start." |
| 432 | echo |
| 433 | echo "Just CTRL-C at any time to stop tailing." |
| 434 | |
| 435 | while [ ! -e "$VM_DIR/console.log" ]; do |
| 436 | sleep 1 |
| 437 | done |
| 438 | |
Jesse Andrews | 1634196 | 2011-10-31 00:21:56 -0700 | [diff] [blame] | 439 | tail -F $VM_DIR/console.log & |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 440 | |
| 441 | TAIL_PID=$! |
| 442 | |
| 443 | function kill_tail() { |
| 444 | kill $TAIL_PID |
| 445 | exit 1 |
| 446 | } |
| 447 | |
| 448 | # Let Ctrl-c kill tail and exit |
| 449 | trap kill_tail SIGINT |
| 450 | |
Jesse Andrews | 1634196 | 2011-10-31 00:21:56 -0700 | [diff] [blame] | 451 | set +o xtrace |
| 452 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 453 | echo "Waiting stack.sh to finish..." |
| 454 | while ! cat $VM_DIR/console.log | grep -q 'All done' ; do |
Jesse Andrews | 1634196 | 2011-10-31 00:21:56 -0700 | [diff] [blame] | 455 | sleep 1 |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 456 | done |
| 457 | |
Jesse Andrews | 1634196 | 2011-10-31 00:21:56 -0700 | [diff] [blame] | 458 | set -o xtrace |
| 459 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 460 | kill $TAIL_PID |
| 461 | |
Jesse Andrews | a06ac1c | 2011-10-31 22:29:23 -0700 | [diff] [blame] | 462 | if ! grep -q "^stack.sh completed in" $VM_DIR/console.log; then |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 463 | exit 1 |
| 464 | fi |
| 465 | echo "" |
| 466 | echo "Finished - Zip-a-dee Doo-dah!" |
| 467 | fi |