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