Saturday 30 April 2011

LXC on Debian Squeeze

We've been using Linux Containers for a couple of weeks now to run our continuous integration environment and a bunch of other servers. Setting up containers is pretty easy but I found I was always doing the same post-configuration tasks again and again. So I wrapped them up:
mkdir /var/lib/lxc/jenkins01
lxc-debian -p /var/lib/lxc/jenkins01
lxc-post-config jenkins01 192.168.0.30

Now the container starts when the host starts up, sets the network settings to a static IP and shuts down nicely (init 0) when it receives a signal from the host. You need to configure your host to send a PWR signal to each container from your /etc/init.d/lxc and wait for it to shutdown. Just insert the following into the stop sections:
for i in `pidof lxc-start`; do kill -PWR $i; done; sleep 30
At the moment the script assumes that you sit on a 192.168.0.0/8 network but I'll get round to changing that. I'm also assuming that you're using some kind of distribution based on Debian Squeeze.

You can grab the script from https://github.com/shin-nien/lxc-tools/raw/master/lxc-post-config

No comments:

Post a Comment