#!/bin/bash # Configurable params BRIDGE=${BRIDGE:-br0} CONTAINER=${CONTAINER:-STACK} 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} NAMESERVER=${NAMESERVER:-192.168.1.1} COPYENV=${COPYENV:-1} WARMCACHE=${WARMCACHE:-0} # Shutdown any existing container lxc-stop -n $CONTAINER # This prevents zombie containers cgdelete -r cpu,net_cls:$CONTAINER # Destroy the old container lxc-destroy -n $CONTAINER # Warm the base image on first run or when WARMCACHE=1 CACHEDIR=/var/cache/lxc/natty/rootfs-amd64 if [ "$WARMCACHE" = "1" ] || [ ! -d $CACHEDIR ]; then if [ -d $CACHEDIR ]; then # Pre-cache files chroot $CACHEDIR apt-get update chroot $CACHEDIR apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` chroot $CACHEDIR pip install `cat pips/*` fi fi # Create network configuration LXC_CONF=/tmp/net.conf cat > $LXC_CONF <> $ROOTFS/etc/sudoers # Copy over your ssh keys and env if desired if [ "$COPYENV" = "1" ]; then cp -pr ~/.ssh $ROOTFS/opt/.ssh cp -p ~/.ssh/id_rsa.pub $ROOTFS/opt/.ssh/authorized_keys cp -pr ~/.gitconfig $ROOTFS/opt/.gitconfig cp -pr ~/.vimrc $ROOTFS/opt/.vimrc cp -pr ~/.bashrc $ROOTFS/opt/.bashrc fi # Give stack ownership over /opt so it may do the work needed chroot $ROOTFS chown -R stack /opt # Configure instance network INTERFACES=$ROOTFS/etc/network/interfaces cat > $INTERFACES < $INSTALL_SH < /etc/rc.local # Make sure dns is set up echo "nameserver $NAMESERVER" | resolvconf -a eth0 sleep 1 # Install and run stack.sh apt-get update apt-get -y --force-yes install git-core vim-nox sudo su -c "git clone git://github.com/cloudbuilders/nfs-stack.git ~/nfs-stack" stack su -c "cd ~/nfs-stack && ./stack.sh" stack EOF chmod 700 $INSTALL_SH # Make installer run on boot RC_LOCAL=$ROOTFS/etc/rc.local cat > $RC_LOCAL <