Anthony Young | 4f27922 | 2011-09-13 21:51:28 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Jesse Andrews | 18ebd86 | 2011-09-19 14:23:42 -0700 | [diff] [blame] | 2 | |
Anthony Young | dfc0748 | 2011-11-15 15:29:37 -0800 | [diff] [blame] | 3 | # Debug stuff |
| 4 | set -o errexit |
| 5 | set -o xtrace |
| 6 | |
Jesse Andrews | 46ad2de | 2011-09-28 18:29:50 -0700 | [diff] [blame] | 7 | # Sanity check |
| 8 | if [ "$EUID" -ne "0" ]; then |
| 9 | echo "This script must be run with root privileges." |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 13 | # Keep track of ubuntu version |
| 14 | UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'` |
Jesse Andrews | 46ad2de | 2011-09-28 18:29:50 -0700 | [diff] [blame] | 15 | |
Anthony Young | e8efef7 | 2011-10-14 12:00:50 -0700 | [diff] [blame] | 16 | # Move to top devstack dir |
| 17 | cd .. |
| 18 | |
Anthony Young | cf145b7 | 2011-10-13 15:07:36 -0700 | [diff] [blame] | 19 | # Abort if localrc is not set |
| 20 | if [ ! -e ./localrc ]; then |
| 21 | echo "You must have a localrc with ALL necessary passwords defined before proceeding." |
| 22 | echo "See stack.sh for required passwords." |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
Anthony Young | 2f14020 | 2011-09-26 13:02:40 -0700 | [diff] [blame] | 26 | # Source params |
| 27 | source ./stackrc |
| 28 | |
Anthony Young | 84064da | 2011-09-26 16:19:50 -0700 | [diff] [blame] | 29 | # Store cwd |
| 30 | CWD=`pwd` |
| 31 | |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 32 | # Configurable params |
| 33 | BRIDGE=${BRIDGE:-br0} |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 34 | GUEST_NAME=${GUEST_NAME:-STACK} |
| 35 | GUEST_IP=${GUEST_IP:-192.168.1.50} |
| 36 | GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24} |
| 37 | GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0} |
| 38 | GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.1.1} |
Anthony Young | ae8bc12 | 2011-10-17 10:38:05 -0700 | [diff] [blame] | 39 | NAMESERVER=${NAMESERVER:-`cat /etc/resolv.conf | grep nameserver | head -1 | cut -d " " -f2`} |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 40 | COPYENV=${COPYENV:-1} |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 41 | DEST=${DEST:-/opt/stack} |
Anthony Young | 25369c9 | 2011-10-14 16:50:27 -0700 | [diff] [blame] | 42 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 43 | |
Anthony Young | 1c36464 | 2011-09-13 20:21:42 -0700 | [diff] [blame] | 44 | # Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" |
Anthony Young | b22263a | 2011-10-20 10:26:30 -0700 | [diff] [blame] | 45 | # By default, n-vol is disabled for lxc, as iscsitarget doesn't work properly in lxc |
Tres Henry | ca85b79 | 2011-10-28 14:00:21 -0700 | [diff] [blame] | 46 | STACKSH_PARAMS=${STACKSH_PARAMS:-"ENABLED_SERVICES=g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,horizon,mysql,rabbit"} |
Anthony Young | 1c36464 | 2011-09-13 20:21:42 -0700 | [diff] [blame] | 47 | |
Anthony Young | a34b695 | 2011-09-26 15:24:59 -0700 | [diff] [blame] | 48 | # Option to use the version of devstack on which we are currently working |
| 49 | USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} |
| 50 | |
Anthony Young | 936c928 | 2011-09-13 23:36:43 -0700 | [diff] [blame] | 51 | |
Anthony Young | 190321e | 2011-09-13 23:21:29 -0700 | [diff] [blame] | 52 | # Install deps |
Anthony Young | 856d09f | 2011-09-19 19:49:20 -0700 | [diff] [blame] | 53 | apt-get install -y lxc debootstrap |
Anthony Young | 190321e | 2011-09-13 23:21:29 -0700 | [diff] [blame] | 54 | |
| 55 | # Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup |
Anthony Young | 4f27922 | 2011-09-13 21:51:28 -0700 | [diff] [blame] | 56 | if ! which cgdelete | grep -q cgdelete; then |
termie | bd550ed | 2011-09-28 16:54:25 -0500 | [diff] [blame] | 57 | apt-get install -y g++ bison flex libpam0g-dev make |
| 58 | wget http://sourceforge.net/projects/libcg/files/libcgroup/v0.37.1/libcgroup-0.37.1.tar.bz2/download -O /tmp/libcgroup-0.37.1.tar.bz2 |
Anthony Young | 190321e | 2011-09-13 23:21:29 -0700 | [diff] [blame] | 59 | cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2 && tar xfv libcgroup-0.37.1.tar |
| 60 | cd libcgroup-0.37.1 |
| 61 | ./configure |
| 62 | make install |
Dean Troyer | 62a6deb | 2011-09-21 20:06:01 -0500 | [diff] [blame] | 63 | ldconfig |
Anthony Young | 4f27922 | 2011-09-13 21:51:28 -0700 | [diff] [blame] | 64 | fi |
| 65 | |
Anthony Young | 6053496 | 2011-09-13 10:40:04 -0700 | [diff] [blame] | 66 | # Create lxc configuration |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 67 | LXC_CONF=/tmp/$GUEST_NAME.conf |
Anthony Young | 40203cb | 2011-09-13 09:17:56 -0700 | [diff] [blame] | 68 | cat > $LXC_CONF <<EOF |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 69 | lxc.network.type = veth |
| 70 | lxc.network.link = $BRIDGE |
| 71 | lxc.network.flags = up |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 72 | lxc.network.ipv4 = $GUEST_CIDR |
Anthony Young | 40203cb | 2011-09-13 09:17:56 -0700 | [diff] [blame] | 73 | # allow tap/tun devices |
Anthony Young | f49d7ee | 2011-09-13 03:29:52 -0700 | [diff] [blame] | 74 | lxc.cgroup.devices.allow = c 10:200 rwm |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 75 | EOF |
| 76 | |
Anthony Young | 6053496 | 2011-09-13 10:40:04 -0700 | [diff] [blame] | 77 | # Shutdown any existing container |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 78 | lxc-stop -n $GUEST_NAME |
Anthony Young | 6053496 | 2011-09-13 10:40:04 -0700 | [diff] [blame] | 79 | |
Anthony Young | 4f27922 | 2011-09-13 21:51:28 -0700 | [diff] [blame] | 80 | # This kills zombie containers |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 81 | if [ -d /cgroup/$GUEST_NAME ]; then |
| 82 | cgdelete -r cpu,net_cls:$GUEST_NAME |
Anthony Young | 4f27922 | 2011-09-13 21:51:28 -0700 | [diff] [blame] | 83 | fi |
Anthony Young | 6053496 | 2011-09-13 10:40:04 -0700 | [diff] [blame] | 84 | |
Anthony Young | 2f14020 | 2011-09-26 13:02:40 -0700 | [diff] [blame] | 85 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 86 | # be owned by the installation user, we create the directory and change the |
| 87 | # ownership to the proper user. |
| 88 | function git_clone { |
| 89 | if [ ! -d $2 ]; then |
| 90 | sudo mkdir $2 |
| 91 | sudo chown `whoami` $2 |
| 92 | git clone $1 $2 |
| 93 | cd $2 |
| 94 | # This checkout syntax works for both branches and tags |
| 95 | git checkout $3 |
| 96 | fi |
| 97 | } |
Jesse Andrews | 18ebd86 | 2011-09-19 14:23:42 -0700 | [diff] [blame] | 98 | |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 99 | # Helper to create the container |
| 100 | function create_lxc { |
| 101 | if [ "natty" = "$UBUNTU_VERSION" ]; then |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 102 | lxc-create -n $GUEST_NAME -t natty -f $LXC_CONF |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 103 | else |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 104 | lxc-create -n $GUEST_NAME -t ubuntu -f $LXC_CONF |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 105 | fi |
| 106 | } |
| 107 | |
Anthony Young | beab639 | 2011-09-28 15:12:18 -0700 | [diff] [blame] | 108 | # Location of the base image directory |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 109 | if [ "natty" = "$UBUNTU_VERSION" ]; then |
| 110 | CACHEDIR=/var/cache/lxc/natty/rootfs-amd64 |
| 111 | else |
| 112 | CACHEDIR=/var/cache/lxc/oneiric/rootfs-amd64 |
| 113 | fi |
Anthony Young | beab639 | 2011-09-28 15:12:18 -0700 | [diff] [blame] | 114 | |
| 115 | # Provide option to do totally clean install |
| 116 | if [ "$CLEAR_LXC_CACHE" = "1" ]; then |
| 117 | rm -rf $CACHEDIR |
| 118 | fi |
| 119 | |
| 120 | # Warm the base image on first install |
| 121 | if [ ! -f $CACHEDIR/bootstrapped ]; then |
Jesse Andrews | 18ebd86 | 2011-09-19 14:23:42 -0700 | [diff] [blame] | 122 | # by deleting the container, we force lxc-create to re-bootstrap (lxc is |
| 123 | # lazy and doesn't do anything if a container already exists) |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 124 | lxc-destroy -n $GUEST_NAME |
Anthony Young | 6053496 | 2011-09-13 10:40:04 -0700 | [diff] [blame] | 125 | # trigger the initial debootstrap |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 126 | create_lxc |
Anthony Young | beab639 | 2011-09-28 15:12:18 -0700 | [diff] [blame] | 127 | touch $CACHEDIR/bootstrapped |
Anthony Young | 6053496 | 2011-09-13 10:40:04 -0700 | [diff] [blame] | 128 | fi |
| 129 | |
Anthony Young | 6b9d6da | 2011-10-17 10:12:22 -0700 | [diff] [blame] | 130 | # Make sure that base requirements are installed |
| 131 | chroot $CACHEDIR apt-get update |
Anthony Young | ca2c047 | 2011-11-03 16:29:32 -0700 | [diff] [blame] | 132 | chroot $CACHEDIR apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1` |
Anthony Young | dfc0748 | 2011-11-15 15:29:37 -0800 | [diff] [blame] | 133 | chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1` || true |
Anthony Young | 6b9d6da | 2011-10-17 10:12:22 -0700 | [diff] [blame] | 134 | chroot $CACHEDIR pip install `cat files/pips/*` |
| 135 | |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 136 | # Clean out code repos if directed to do so |
| 137 | if [ "$CLEAN" = "1" ]; then |
Anthony Young | 4f10de8 | 2011-09-26 20:03:40 -0700 | [diff] [blame] | 138 | rm -rf $CACHEDIR/$DEST |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 139 | fi |
| 140 | |
Anthony Young | 303233e | 2011-09-26 13:12:57 -0700 | [diff] [blame] | 141 | # Cache openstack code |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 142 | mkdir -p $CACHEDIR/$DEST |
| 143 | git_clone $NOVA_REPO $CACHEDIR/$DEST/nova $NOVA_BRANCH |
| 144 | git_clone $GLANCE_REPO $CACHEDIR/$DEST/glance $GLANCE_BRANCH |
| 145 | git_clone $KEYSTONE_REPO $CACHEDIR/$DESTkeystone $KEYSTONE_BRANCH |
Anthony Young | 583bad0 | 2011-10-18 08:22:30 -0700 | [diff] [blame] | 146 | git_clone $NOVNC_REPO $CACHEDIR/$DEST/noVNC $NOVNC_BRANCH |
Tres Henry | ca85b79 | 2011-10-28 14:00:21 -0700 | [diff] [blame] | 147 | git_clone $HORIZON_REPO $CACHEDIR/$DEST/horizon $HORIZON_BRANCH $HORIZON_TAG |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 148 | git_clone $NOVACLIENT_REPO $CACHEDIR/$DEST/python-novaclient $NOVACLIENT_BRANCH |
| 149 | git_clone $OPENSTACKX_REPO $CACHEDIR/$DEST/openstackx $OPENSTACKX_BRANCH |
Anthony Young | 028cad1 | 2011-10-17 14:10:42 -0700 | [diff] [blame] | 150 | git_clone $KEYSTONE_REPO $CACHEDIR/$DEST/keystone $KEYSTONE_BRANCH |
| 151 | git_clone $NOVNC_REPO $CACHEDIR/$DEST/novnc $NOVNC_BRANCH |
Anthony Young | 303233e | 2011-09-26 13:12:57 -0700 | [diff] [blame] | 152 | |
Anthony Young | a34b695 | 2011-09-26 15:24:59 -0700 | [diff] [blame] | 153 | # Use this version of devstack? |
| 154 | if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 155 | rm -rf $CACHEDIR/$DEST/devstack |
| 156 | cp -pr $CWD $CACHEDIR/$DEST/devstack |
Anthony Young | a34b695 | 2011-09-26 15:24:59 -0700 | [diff] [blame] | 157 | fi |
| 158 | |
Jesse Andrews | 70188b3 | 2011-10-26 21:59:20 -0700 | [diff] [blame] | 159 | # pre-cache uec images |
| 160 | for image_url in ${IMAGE_URLS//,/ }; do |
| 161 | IMAGE_FNAME=`basename "$image_url"` |
| 162 | if [ ! -f $CACHEDIR/$IMAGE_FNAME ]; then |
| 163 | wget -c $image_url -O $CACHEDIR/$IMAGE_FNAME |
| 164 | fi |
| 165 | cp $CACHEDIR/$IMAGE_FNAME $CACHEDIR/$DEST/devstack/files |
| 166 | done |
| 167 | |
Anthony Young | 6053496 | 2011-09-13 10:40:04 -0700 | [diff] [blame] | 168 | # Destroy the old container |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 169 | lxc-destroy -n $GUEST_NAME |
Anthony Young | 6053496 | 2011-09-13 10:40:04 -0700 | [diff] [blame] | 170 | |
Anthony Young | 23761c3 | 2011-09-16 14:54:20 -0700 | [diff] [blame] | 171 | # If this call is to TERMINATE the container then exit |
| 172 | if [ "$TERMINATE" = "1" ]; then |
| 173 | exit |
| 174 | fi |
| 175 | |
Anthony Young | 7c3e5ed | 2011-09-13 09:57:31 -0700 | [diff] [blame] | 176 | # Create the container |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 177 | create_lxc |
Anthony Young | b3c0454 | 2011-09-13 01:28:18 -0700 | [diff] [blame] | 178 | |
Anthony Young | f9998ab | 2011-09-13 10:43:44 -0700 | [diff] [blame] | 179 | # Specify where our container rootfs lives |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 180 | ROOTFS=/var/lib/lxc/$GUEST_NAME/rootfs/ |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 181 | |
termie | bd550ed | 2011-09-28 16:54:25 -0500 | [diff] [blame] | 182 | # Create a stack user that is a member of the libvirtd group so that stack |
Anthony Young | 7c3e5ed | 2011-09-13 09:57:31 -0700 | [diff] [blame] | 183 | # is able to interact with libvirt. |
| 184 | chroot $ROOTFS groupadd libvirtd |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 185 | chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd |
Anthony Young | 7c3e5ed | 2011-09-13 09:57:31 -0700 | [diff] [blame] | 186 | |
| 187 | # a simple password - pass |
| 188 | echo stack:pass | chroot $ROOTFS chpasswd |
| 189 | |
termie | bd550ed | 2011-09-28 16:54:25 -0500 | [diff] [blame] | 190 | # and has sudo ability (in the future this should be limited to only what |
Anthony Young | 7c3e5ed | 2011-09-13 09:57:31 -0700 | [diff] [blame] | 191 | # stack requires) |
| 192 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers |
| 193 | |
Dean Troyer | 62a6deb | 2011-09-21 20:06:01 -0500 | [diff] [blame] | 194 | # Copy kernel modules |
| 195 | mkdir -p $ROOTFS/lib/modules/`uname -r`/kernel |
| 196 | cp -p /lib/modules/`uname -r`/modules.dep $ROOTFS/lib/modules/`uname -r`/ |
| 197 | cp -pR /lib/modules/`uname -r`/kernel/net $ROOTFS/lib/modules/`uname -r`/kernel/ |
| 198 | |
Anthony Young | 34c4702 | 2011-09-13 22:14:37 -0700 | [diff] [blame] | 199 | # Gracefully cp only if source file/dir exists |
Anthony Young | fe1d95a | 2011-09-13 22:09:36 -0700 | [diff] [blame] | 200 | function cp_it { |
| 201 | if [ -e $1 ] || [ -d $1 ]; then |
termie | 1c7f0c9 | 2011-09-28 17:09:00 -0500 | [diff] [blame] | 202 | cp -pRL $1 $2 |
Anthony Young | fe1d95a | 2011-09-13 22:09:36 -0700 | [diff] [blame] | 203 | fi |
| 204 | } |
| 205 | |
Anthony Young | b3c0454 | 2011-09-13 01:28:18 -0700 | [diff] [blame] | 206 | # Copy over your ssh keys and env if desired |
| 207 | if [ "$COPYENV" = "1" ]; then |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 208 | cp_it ~/.ssh $ROOTFS/$DEST/.ssh |
| 209 | cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys |
| 210 | cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig |
| 211 | cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc |
| 212 | cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 213 | fi |
| 214 | |
Anthony Young | fde5a1c | 2011-09-15 23:49:02 -0700 | [diff] [blame] | 215 | # Make our ip address hostnames look nice at the command prompt |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 216 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc |
Anthony Young | fde5a1c | 2011-09-15 23:49:02 -0700 | [diff] [blame] | 217 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile |
| 218 | |
Anthony Young | adbe9c1 | 2011-09-26 19:58:49 -0700 | [diff] [blame] | 219 | # Give stack ownership over $DEST so it may do the work needed |
| 220 | chroot $ROOTFS chown -R stack $DEST |
Anthony Young | 7c3e5ed | 2011-09-13 09:57:31 -0700 | [diff] [blame] | 221 | |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 222 | # Configure instance network |
| 223 | INTERFACES=$ROOTFS/etc/network/interfaces |
| 224 | cat > $INTERFACES <<EOF |
| 225 | auto lo |
| 226 | iface lo inet loopback |
| 227 | |
| 228 | auto eth0 |
| 229 | iface eth0 inet static |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 230 | address $GUEST_IP |
| 231 | netmask $GUEST_NETMASK |
| 232 | gateway $GUEST_GATEWAY |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 233 | EOF |
| 234 | |
Anthony Young | 1c36464 | 2011-09-13 20:21:42 -0700 | [diff] [blame] | 235 | # Configure the runner |
Anthony Young | e8fed48 | 2011-09-26 19:50:43 -0700 | [diff] [blame] | 236 | RUN_SH=$ROOTFS/$DEST/run.sh |
Anthony Young | fe1d95a | 2011-09-13 22:09:36 -0700 | [diff] [blame] | 237 | cat > $RUN_SH <<EOF |
Anthony Young | 10791a1 | 2011-09-14 09:40:58 -0700 | [diff] [blame] | 238 | #!/usr/bin/env bash |
Anthony Young | 7c3e5ed | 2011-09-13 09:57:31 -0700 | [diff] [blame] | 239 | # Make sure dns is set up |
Anthony Young | 56e6292 | 2011-09-14 02:54:27 -0700 | [diff] [blame] | 240 | echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0 |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 241 | # Make there is a default route - needed for natty |
| 242 | if ! route | grep -q default; then |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 243 | sudo ip route add default via $GUEST_GATEWAY |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 244 | fi |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 245 | sleep 1 |
Anthony Young | 99003e7 | 2011-09-13 02:05:12 -0700 | [diff] [blame] | 246 | |
Anthony Young | 927a656 | 2011-09-14 01:58:01 -0700 | [diff] [blame] | 247 | # Kill any existing screens |
Anthony Young | 92e31ab | 2011-09-14 02:56:41 -0700 | [diff] [blame] | 248 | killall screen |
Anthony Young | 927a656 | 2011-09-14 01:58:01 -0700 | [diff] [blame] | 249 | |
Anthony Young | 99003e7 | 2011-09-13 02:05:12 -0700 | [diff] [blame] | 250 | # Install and run stack.sh |
Anthony Young | 56e6292 | 2011-09-14 02:54:27 -0700 | [diff] [blame] | 251 | sudo apt-get update |
| 252 | sudo apt-get -y --force-yes install git-core vim-nox sudo |
Anthony Young | adbe9c1 | 2011-09-26 19:58:49 -0700 | [diff] [blame] | 253 | if [ ! -d "$DEST/devstack" ]; then |
| 254 | git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack |
Anthony Young | 1c36464 | 2011-09-13 20:21:42 -0700 | [diff] [blame] | 255 | fi |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 256 | cd $DEST/devstack && $STACKSH_PARAMS FORCE=yes ./stack.sh > /$DEST/run.sh.log |
termie | 7377444 | 2011-09-28 19:02:28 -0500 | [diff] [blame] | 257 | echo >> /$DEST/run.sh.log |
| 258 | echo >> /$DEST/run.sh.log |
| 259 | echo "All done! Time to start clicking." >> /$DEST/run.sh.log |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 260 | EOF |
| 261 | |
Anthony Young | fe1d95a | 2011-09-13 22:09:36 -0700 | [diff] [blame] | 262 | # Make the run.sh executable |
Anthony Young | 56e6292 | 2011-09-14 02:54:27 -0700 | [diff] [blame] | 263 | chmod 755 $RUN_SH |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 264 | |
Anthony Young | fe1d95a | 2011-09-13 22:09:36 -0700 | [diff] [blame] | 265 | # Make runner launch on boot |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 266 | RC_LOCAL=$ROOTFS/etc/init.d/local |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 267 | cat > $RC_LOCAL <<EOF |
| 268 | #!/bin/sh -e |
Anthony Young | adbe9c1 | 2011-09-26 19:58:49 -0700 | [diff] [blame] | 269 | su -c "$DEST/run.sh" stack |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 270 | EOF |
Anthony Young | 9ff71ac | 2011-10-14 15:02:20 -0700 | [diff] [blame] | 271 | chmod +x $RC_LOCAL |
| 272 | chroot $ROOTFS sudo update-rc.d local defaults 80 |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 273 | |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 274 | # Configure cgroup directory |
Anthony Young | 4f27922 | 2011-09-13 21:51:28 -0700 | [diff] [blame] | 275 | if ! mount | grep -q cgroup; then |
| 276 | mkdir -p /cgroup |
| 277 | mount none -t cgroup /cgroup |
| 278 | fi |
Anthony Young | 72d6963 | 2011-09-12 21:09:55 -0700 | [diff] [blame] | 279 | |
| 280 | # Start our container |
Jesse Andrews | 82040df | 2011-10-22 20:56:23 -0700 | [diff] [blame] | 281 | lxc-start -d -n $GUEST_NAME |
termie | 7377444 | 2011-09-28 19:02:28 -0500 | [diff] [blame] | 282 | |
Anthony Young | 25369c9 | 2011-10-14 16:50:27 -0700 | [diff] [blame] | 283 | if [ "$WAIT_TILL_LAUNCH" = "1" ]; then |
| 284 | # Done creating the container, let's tail the log |
| 285 | echo |
| 286 | echo "=============================================================" |
| 287 | echo " -- YAY! --" |
| 288 | echo "=============================================================" |
| 289 | echo |
| 290 | echo "We're done creating the container, about to start tailing the" |
| 291 | echo "stack.sh log. It will take a second or two to start." |
| 292 | echo |
| 293 | echo "Just CTRL-C at any time to stop tailing." |
termie | 7377444 | 2011-09-28 19:02:28 -0500 | [diff] [blame] | 294 | |
Anthony Young | 25369c9 | 2011-10-14 16:50:27 -0700 | [diff] [blame] | 295 | while [ ! -e "$ROOTFS/$DEST/run.sh.log" ]; do |
| 296 | sleep 1 |
| 297 | done |
termie | 7377444 | 2011-09-28 19:02:28 -0500 | [diff] [blame] | 298 | |
Anthony Young | 25369c9 | 2011-10-14 16:50:27 -0700 | [diff] [blame] | 299 | tail -F $ROOTFS/$DEST/run.sh.log & |
| 300 | |
| 301 | TAIL_PID=$! |
| 302 | |
| 303 | function kill_tail() { |
Anthony Young | 04db155 | 2011-10-17 09:40:45 -0700 | [diff] [blame] | 304 | kill $TAIL_PID |
Anthony Young | 25369c9 | 2011-10-14 16:50:27 -0700 | [diff] [blame] | 305 | exit 1 |
| 306 | } |
Vishvananda Ishaya | 9b35367 | 2011-10-20 10:07:10 -0700 | [diff] [blame] | 307 | |
Anthony Young | 25369c9 | 2011-10-14 16:50:27 -0700 | [diff] [blame] | 308 | # Let Ctrl-c kill tail and exit |
| 309 | trap kill_tail SIGINT |
| 310 | |
| 311 | echo "Waiting stack.sh to finish..." |
| 312 | while ! cat $ROOTFS/$DEST/run.sh.log | grep -q 'All done' ; do |
| 313 | sleep 5 |
| 314 | done |
| 315 | |
| 316 | kill $TAIL_PID |
Jesse Andrews | ad21d1a | 2011-10-26 12:39:00 -0700 | [diff] [blame] | 317 | |
| 318 | if grep -q "stack.sh failed" $ROOTFS/$DEST/run.sh.log; then |
| 319 | exit 1 |
| 320 | fi |
| 321 | |
Anthony Young | 25369c9 | 2011-10-14 16:50:27 -0700 | [diff] [blame] | 322 | echo "" |
| 323 | echo "Finished - Zip-a-dee Doo-dah!" |
| 324 | fi |