| ... | ... |
@@ -10,16 +10,19 @@ NAMESERVER=${NAMESERVER:-192.168.1.1}
|
| 10 | 10 |
COPYENV=${COPYENV:-1}
|
| 11 | 11 |
WARMCACHE=${WARMCACHE:-0}
|
| 12 | 12 |
|
| 13 |
-# Destroy any existing container |
|
| 13 |
+# Shutdown any existing container |
|
| 14 | 14 |
lxc-stop -n $CONTAINER |
| 15 | 15 |
sleep 1 |
| 16 |
+# This prevents zombie containers |
|
| 16 | 17 |
cgdelete -r cpu,net_cls:$CONTAINER |
| 17 | 18 |
sleep 1 |
| 19 |
+# Destroy the old container |
|
| 18 | 20 |
lxc-destroy -n $CONTAINER |
| 19 | 21 |
sleep 1 |
| 20 | 22 |
|
| 23 |
+# Warm the base image on first run or when WARMCACHE=1 |
|
| 21 | 24 |
CACHEDIR=/var/cache/lxc/natty/rootfs-amd64 |
| 22 |
-if [ "$WARMCACHE" = "1" ]; then |
|
| 25 |
+if [ "$WARMCACHE" = "1" ] || [ ! -d $CACHEDIR ]; then |
|
| 23 | 26 |
if [ -d $CACHEDIR ]; then |
| 24 | 27 |
# Pre-cache files |
| 25 | 28 |
chroot $CACHEDIR apt-get update |
| ... | ... |
@@ -29,17 +32,18 @@ if [ "$WARMCACHE" = "1" ]; then |
| 29 | 29 |
fi |
| 30 | 30 |
|
| 31 | 31 |
# Create network configuration |
| 32 |
-NET_CONF=/tmp/net.conf |
|
| 33 |
-cat > $NET_CONF <<EOF |
|
| 32 |
+LXC_CONF=/tmp/net.conf |
|
| 33 |
+cat > $LXC_CONF <<EOF |
|
| 34 | 34 |
lxc.network.type = veth |
| 35 | 35 |
lxc.network.link = $BRIDGE |
| 36 | 36 |
lxc.network.flags = up |
| 37 | 37 |
lxc.network.ipv4 = $CONTAINER_CIDR |
| 38 |
+# allow tap/tun devices |
|
| 38 | 39 |
lxc.cgroup.devices.allow = c 10:200 rwm |
| 39 | 40 |
EOF |
| 40 | 41 |
|
| 41 | 42 |
# Configure the network |
| 42 |
-lxc-create -n $CONTAINER -t natty -f $NET_CONF |
|
| 43 |
+lxc-create -n $CONTAINER -t natty -f $LXC_CONF |
|
| 43 | 44 |
sleep 2 |
| 44 | 45 |
|
| 45 | 46 |
# Where our container lives |