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