| ... | ... |
@@ -8,10 +8,13 @@ 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 |
|
| 12 | 13 |
# Destroy any existing container |
| 13 | 14 |
lxc-stop -n $CONTAINER |
| 15 |
+sleep 1 |
|
| 14 | 16 |
lxc-destroy -n $CONTAINER |
| 17 |
+sleep 1 |
|
| 15 | 18 |
|
| 16 | 19 |
# Create network configuration |
| 17 | 20 |
NET_CONF=/tmp/net.conf |
| ... | ... |
@@ -25,12 +28,21 @@ EOF |
| 25 | 25 |
# Configure the network |
| 26 | 26 |
lxc-create -n $CONTAINER -t natty -f $NET_CONF |
| 27 | 27 |
|
| 28 |
+if [ "$WARMCACHE" = "1" ]; then |
|
| 29 |
+ # Pre-cache files |
|
| 30 |
+ BASECACHE=/var/cache/lxc/natty/rootfs-amd64 |
|
| 31 |
+ chroot $BASECACHE apt-get update |
|
| 32 |
+ chroot $BASECACHE apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
|
| 33 |
+ chroot $BASECACHE pip install `cat pips/*` |
|
| 34 |
+fi |
|
| 35 |
+ |
|
| 28 | 36 |
# Where our container lives |
| 29 | 37 |
ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/ |
| 30 | 38 |
|
| 31 |
-# Copy over your ssh keys if desired |
|
| 32 |
-if [ $COPYENV ]; then |
|
| 39 |
+# Copy over your ssh keys and env if desired |
|
| 40 |
+if [ "$COPYENV" = "1" ]; then |
|
| 33 | 41 |
cp -pr ~/.ssh $ROOTFS/root/.ssh |
| 42 |
+ cp -p ~/.ssh/id_rsa.pub $ROOTFS/root/.ssh/authorized_keys |
|
| 34 | 43 |
cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig |
| 35 | 44 |
cp -pr ~/.vimrc $ROOTFS/root/.vimrc |
| 36 | 45 |
cp -pr ~/.bashrc $ROOTFS/root/.bashrc |
| ... | ... |
@@ -79,8 +91,10 @@ cp -pr $CACHEDIR/apt/* $ROOTFS/var/cache/apt/ |
| 79 | 79 |
cp -pr $CACHEDIR/pip/* $ROOTFS/var/cache/pip/ |
| 80 | 80 |
|
| 81 | 81 |
# Configure cgroup directory |
| 82 |
-mkdir -p /cgroup |
|
| 83 |
-mount none -t cgroup /cgroup |
|
| 82 |
+if [ ! -d /cgroup ] ; then |
|
| 83 |
+ mkdir -p /cgroup |
|
| 84 |
+ mount none -t cgroup /cgroup |
|
| 85 |
+fi |
|
| 84 | 86 |
|
| 85 | 87 |
# Start our container |
| 86 | 88 |
lxc-start -d -n $CONTAINER |