Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Dean Troyer | 5611951 | 2011-10-11 19:39:34 -0500 | [diff] [blame] | 2 | # build_ramdisk.sh - Build RAM disk images |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 3 | |
| 4 | if [ ! "$#" -eq "1" ]; then |
| 5 | echo "$0 builds a gziped natty openstack install" |
| 6 | echo "usage: $0 dest" |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 10 | IMG_FILE=$1 |
| 11 | |
Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 12 | PROGDIR=`dirname $0` |
Dean Troyer | d4a3bac | 2011-10-03 21:16:27 -0500 | [diff] [blame] | 13 | CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack} |
Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 14 | |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 15 | # Source params |
| 16 | source ./stackrc |
| 17 | |
Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 18 | # Store cwd |
| 19 | CWD=`pwd` |
| 20 | |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 21 | DEST=${DEST:-/opt/stack} |
| 22 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 23 | # Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" |
| 24 | STACKSH_PARAMS=${STACKSH_PARAMS:-} |
| 25 | |
Dean Troyer | a3379e0 | 2011-10-03 11:14:13 -0500 | [diff] [blame] | 26 | # Option to use the version of devstack on which we are currently working |
| 27 | USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} |
| 28 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 29 | # Set up nbd |
| 30 | modprobe nbd max_part=63 |
| 31 | NBD=${NBD:-/dev/nbd9} |
| 32 | NBD_DEV=`basename $NBD` |
| 33 | |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 34 | # clean install of natty |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 35 | if [ ! -r $CHROOTCACHE/natty-base.img ]; then |
| 36 | $PROGDIR/get_uec_image.sh natty $CHROOTCACHE/natty-base.img |
| 37 | # # copy kernel modules... |
| 38 | # # NOTE(ja): is there a better way to do this? |
| 39 | # cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules |
| 40 | # # a simple password - pass |
| 41 | # echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 42 | fi |
| 43 | |
| 44 | # prime natty with as many apt/pips as we can |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 45 | if [ ! -r $CHROOTCACHE/natty-dev.img ]; then |
| 46 | cp -p $CHROOTCACHE/natty-base.img $CHROOTCACHE/natty-dev.img |
| 47 | |
| 48 | qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img |
| 49 | if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then |
| 50 | echo "Couldn't connect $NBD" |
| 51 | exit 1 |
| 52 | fi |
| 53 | MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX` |
| 54 | mount -t ext4 ${NBD}p1 $MNTDIR |
| 55 | cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf |
| 56 | |
| 57 | chroot $MNTDIR apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
| 58 | chroot $MNTDIR pip install `cat files/pips/*` |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 59 | |
Vishvananda Ishaya | 9b35367 | 2011-10-20 10:07:10 -0700 | [diff] [blame] | 60 | # Create a stack user that is a member of the libvirtd group so that stack |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 61 | # is able to interact with libvirt. |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 62 | chroot $MNTDIR groupadd libvirtd |
| 63 | chroot $MNTDIR useradd stack -s /bin/bash -d $DEST -G libvirtd |
| 64 | mkdir -p $MNTDIR/$DEST |
| 65 | chroot $MNTDIR chown stack $DEST |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 66 | |
| 67 | # a simple password - pass |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 68 | echo stack:pass | chroot $MNTDIR chpasswd |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 69 | |
Vishvananda Ishaya | 9b35367 | 2011-10-20 10:07:10 -0700 | [diff] [blame] | 70 | # and has sudo ability (in the future this should be limited to only what |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 71 | # stack requires) |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 72 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers |
| 73 | |
| 74 | umount $MNTDIR |
| 75 | rmdir $MNTDIR |
| 76 | qemu-nbd -d $NBD |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 77 | fi |
| 78 | |
| 79 | # clone git repositories onto the system |
| 80 | # ====================================== |
| 81 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 82 | if [ ! -r $IMG_FILE ]; then |
Dean Troyer | 61be924 | 2011-10-25 22:35:23 -0500 | [diff] [blame] | 83 | qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img |
| 84 | if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then |
| 85 | echo "Couldn't connect $NBD" |
| 86 | exit 1 |
| 87 | fi |
| 88 | |
| 89 | # Pre-create the image file |
| 90 | # FIXME(dt): This should really get the partition size to |
| 91 | # pre-create the image file |
| 92 | dd if=/dev/zero of=$IMG_FILE bs=1 count=1 seek=$((2*1024*1024*1024)) |
| 93 | # Create filesystem image for RAM disk |
| 94 | dd if=${NBD}p1 of=$IMG_FILE bs=1M |
| 95 | |
| 96 | qemu-nbd -d $NBD |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 97 | fi |
| 98 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 99 | MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX` |
Dean Troyer | 61be924 | 2011-10-25 22:35:23 -0500 | [diff] [blame] | 100 | mount -t ext4 -o loop $IMG_FILE $MNTDIR |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 101 | cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf |
| 102 | |
Dean Troyer | ea442c1 | 2011-10-26 12:34:59 -0500 | [diff] [blame^] | 103 | # We need to install a non-virtual kernel and modules to boot from |
| 104 | if [ ! -r `ls $MNTDIR/boot/vmlinuz-2.6.*-generic | head -1` ]; then |
| 105 | chroot $MNTDIR apt-get install -y linux-generic |
| 106 | fi |
| 107 | |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 108 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 109 | # be owned by the installation user, we create the directory and change the |
| 110 | # ownership to the proper user. |
| 111 | function git_clone { |
| 112 | |
| 113 | # clone new copy or fetch latest changes |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 114 | CHECKOUT=${MNTDIR}$2 |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 115 | if [ ! -d $CHECKOUT ]; then |
| 116 | mkdir -p $CHECKOUT |
| 117 | git clone $1 $CHECKOUT |
| 118 | else |
| 119 | pushd $CHECKOUT |
| 120 | git fetch |
| 121 | popd |
| 122 | fi |
| 123 | |
| 124 | # FIXME(ja): checkout specified version (should works for branches and tags) |
| 125 | |
| 126 | pushd $CHECKOUT |
| 127 | # checkout the proper branch/tag |
| 128 | git checkout $3 |
| 129 | # force our local version to be the same as the remote version |
| 130 | git reset --hard origin/$3 |
| 131 | popd |
| 132 | |
| 133 | # give ownership to the stack user |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 134 | chroot $MNTDIR chown -R stack $2 |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 137 | git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH |
| 138 | git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH |
| 139 | git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH |
| 140 | git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH |
| 141 | git_clone $DASH_REPO $DEST/dash $DASH_BRANCH |
| 142 | git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH |
| 143 | git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 144 | |
Dean Troyer | b5da519 | 2011-10-17 13:32:06 -0500 | [diff] [blame] | 145 | # Use this version of devstack |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 146 | rm -rf $MNTDIR/$DEST/devstack |
| 147 | cp -pr $CWD $MNTDIR/$DEST/devstack |
| 148 | chroot $MNTDIR chown -R stack $DEST/devstack |
Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 149 | |
Dean Troyer | cf9db8d | 2011-10-03 13:42:16 -0500 | [diff] [blame] | 150 | # Configure host network for DHCP |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 151 | mkdir -p $MNTDIR/etc/network |
| 152 | cat > $MNTDIR/etc/network/interfaces <<EOF |
Dean Troyer | cf9db8d | 2011-10-03 13:42:16 -0500 | [diff] [blame] | 153 | auto lo |
| 154 | iface lo inet loopback |
| 155 | |
| 156 | auto eth0 |
| 157 | iface eth0 inet dhcp |
| 158 | EOF |
| 159 | |
Dean Troyer | 288f3bd | 2011-10-13 15:50:44 -0500 | [diff] [blame] | 160 | # Set hostname |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 161 | echo "ramstack" >$MNTDIR/etc/hostname |
| 162 | echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts |
Dean Troyer | 288f3bd | 2011-10-13 15:50:44 -0500 | [diff] [blame] | 163 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 164 | # Configure the runner |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 165 | RUN_SH=$MNTDIR/$DEST/run.sh |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 166 | cat > $RUN_SH <<EOF |
| 167 | #!/usr/bin/env bash |
| 168 | |
Dean Troyer | 7c076ee | 2011-10-13 13:20:13 -0500 | [diff] [blame] | 169 | # Get IP range |
| 170 | set \`ip addr show dev eth0 | grep inet\` |
| 171 | PREFIX=\`echo \$2 | cut -d. -f1,2,3\` |
| 172 | export FLOATING_RANGE="\$PREFIX.224/27" |
| 173 | |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 174 | # Kill any existing screens |
| 175 | killall screen |
| 176 | |
| 177 | # Run stack.sh |
| 178 | cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log |
| 179 | echo >> $DEST/run.sh.log |
| 180 | echo >> $DEST/run.sh.log |
| 181 | echo "All done! Time to start clicking." >> $DEST/run.sh.log |
| 182 | EOF |
| 183 | |
| 184 | # Make the run.sh executable |
| 185 | chmod 755 $RUN_SH |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 186 | chroot $MNTDIR chown stack $DEST/run.sh |
Dean Troyer | 8f851e7 | 2011-10-11 20:22:23 -0500 | [diff] [blame] | 187 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 188 | umount $MNTDIR |
| 189 | rmdir $MNTDIR |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 190 | |
Dean Troyer | a6466e0 | 2011-10-25 17:53:24 -0500 | [diff] [blame] | 191 | gzip -1 $IMG_FILE |