2011-09-14 04:51:28 +00:00
|
|
|
#!/usr/bin/env bash
|
2011-09-19 21:23:42 +00:00
|
|
|
|
2011-09-26 21:04:13 +00:00
|
|
|
# Use stackrc.example if stackrc is missing
|
|
|
|
if [ ! -e ./stackrc ]; then
|
|
|
|
read -n1 -p "No stackrc present. Copy stackrc.example to stackrc? (y/n) "
|
|
|
|
echo
|
|
|
|
[[ $REPLY = [yY] ]] && cp stackrc.example stackrc|| { echo "Aborting: Missing stackrc"; exit 1; }
|
|
|
|
fi
|
|
|
|
|
2011-09-26 20:02:40 +00:00
|
|
|
# Source params
|
|
|
|
source ./stackrc
|
|
|
|
|
2011-09-26 23:19:50 +00:00
|
|
|
# Store cwd
|
|
|
|
CWD=`pwd`
|
|
|
|
|
2011-09-13 04:09:55 +00:00
|
|
|
# Configurable params
|
|
|
|
BRIDGE=${BRIDGE:-br0}
|
2011-09-13 17:16:13 +00:00
|
|
|
CONTAINER=${CONTAINER:-STACK}
|
2011-09-13 04:09:55 +00:00
|
|
|
CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
|
|
|
|
CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
|
|
|
|
CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
|
|
|
|
CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
|
2011-09-14 07:49:39 +00:00
|
|
|
NAMESERVER=${NAMESERVER:-$CONTAINER_GATEWAY}
|
2011-09-13 04:09:55 +00:00
|
|
|
COPYENV=${COPYENV:-1}
|
2011-09-13 17:40:04 +00:00
|
|
|
|
2011-09-14 03:21:42 +00:00
|
|
|
# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
|
|
|
|
STACKSH_PARAMS=${STACKSH_PARAMS:-}
|
|
|
|
|
2011-09-26 22:24:59 +00:00
|
|
|
# Option to use the version of devstack on which we are currently working
|
|
|
|
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
|
|
|
|
|
2011-09-14 06:36:43 +00:00
|
|
|
# Warn users who aren't on natty
|
|
|
|
if ! grep -q natty /etc/lsb-release; then
|
|
|
|
echo "WARNING: this script has only been tested on natty"
|
|
|
|
fi
|
|
|
|
|
2011-09-14 06:21:29 +00:00
|
|
|
# Install deps
|
2011-09-20 02:49:20 +00:00
|
|
|
apt-get install -y lxc debootstrap
|
2011-09-14 06:21:29 +00:00
|
|
|
|
|
|
|
# Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup
|
2011-09-14 04:51:28 +00:00
|
|
|
if ! which cgdelete | grep -q cgdelete; then
|
2011-09-20 02:49:20 +00:00
|
|
|
apt-get install -y g++ bison flex libpam0g-dev
|
2011-09-14 06:21:29 +00:00
|
|
|
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
|
|
|
|
cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2 && tar xfv libcgroup-0.37.1.tar
|
|
|
|
cd libcgroup-0.37.1
|
|
|
|
./configure
|
|
|
|
make install
|
2011-09-22 01:06:01 +00:00
|
|
|
ldconfig
|
2011-09-14 04:51:28 +00:00
|
|
|
fi
|
|
|
|
|
2011-09-13 17:40:04 +00:00
|
|
|
# Create lxc configuration
|
|
|
|
LXC_CONF=/tmp/$CONTAINER.conf
|
|
|
|
cat > $LXC_CONF <<EOF
|
|
|
|
lxc.network.type = veth
|
|
|
|
lxc.network.link = $BRIDGE
|
|
|
|
lxc.network.flags = up
|
|
|
|
lxc.network.ipv4 = $CONTAINER_CIDR
|
|
|
|
# allow tap/tun devices
|
|
|
|
lxc.cgroup.devices.allow = c 10:200 rwm
|
|
|
|
EOF
|
2011-09-13 04:09:55 +00:00
|
|
|
|
2011-09-13 16:17:56 +00:00
|
|
|
# Shutdown any existing container
|
2011-09-13 04:09:55 +00:00
|
|
|
lxc-stop -n $CONTAINER
|
2011-09-13 16:57:31 +00:00
|
|
|
|
2011-09-14 04:51:28 +00:00
|
|
|
# This kills zombie containers
|
|
|
|
if [ -d /cgroup/$CONTAINER ]; then
|
|
|
|
cgdelete -r cpu,net_cls:$CONTAINER
|
|
|
|
fi
|
2011-09-13 16:57:31 +00:00
|
|
|
|
2011-09-26 20:02:40 +00:00
|
|
|
# git clone only if directory doesn't exist already. Since ``DEST`` might not
|
|
|
|
# be owned by the installation user, we create the directory and change the
|
|
|
|
# ownership to the proper user.
|
|
|
|
function git_clone {
|
|
|
|
if [ ! -d $2 ]; then
|
|
|
|
sudo mkdir $2
|
|
|
|
sudo chown `whoami` $2
|
|
|
|
git clone $1 $2
|
|
|
|
cd $2
|
|
|
|
# This checkout syntax works for both branches and tags
|
|
|
|
git checkout $3
|
|
|
|
fi
|
|
|
|
}
|
2011-09-19 21:23:42 +00:00
|
|
|
|
2011-09-13 17:40:04 +00:00
|
|
|
# Warm the base image on first install
|
2011-09-13 09:05:12 +00:00
|
|
|
CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
|
2011-09-26 20:25:11 +00:00
|
|
|
if [ ! -d $CACHEDIR ]; then
|
2011-09-19 21:23:42 +00:00
|
|
|
# by deleting the container, we force lxc-create to re-bootstrap (lxc is
|
|
|
|
# lazy and doesn't do anything if a container already exists)
|
|
|
|
lxc-destroy -n $CONTAINER
|
2011-09-13 17:40:04 +00:00
|
|
|
# trigger the initial debootstrap
|
|
|
|
lxc-create -n $CONTAINER -t natty -f $LXC_CONF
|
|
|
|
chroot $CACHEDIR apt-get update
|
2011-09-20 03:23:42 +00:00
|
|
|
chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
|
2011-09-16 18:27:43 +00:00
|
|
|
chroot $CACHEDIR pip install `cat files/pips/*`
|
2011-09-13 09:05:12 +00:00
|
|
|
fi
|
2011-09-13 04:09:55 +00:00
|
|
|
|
2011-09-26 20:12:57 +00:00
|
|
|
# Cache openstack code
|
|
|
|
git_clone $NOVA_REPO $CACHEDIR/opt/nova $NOVA_BRANCH
|
|
|
|
git_clone $GLANCE_REPO $CACHEDIR/opt/glance $GLANCE_BRANCH
|
|
|
|
git_clone $KEYSTONE_REPO $CACHEDIR/opt/keystone $KEYSTONE_BRANCH
|
|
|
|
git_clone $NOVNC_REPO $CACHEDIR/opt/novnc $NOVNC_BRANCH
|
|
|
|
git_clone $DASH_REPO $CACHEDIR/opt/dash $DASH_BRANCH $DASH_TAG
|
|
|
|
git_clone $NIXON_REPO $CACHEDIR/opt/nixon $NIXON_BRANCH
|
|
|
|
git_clone $NOVACLIENT_REPO $CACHEDIR/opt/python-novaclient $NOVACLIENT_BRANCH
|
|
|
|
git_clone $OPENSTACKX_REPO $CACHEDIR/opt/openstackx $OPENSTACKX_BRANCH
|
|
|
|
git_clone $MUNIN_REPO $CACHEDIR/opt/openstack-munin $MUNIN_BRANCH
|
|
|
|
|
2011-09-26 22:24:59 +00:00
|
|
|
# Use this version of devstack?
|
|
|
|
if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
|
|
|
|
rm -rf $CACHEDIR/opt/devstack
|
2011-09-26 23:19:50 +00:00
|
|
|
cp -pr $CWD $CACHEDIR/opt/devstack
|
2011-09-26 22:24:59 +00:00
|
|
|
fi
|
|
|
|
|
2011-09-13 17:40:04 +00:00
|
|
|
# Destroy the old container
|
|
|
|
lxc-destroy -n $CONTAINER
|
2011-09-13 04:09:55 +00:00
|
|
|
|
2011-09-16 21:54:20 +00:00
|
|
|
# If this call is to TERMINATE the container then exit
|
|
|
|
if [ "$TERMINATE" = "1" ]; then
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2011-09-13 16:57:31 +00:00
|
|
|
# Create the container
|
2011-09-13 16:17:56 +00:00
|
|
|
lxc-create -n $CONTAINER -t natty -f $LXC_CONF
|
2011-09-13 08:28:18 +00:00
|
|
|
|
2011-09-13 17:43:44 +00:00
|
|
|
# Specify where our container rootfs lives
|
2011-09-13 04:09:55 +00:00
|
|
|
ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
|
|
|
|
|
2011-09-13 16:57:31 +00:00
|
|
|
# Create a stack user that is a member of the libvirtd group so that stack
|
|
|
|
# is able to interact with libvirt.
|
|
|
|
chroot $ROOTFS groupadd libvirtd
|
|
|
|
chroot $ROOTFS useradd stack -s /bin/bash -d /opt -G libvirtd
|
|
|
|
|
|
|
|
# a simple password - pass
|
|
|
|
echo stack:pass | chroot $ROOTFS chpasswd
|
|
|
|
|
|
|
|
# and has sudo ability (in the future this should be limited to only what
|
|
|
|
# stack requires)
|
|
|
|
echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers
|
|
|
|
|
2011-09-22 01:06:01 +00:00
|
|
|
# Copy kernel modules
|
|
|
|
mkdir -p $ROOTFS/lib/modules/`uname -r`/kernel
|
|
|
|
cp -p /lib/modules/`uname -r`/modules.dep $ROOTFS/lib/modules/`uname -r`/
|
|
|
|
cp -pR /lib/modules/`uname -r`/kernel/net $ROOTFS/lib/modules/`uname -r`/kernel/
|
|
|
|
|
2011-09-14 05:14:37 +00:00
|
|
|
# Gracefully cp only if source file/dir exists
|
2011-09-14 05:09:36 +00:00
|
|
|
function cp_it {
|
|
|
|
if [ -e $1 ] || [ -d $1 ]; then
|
|
|
|
cp -pr $1 $2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-09-13 08:28:18 +00:00
|
|
|
# Copy over your ssh keys and env if desired
|
|
|
|
if [ "$COPYENV" = "1" ]; then
|
2011-09-14 05:09:36 +00:00
|
|
|
cp_it ~/.ssh $ROOTFS/opt/.ssh
|
|
|
|
cp_it ~/.ssh/id_rsa.pub $ROOTFS/opt/.ssh/authorized_keys
|
|
|
|
cp_it ~/.gitconfig $ROOTFS/opt/.gitconfig
|
|
|
|
cp_it ~/.vimrc $ROOTFS/opt/.vimrc
|
|
|
|
cp_it ~/.bashrc $ROOTFS/opt/.bashrc
|
2011-09-13 04:09:55 +00:00
|
|
|
fi
|
|
|
|
|
2011-09-16 06:49:02 +00:00
|
|
|
# Make our ip address hostnames look nice at the command prompt
|
|
|
|
echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/opt/.bashrc
|
|
|
|
echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile
|
|
|
|
|
2011-09-13 17:05:07 +00:00
|
|
|
# Give stack ownership over /opt so it may do the work needed
|
2011-09-13 16:57:31 +00:00
|
|
|
chroot $ROOTFS chown -R stack /opt
|
|
|
|
|
2011-09-13 04:09:55 +00:00
|
|
|
# Configure instance network
|
|
|
|
INTERFACES=$ROOTFS/etc/network/interfaces
|
|
|
|
cat > $INTERFACES <<EOF
|
|
|
|
auto lo
|
|
|
|
iface lo inet loopback
|
|
|
|
|
|
|
|
auto eth0
|
|
|
|
iface eth0 inet static
|
|
|
|
address $CONTAINER_IP
|
|
|
|
netmask $CONTAINER_NETMASK
|
|
|
|
gateway $CONTAINER_GATEWAY
|
|
|
|
EOF
|
|
|
|
|
2011-09-14 03:21:42 +00:00
|
|
|
# Configure the runner
|
2011-09-14 09:54:27 +00:00
|
|
|
RUN_SH=$ROOTFS/opt/run.sh
|
2011-09-14 05:09:36 +00:00
|
|
|
cat > $RUN_SH <<EOF
|
2011-09-14 16:40:58 +00:00
|
|
|
#!/usr/bin/env bash
|
2011-09-13 16:57:31 +00:00
|
|
|
# Make sure dns is set up
|
2011-09-14 09:54:27 +00:00
|
|
|
echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0
|
2011-09-13 04:09:55 +00:00
|
|
|
sleep 1
|
2011-09-13 09:05:12 +00:00
|
|
|
|
2011-09-14 08:58:01 +00:00
|
|
|
# Kill any existing screens
|
2011-09-14 09:56:41 +00:00
|
|
|
killall screen
|
2011-09-14 08:58:01 +00:00
|
|
|
|
2011-09-13 09:05:12 +00:00
|
|
|
# Install and run stack.sh
|
2011-09-14 09:54:27 +00:00
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get -y --force-yes install git-core vim-nox sudo
|
2011-09-14 18:25:47 +00:00
|
|
|
if [ ! -d "/opt/devstack" ]; then
|
2011-09-16 04:05:50 +00:00
|
|
|
git clone git://github.com/cloudbuilders/devstack.git /opt/devstack
|
2011-09-14 03:21:42 +00:00
|
|
|
fi
|
2011-09-14 18:25:47 +00:00
|
|
|
cd /opt/devstack && $STACKSH_PARAMS ./stack.sh > /opt/run.sh.log
|
2011-09-13 04:09:55 +00:00
|
|
|
EOF
|
|
|
|
|
2011-09-14 05:09:36 +00:00
|
|
|
# Make the run.sh executable
|
2011-09-14 09:54:27 +00:00
|
|
|
chmod 755 $RUN_SH
|
2011-09-13 04:09:55 +00:00
|
|
|
|
2011-09-14 05:09:36 +00:00
|
|
|
# Make runner launch on boot
|
2011-09-13 04:09:55 +00:00
|
|
|
RC_LOCAL=$ROOTFS/etc/rc.local
|
|
|
|
cat > $RC_LOCAL <<EOF
|
|
|
|
#!/bin/sh -e
|
2011-09-14 09:54:27 +00:00
|
|
|
su -c "/opt/run.sh" stack
|
2011-09-13 04:09:55 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# Configure cgroup directory
|
2011-09-14 04:51:28 +00:00
|
|
|
if ! mount | grep -q cgroup; then
|
|
|
|
mkdir -p /cgroup
|
|
|
|
mount none -t cgroup /cgroup
|
|
|
|
fi
|
2011-09-13 04:09:55 +00:00
|
|
|
|
|
|
|
# Start our container
|
|
|
|
lxc-start -d -n $CONTAINER
|