blob: d2478183d324de7d518a44cf5e1cdd38ed5c3d32 [file] [log] [blame]
Anthony Young72d69632011-09-12 21:09:55 -07001#!/bin/bash
2# Configurable params
3BRIDGE=${BRIDGE:-br0}
4CONTAINER=${CONTAINER:-TESTER}
5CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
6CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
7CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
8CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
9NAMESERVER=${NAMESERVER:-192.168.1.1}
10COPYENV=${COPYENV:-1}
Anthony Youngb3c04542011-09-13 01:28:18 -070011WARMCACHE=${WARMCACHE:-0}
Anthony Young72d69632011-09-12 21:09:55 -070012
13# Destroy any existing container
14lxc-stop -n $CONTAINER
Anthony Young99003e72011-09-13 02:05:12 -070015sleep 2
Anthony Young72d69632011-09-12 21:09:55 -070016lxc-destroy -n $CONTAINER
Anthony Young99003e72011-09-13 02:05:12 -070017sleep 2
18
19CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
20if [ "$WARMCACHE" = "1" ]; then
21 if [ -d $CACHEDIR ]; then
22 # Pre-cache files
23 chroot $CACHEDIR apt-get update
24 chroot $CACHEDIR apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
25 chroot $CACHEDIR pip install `cat pips/*`
26 fi
27fi
Anthony Young72d69632011-09-12 21:09:55 -070028
29# Create network configuration
30NET_CONF=/tmp/net.conf
31cat > $NET_CONF <<EOF
32lxc.network.type = veth
33lxc.network.link = $BRIDGE
34lxc.network.flags = up
35lxc.network.ipv4 = $CONTAINER_CIDR
36EOF
37
38# Configure the network
39lxc-create -n $CONTAINER -t natty -f $NET_CONF
Anthony Young99003e72011-09-13 02:05:12 -070040sleep 2
Anthony Youngb3c04542011-09-13 01:28:18 -070041
Anthony Young72d69632011-09-12 21:09:55 -070042# Where our container lives
43ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
44
Anthony Youngb3c04542011-09-13 01:28:18 -070045# Copy over your ssh keys and env if desired
46if [ "$COPYENV" = "1" ]; then
Anthony Young72d69632011-09-12 21:09:55 -070047 cp -pr ~/.ssh $ROOTFS/root/.ssh
Anthony Youngb3c04542011-09-13 01:28:18 -070048 cp -p ~/.ssh/id_rsa.pub $ROOTFS/root/.ssh/authorized_keys
Anthony Young72d69632011-09-12 21:09:55 -070049 cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig
50 cp -pr ~/.vimrc $ROOTFS/root/.vimrc
51 cp -pr ~/.bashrc $ROOTFS/root/.bashrc
52fi
53
54# Configure instance network
55INTERFACES=$ROOTFS/etc/network/interfaces
56cat > $INTERFACES <<EOF
57auto lo
58iface lo inet loopback
59
60auto eth0
61iface eth0 inet static
62 address $CONTAINER_IP
63 netmask $CONTAINER_NETMASK
64 gateway $CONTAINER_GATEWAY
65EOF
66
67# Configure the first run installer
68INSTALL_SH=$ROOTFS/root/install.sh
69cat > $INSTALL_SH <<EOF
70#!/bin/bash
71echo "nameserver $NAMESERVER" | resolvconf -a eth0
72sleep 1
Anthony Young99003e72011-09-13 02:05:12 -070073# Create a stack user that is a member of the libvirtd group so that stack
74# is able to interact with libvirt.
75groupadd libvirtd
76useradd stack -s /bin/bash -d /opt -G libvirtd
77
78# a simple password - pass
79echo stack:pass | chpasswd
80
81# give stack ownership over /opt so it may do the work needed
82chown -R stack /opt
83
84# and has sudo ability (in the future this should be limited to only what
85# stack requires)
86
87echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
88
89# Install and run stack.sh
Anthony Younge2c3a372011-09-12 23:25:37 -070090apt-get update
91apt-get -y --force-yes install git-core vim-nox sudo
Anthony Young99003e72011-09-13 02:05:12 -070092su -c "git clone git://github.com/cloudbuilders/nfs-stack.git /opt/nfs-stack" stack
93su -c "cd /opt/nfs-stack && ./stack.sh" stack
Anthony Young72d69632011-09-12 21:09:55 -070094EOF
95
96chmod 700 $INSTALL_SH
97
98# Make installer run on boot
99RC_LOCAL=$ROOTFS/etc/rc.local
100cat > $RC_LOCAL <<EOF
101#!/bin/sh -e
102/root/install.sh
103EOF
104
Anthony Young72d69632011-09-12 21:09:55 -0700105# Configure cgroup directory
Anthony Young99003e72011-09-13 02:05:12 -0700106mkdir -p /cgroup
107mount none -t cgroup /cgroup
Anthony Young72d69632011-09-12 21:09:55 -0700108
109# Start our container
110lxc-start -d -n $CONTAINER