diff options
author | Diego Elio Pettenò <flameeyes@gentoo.org> | 2010-08-01 21:13:46 +0000 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@gentoo.org> | 2010-08-01 21:13:46 +0000 |
commit | de533e1bf0403014390e98ef2a2551be15214edd (patch) | |
tree | e20492cc03240e574d45eb69a30baa693e827fbd /app-emulation | |
parent | Patchset bump to fix bug #327191 for SH. (diff) | |
download | gentoo-2-de533e1bf0403014390e98ef2a2551be15214edd.tar.gz gentoo-2-de533e1bf0403014390e98ef2a2551be15214edd.tar.bz2 gentoo-2-de533e1bf0403014390e98ef2a2551be15214edd.zip |
New init script, with more thorough verification of the config, support for mounting the cgroup pseudo-fs, proper network dependencies, improved start-up (verifies that the container actually started up) and stop (won't waste time if the container was externally stopped).
(Portage version: 2.2_rc67/cvs/Linux x86_64)
Diffstat (limited to 'app-emulation')
-rw-r--r-- | app-emulation/lxc/ChangeLog | 11 | ||||
-rw-r--r-- | app-emulation/lxc/files/lxc.initd | 69 | ||||
-rw-r--r-- | app-emulation/lxc/lxc-0.7.2-r1.ebuild (renamed from app-emulation/lxc/lxc-0.7.2.ebuild) | 3 |
3 files changed, 70 insertions, 13 deletions
diff --git a/app-emulation/lxc/ChangeLog b/app-emulation/lxc/ChangeLog index 1f7c68870a8d..f774d4f261d2 100644 --- a/app-emulation/lxc/ChangeLog +++ b/app-emulation/lxc/ChangeLog @@ -1,6 +1,15 @@ # ChangeLog for app-emulation/lxc # Copyright 1999-2010 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/ChangeLog,v 1.14 2010/08/01 03:17:50 flameeyes Exp $ +# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/ChangeLog,v 1.15 2010/08/01 21:13:45 flameeyes Exp $ + +*lxc-0.7.2-r1 (01 Aug 2010) + + 01 Aug 2010; Diego E. Pettenò <flameeyes@gentoo.org> -lxc-0.7.2.ebuild, + +lxc-0.7.2-r1.ebuild, files/lxc.initd: + New init script, with more thorough verification of the config, support + for mounting the cgroup pseudo-fs, proper network dependencies, improved + start-up (verifies that the container actually started up) and stop (won't + waste time if the container was externally stopped). *lxc-0.7.2 (01 Aug 2010) diff --git a/app-emulation/lxc/files/lxc.initd b/app-emulation/lxc/files/lxc.initd index 99706980cb2d..78acc1400a3e 100644 --- a/app-emulation/lxc/files/lxc.initd +++ b/app-emulation/lxc/files/lxc.initd @@ -1,13 +1,17 @@ #!/sbin/runscript -# Copyright 1999-2010 Gentoo Foundation +# Copyright 2010-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/files/lxc.initd,v 1.1 2010/08/01 03:17:51 flameeyes Exp $ +# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/files/lxc.initd,v 1.2 2010/08/01 21:13:46 flameeyes Exp $ CONTAINER=${SVCNAME#*.} CONFIGFILE=${CONFIGFILE:-/etc/lxc/${CONTAINER}.conf} -depend() { - need net.lo localmount +lxc_get_var() { + awk 'BEGIN { FS="[ \t]*=[ \t]*" } $1 == "'$1'" { print $2; exit }' ${CONFIGFILE} +} + +cgroup_get_mount() { + mount | awk '$5 == "cgroup" { print $3; exit }' } checkconfig() { @@ -16,37 +20,81 @@ checkconfig() { eerror " ln -s lxc /etc/init.d/lxc.container" return 1 fi + + utsname=$(lxc_get_var lxc.utsname) + if [ ${CONTAINER} != ${utsname} ]; then + eerror "You should use the same name for the service and the" + eerror "container. Right now the container is called ${utsname}" + return 1 + fi } -rootpath() { - sed -n -e 's:^[ \t]*lxc.rootfs[ \t]*=[ \t]*\(.*\)$:\1:p' ${CONFIGFILE} +depend() { + # be quiet, since we have to run depend() also for the + # non-muxed init script, unfortunately. + checkconfig 2>/dev/null || return 0 + + config ${CONFIGFILE} + need localmount + + # find out which network interface the container is linked to, + # and then require that to be enabled, so that the + # dependencies are correct. + netif=$(lxc_get_var lxc.network.link) + [ -n "${netif}" ] && need net.${netif} } start() { checkconfig || return 1 + # make sure that cgroup is mounted if it isn't already, this + # ensures that we can actually proceed! + cgroupmount=$(cgroup_get_mount) + if [ -z ${cgroupmount} ]; then + mkdir -p /cgroup + + if ! mount -t cgroup cgroup /cgroup; then + eerror "Unable to mount cgroup pseudo-filesystem on /cgroup" + return 1 + fi + + cgroupmount=/cgroup + fi + rm /var/log/lxc/${CONTAINER}.log + rootpath=$(lxc_get_var lxc.rootfs) + # Check the format of our init and the chroot's init, to see if we # have to use linux32 or linux64… - case $(scanelf -BF '%M#f' /sbin/init $(rootpath)/sbin/init | tr '\n' ':') in + case $(scanelf -BF '%M#f' /sbin/init ${rootpath}/sbin/init | tr '\n' ':') in ELFCLASS64:ELFCLASS64:) setarch=;; ELFCLASS32:ELFCLASS32:) setarch=;; ELFCLASS32:ELFCLASS64:) setarch=linux64;; ELFCLASS64:ELFCLASS32:) setarch=linux32;; esac - mkdir -p /var/log/lxc - ebegin "Starting ${CONTAINER}" ${setarch} lxc-start -n ${CONTAINER} -f ${CONFIGFILE} -d -o /var/log/lxc/${CONTAINER}.log + sleep 0.5 + + # lxc-start -d will _always_ report a correct startup, even if it + # failed, so rather than trust that, check that the cgroup exists. + [ -d ${cgroupmount}/${CONTAINER} ] eend $? } stop() { checkconfig || return 1 - local init_pid=$(head -n1 /cgroup/${CONTAINER}/tasks) + cgroupmount=$(cgroup_get_mount) + + if ! [ -d ${cgroupmount}/${CONTAINER} ]; then + ewarn "${CONTAINER} doesn't seem to be started." + return 0 + fi + + init_pid=$(head -n1 ${cgroupmount}/${CONTAINER}/tasks) ebegin "Shutting down system in ${CONTAINER}" kill -INT ${init_pid} @@ -64,4 +112,3 @@ stop() { lxc-stop -n ${CONTAINER} eend $? } - diff --git a/app-emulation/lxc/lxc-0.7.2.ebuild b/app-emulation/lxc/lxc-0.7.2-r1.ebuild index ccf6066c7099..c7b0648486e5 100644 --- a/app-emulation/lxc/lxc-0.7.2.ebuild +++ b/app-emulation/lxc/lxc-0.7.2-r1.ebuild @@ -1,6 +1,6 @@ # Copyright 1999-2010 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/lxc-0.7.2.ebuild,v 1.1 2010/08/01 03:17:50 flameeyes Exp $ +# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/lxc-0.7.2-r1.ebuild,v 1.1 2010/08/01 21:13:45 flameeyes Exp $ EAPI="2" @@ -90,6 +90,7 @@ src_install() { # Gentoo-specific additions! newinitd "${FILESDIR}/${PN}.initd" ${PN} + keepdir /var/log/lxc } pkg_postinst() { |