Package: lxc
Version: 0.7.5-24
Severity: wishlist
Hi,
This is just a proposal. I started to organize the services in containers on
two servers (node B as cold standby).
When switching from node A to node B, I like to have a very basic check, if the
container is already active on the other node.
A simple test might be:
ping static IP address and start if address is not pingable
Therefore I attached a little patch, which reads a property from the containers
config file and evaluates the condition before starting up a container.
content of config file may look like the following (including other use cases):
# do only start if my designated IP is not pingable
lifecycle.startupcondition = $({ ping -i 2 -w 4 192.168.1.200 >/dev/null; echo
$?; }) = 1
# do only start if IP of my virbr0 device is pingable
lifecycle.startupcondition = $({ ping -i 2 -w 4 192.168.122.1 >/dev/null; echo
$?; }) = 0
# do only start if trigger file exists
lifecycle.startupcondition = $({ [ -f /root/I_AM_MASTER ] >/dev/null; echo $?;
}) = 0
I tried to put it into the wrapper, but the initd script doesn't use the
wrapper for starting (maybe because the wrapper does not pass arguments to lxc-
start and ought to be simple).
Regards,
Marcus
btw: I wasn't able to clone the git repo at http://sources.progress-
linux.org/gitweb/?p=users/daniel/packages/lxc.git;a=shortlog;h=refs/heads/debian
neither by http nor by git directly. Other repos work. So the patch is diffed
against lxc 0.7.5-24 deb package.
-- System Information:
Debian Release: 6.0.4
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 3.2.0-0.bpo.2-amd64 (SMP w/1 CPU core)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages lxc depends on:
ii debconf [debconf-2.0] 1.5.36.1 Debian configuration management sy
ii libc6 2.11.3-2 Embedded GNU C Library: Shared lib
ii libcap2 1:2.19-3 support for getting/setting POSIX.
Versions of packages lxc recommends:
ii debootstrap 1.0.26+squeeze1 Bootstrap a basic Debian system
ii libcap2-bin 1:2.19-3 basic utility programs for using c
Versions of packages lxc suggests:
pn lxctl <none> (no description available)
-- debconf information:
lxc/shutdown: stop
lxc/directory: /var/lib/lxc
--- /etc/init.d/lxc 2012-02-03 22:27:16.000000000 +0100
+++ lxc.init 2012-04-24 19:44:43.000000000 +0200
@@ -69,11 +69,21 @@
;;
esac
+ # conditional start
+ STARTCOND=$(grep
"^\s*\t*lifecycle.startupcondition" \
+ ${_CONFIG} | sed -e 's|^[^=]*=\s*||')
+ [ -z "$STARTCOND" ] && STARTCOND="true=true"
+
if ! lxc-info -n ${_CONTAINER} 2>&1 | grep -qs
"RUNNING"
then
log_progress_msg "${_CONTAINER}"
-
- lxc-${_PROGRAM} -n ${_CONTAINER} -f
${_CONFIG} -d
+ if eval test $STARTCOND
+ then
+ log_progress_msg
"Startcondition evaluated to true."
+ lxc-${_PROGRAM} -n
${_CONTAINER} -f ${_CONFIG} -d
+ else
+ log_progress_msg
"Startcondition did NOT evaluate to true. ${_CONTAINER} (skip)"
+ fi
else
log_progress_msg "${_CONTAINER} (skip)"
fi