#!/usr/bin/env bash # Debug stuff set -o errexit set -o xtrace # Sanity check if [ "$EUID" -ne "0" ]; then echo "This script must be run with root privileges." exit 1 fi # Keep track of ubuntu version UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'` # Move to top devstack dir cd .. # Abort if localrc is not set if [ ! -e ./localrc ]; then echo "You must have a localrc with ALL necessary passwords defined before proceeding." echo "See stack.sh for required passwords." exit 1 fi # Source params source ./stackrc # Store cwd CWD=`pwd` # Configurable params BRIDGE=${BRIDGE:-br0} GUEST_NAME=${GUEST_NAME:-STACK} GUEST_IP=${GUEST_IP:-192.168.1.50} GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24} GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0} GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.1.1} NAMESERVER=${NAMESERVER:-`cat /etc/resolv.conf | grep nameserver | head -1 | cut -d " " -f2`} COPYENV=${COPYENV:-1} DEST=${DEST:-/opt/stack} WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} # Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" # By default, n-vol is disabled for lxc, as iscsitarget doesn't work properly in lxc STACKSH_PARAMS=${STACKSH_PARAMS:-"ENABLED_SERVICES=g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,horizon,mysql,rabbit"} # Option to use the version of devstack on which we are currently working USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} # Install deps apt-get install -y lxc debootstrap # Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup if ! which cgdelete | grep -q cgdelete; then apt-get install -y g++ bison flex libpam0g-dev make 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 ldconfig fi # Create lxc configuration LXC_CONF=/tmp/$GUEST_NAME.conf cat > $LXC_CONF <> $ROOTFS/etc/sudoers # 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/ # Gracefully cp only if source file/dir exists function cp_it { if [ -e $1 ] || [ -d $1 ]; then cp -pRL $1 $2 fi } # Copy over your ssh keys and env if desired if [ "$COPYENV" = "1" ]; then cp_it ~/.ssh $ROOTFS/$DEST/.ssh cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc fi # Make our ip address hostnames look nice at the command prompt echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile # Give stack ownership over $DEST so it may do the work needed chroot $ROOTFS chown -R stack $DEST # Configure instance network INTERFACES=$ROOTFS/etc/network/interfaces cat > $INTERFACES < $RUN_SH < /$DEST/run.sh.log echo >> /$DEST/run.sh.log echo >> /$DEST/run.sh.log echo "All done! Time to start clicking." >> /$DEST/run.sh.log EOF # Make the run.sh executable chmod 755 $RUN_SH # Make runner launch on boot RC_LOCAL=$ROOTFS/etc/init.d/local cat > $RC_LOCAL <