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