Browse code

simplify pre-cache procedure

Anthony Young authored on 2011/09/14 02:40:04
Showing 1 changed files
... ...
@@ -8,7 +8,17 @@ CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
8 8
 CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
9 9
 NAMESERVER=${NAMESERVER:-192.168.1.1}
10 10
 COPYENV=${COPYENV:-1}
11
-WARMCACHE=${WARMCACHE:-0}
11
+
12
+# Create lxc configuration
13
+LXC_CONF=/tmp/$CONTAINER.conf
14
+cat > $LXC_CONF <<EOF
15
+lxc.network.type = veth
16
+lxc.network.link = $BRIDGE
17
+lxc.network.flags = up
18
+lxc.network.ipv4 = $CONTAINER_CIDR
19
+# allow tap/tun devices
20
+lxc.cgroup.devices.allow = c 10:200 rwm
21
+EOF
12 22
 
13 23
 # Shutdown any existing container
14 24
 lxc-stop -n $CONTAINER
... ...
@@ -16,30 +26,18 @@ lxc-stop -n $CONTAINER
16 16
 # This prevents zombie containers
17 17
 cgdelete -r cpu,net_cls:$CONTAINER
18 18
 
19
-# Destroy the old container
20
-lxc-destroy -n $CONTAINER
21
-
22
-# Warm the base image on first run or when WARMCACHE=1
19
+# Warm the base image on first install
23 20
 CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
24
-if [ "$WARMCACHE" = "1" ] || [ ! -d $CACHEDIR ]; then
25
-    if [ -d $CACHEDIR ]; then
26
-        # Pre-cache files
27
-        chroot $CACHEDIR apt-get update
28
-        chroot $CACHEDIR apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
29
-        chroot $CACHEDIR pip install `cat pips/*`
30
-    fi
21
+if [ ! -d $CACHEDIR ]; then
22
+    # trigger the initial debootstrap
23
+    lxc-create -n $CONTAINER -t natty -f $LXC_CONF
24
+    chroot $CACHEDIR apt-get update
25
+    chroot $CACHEDIR apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
26
+    chroot $CACHEDIR pip install `cat pips/*`
31 27
 fi
32 28
 
33
-# Create network configuration
34
-LXC_CONF=/tmp/net.conf
35
-cat > $LXC_CONF <<EOF
36
-lxc.network.type = veth
37
-lxc.network.link = $BRIDGE
38
-lxc.network.flags = up
39
-lxc.network.ipv4 = $CONTAINER_CIDR
40
-# allow tap/tun devices
41
-lxc.cgroup.devices.allow = c 10:200 rwm
42
-EOF
29
+# Destroy the old container
30
+lxc-destroy -n $CONTAINER
43 31
 
44 32
 # Create the container
45 33
 lxc-create -n $CONTAINER -t natty -f $LXC_CONF