Browse code

add script to launch stack.sh in an lxc container

Anthony Young authored on 2011/09/13 13:09:55
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,76 @@
0
+#!/bin/bash
1
+# Configurable params
2
+BRIDGE=${BRIDGE:-br0}
3
+CONTAINER=${CONTAINER:-TESTER}
4
+CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
5
+CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
6
+CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
7
+CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
8
+NAMESERVER=${NAMESERVER:-192.168.1.1}
9
+COPYENV=${COPYENV:-1}
10
+
11
+# Destroy any existing container
12
+lxc-stop -n $CONTAINER
13
+lxc-destroy -n $CONTAINER
14
+
15
+# Create network configuration
16
+NET_CONF=/tmp/net.conf
17
+cat > $NET_CONF <<EOF
18
+lxc.network.type = veth
19
+lxc.network.link = $BRIDGE
20
+lxc.network.flags = up
21
+lxc.network.ipv4 = $CONTAINER_CIDR
22
+EOF
23
+
24
+# Configure the network
25
+lxc-create -n $CONTAINER -t natty -f $NET_CONF
26
+
27
+# Where our container lives
28
+ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
29
+
30
+# Copy over your ssh keys if desired
31
+if [ $COPYENV ]; then
32
+    cp -pr ~/.ssh $ROOTFS/root/.ssh
33
+    cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig
34
+    cp -pr ~/.vimrc $ROOTFS/root/.vimrc
35
+    cp -pr ~/.bashrc $ROOTFS/root/.bashrc
36
+fi
37
+
38
+# Configure instance network
39
+INTERFACES=$ROOTFS/etc/network/interfaces
40
+cat > $INTERFACES <<EOF
41
+auto lo
42
+iface lo inet loopback
43
+
44
+auto eth0
45
+iface eth0 inet static
46
+        address $CONTAINER_IP
47
+        netmask $CONTAINER_NETMASK
48
+        gateway $CONTAINER_GATEWAY
49
+EOF
50
+
51
+# Configure the first run installer
52
+INSTALL_SH=$ROOTFS/root/install.sh
53
+cat > $INSTALL_SH <<EOF
54
+#!/bin/bash
55
+echo "nameserver $NAMESERVER" | resolvconf -a eth0
56
+sleep 1
57
+apt-get -y --force-yes install git-core vim-nox
58
+git clone git://github.com/cloudbuilders/nfs-stack.git /root/nfs-stack
59
+EOF
60
+
61
+chmod 700 $INSTALL_SH
62
+
63
+# Make installer run on boot
64
+RC_LOCAL=$ROOTFS/etc/rc.local
65
+cat > $RC_LOCAL <<EOF
66
+#!/bin/sh -e
67
+/root/install.sh
68
+EOF
69
+
70
+# Configure cgroup directory
71
+mkdir -p /cgroup
72
+mount none -t cgroup /cgroup
73
+
74
+# Start our container
75
+lxc-start -d -n $CONTAINER