add script to launch stack.sh in an lxc container

This commit is contained in:
Anthony Young 2011-09-12 21:09:55 -07:00
parent 1c1d1505c7
commit 72d69636df

76
lxc/lxc_stack.sh Executable file
View file

@ -0,0 +1,76 @@
#!/bin/bash
# Configurable params
BRIDGE=${BRIDGE:-br0}
CONTAINER=${CONTAINER:-TESTER}
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}
# Destroy any existing container
lxc-stop -n $CONTAINER
lxc-destroy -n $CONTAINER
# Create network configuration
NET_CONF=/tmp/net.conf
cat > $NET_CONF <<EOF
lxc.network.type = veth
lxc.network.link = $BRIDGE
lxc.network.flags = up
lxc.network.ipv4 = $CONTAINER_CIDR
EOF
# Configure the network
lxc-create -n $CONTAINER -t natty -f $NET_CONF
# Where our container lives
ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
# Copy over your ssh keys if desired
if [ $COPYENV ]; then
cp -pr ~/.ssh $ROOTFS/root/.ssh
cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig
cp -pr ~/.vimrc $ROOTFS/root/.vimrc
cp -pr ~/.bashrc $ROOTFS/root/.bashrc
fi
# 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
# Configure the first run installer
INSTALL_SH=$ROOTFS/root/install.sh
cat > $INSTALL_SH <<EOF
#!/bin/bash
echo "nameserver $NAMESERVER" | resolvconf -a eth0
sleep 1
apt-get -y --force-yes install git-core vim-nox
git clone git://github.com/cloudbuilders/nfs-stack.git /root/nfs-stack
EOF
chmod 700 $INSTALL_SH
# Make installer run on boot
RC_LOCAL=$ROOTFS/etc/rc.local
cat > $RC_LOCAL <<EOF
#!/bin/sh -e
/root/install.sh
EOF
# Configure cgroup directory
mkdir -p /cgroup
mount none -t cgroup /cgroup
# Start our container
lxc-start -d -n $CONTAINER