From de533e1bf0403014390e98ef2a2551be15214edd Mon Sep 17 00:00:00 2001 From: Diego Elio Pettenò Date: Sun, 1 Aug 2010 21:13:46 +0000 Subject: 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) --- app-emulation/lxc/ChangeLog | 11 +++- app-emulation/lxc/files/lxc.initd | 69 ++++++++++++++++++---- app-emulation/lxc/lxc-0.7.2-r1.ebuild | 108 ++++++++++++++++++++++++++++++++++ app-emulation/lxc/lxc-0.7.2.ebuild | 107 --------------------------------- 4 files changed, 176 insertions(+), 119 deletions(-) create mode 100644 app-emulation/lxc/lxc-0.7.2-r1.ebuild delete mode 100644 app-emulation/lxc/lxc-0.7.2.ebuild (limited to 'app-emulation') 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ò -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-r1.ebuild b/app-emulation/lxc/lxc-0.7.2-r1.ebuild new file mode 100644 index 000000000000..c7b0648486e5 --- /dev/null +++ b/app-emulation/lxc/lxc-0.7.2-r1.ebuild @@ -0,0 +1,108 @@ +# 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-r1.ebuild,v 1.1 2010/08/01 21:13:45 flameeyes Exp $ + +EAPI="2" + +inherit eutils linux-info versionator base + +DESCRIPTION="LinuX Containers userspace utilities" +HOMEPAGE="http://lxc.sourceforge.net/" +SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz" + +KEYWORDS="~amd64 ~x86" + +LICENSE="LGPL-3" +SLOT="0" +IUSE="doc examples vanilla" + +RDEPEND="sys-libs/libcap" + +DEPEND="${RDEPEND} + doc? ( app-text/docbook-sgml-utils ) + >=sys-kernel/linux-headers-2.6.29" + +# For init script, so protect with vanilla, they are not strictly +# needed. +RDEPEND="${RDEPEND} + vanilla? ( + sys-apps/util-linux + app-misc/pax-utils + )" + +CONFIG_CHECK="~CGROUPS + ~CGROUP_NS ~CPUSETS ~CGROUP_CPUACCT + ~RESOURCE_COUNTERS ~CGROUP_MEM_RES_CTLR + ~CGROUP_SCHED + + ~NAMESPACES + ~IPC_NS ~USER_NS ~PID_NS + + ~DEVPTS_MULTIPLE_INSTANCES + ~CGROUP_FREEZER + ~UTS_NS ~NET_NS + ~VETH ~MACVLAN" + +ERROR_DEVPTS_MULTIPLE_INSTANCES="CONFIG_DEVPTS_MULTIPLE_INSTANCES: needed for pts inside container" + +ERROR_CGROUP_FREEZER="CONFIG_CGROUP_FREEZER: needed to freeze containers" + +ERROR_UTS_NS="CONFIG_UTS_NS: needed to unshare hostnames and uname info" +ERROR_NET_NS="CONFIG_NET_NS: needed for unshared network" + +ERROR_VETH="CONFIG_VETH: needed for internal (inter-container) networking" +ERROR_MACVLAN="CONFIG_MACVLAN: needed for internal (inter-container) networking" + +src_configure() { + econf \ + --localstatedir=/var \ + --bindir=/usr/sbin \ + --docdir=/usr/share/doc/${PF} \ + --with-config-path=/etc/lxc \ + $(use_enable doc) \ + $(use_enable examples) \ + || die "configure failed" +} + +src_install() { + emake DESTDIR="${D}" install || die "install failed" + + dodoc AUTHORS CONTRIBUTING MAINTAINERS \ + NEWS TODO README doc/FAQ.txt || die "dodoc failed" + + # If the documentation is going to be rebuilt, the Makefiles will + # install the man pages themselves; if we're not going to, we + # still need to install them, as they are provided with the + # tarball in recent versions. + if ! use doc; then + doman doc/*.{1,5,7} || die + fi + + rm -r "${D}"/usr/sbin/lxc-{setcap,ls} \ + "${D}"/usr/share/man/man1/lxc-ls.1 \ + || die "unable to remove extraenous content" + + keepdir /etc/lxc + + find "${D}" -name '*.la' -delete + + use vanilla && return 0 + + # Gentoo-specific additions! + newinitd "${FILESDIR}/${PN}.initd" ${PN} + keepdir /var/log/lxc +} + +pkg_postinst() { + if ! use vanilla; then + elog "There is an init script provided with the package now; no documentation" + elog "is currently available though, so please check out /etc/init.d/lxc ." + elog "You _should_ only need to symlink it to /etc/init.d/lxc.configname" + elog "to start the container defined into /etc/lxc/configname.conf ." + elog "For further information about LXC development see" + elog "http://blog.flameeyes.eu/tag/lxc" # remove once proper doc is available + elog "" + fi + ewarn "To use the lxc-debian and lxc-fedora commands, you need respectively" + ewarn "dev-util/debootstrap and sys-apps/yum." +} diff --git a/app-emulation/lxc/lxc-0.7.2.ebuild b/app-emulation/lxc/lxc-0.7.2.ebuild deleted file mode 100644 index ccf6066c7099..000000000000 --- a/app-emulation/lxc/lxc-0.7.2.ebuild +++ /dev/null @@ -1,107 +0,0 @@ -# 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 $ - -EAPI="2" - -inherit eutils linux-info versionator base - -DESCRIPTION="LinuX Containers userspace utilities" -HOMEPAGE="http://lxc.sourceforge.net/" -SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz" - -KEYWORDS="~amd64 ~x86" - -LICENSE="LGPL-3" -SLOT="0" -IUSE="doc examples vanilla" - -RDEPEND="sys-libs/libcap" - -DEPEND="${RDEPEND} - doc? ( app-text/docbook-sgml-utils ) - >=sys-kernel/linux-headers-2.6.29" - -# For init script, so protect with vanilla, they are not strictly -# needed. -RDEPEND="${RDEPEND} - vanilla? ( - sys-apps/util-linux - app-misc/pax-utils - )" - -CONFIG_CHECK="~CGROUPS - ~CGROUP_NS ~CPUSETS ~CGROUP_CPUACCT - ~RESOURCE_COUNTERS ~CGROUP_MEM_RES_CTLR - ~CGROUP_SCHED - - ~NAMESPACES - ~IPC_NS ~USER_NS ~PID_NS - - ~DEVPTS_MULTIPLE_INSTANCES - ~CGROUP_FREEZER - ~UTS_NS ~NET_NS - ~VETH ~MACVLAN" - -ERROR_DEVPTS_MULTIPLE_INSTANCES="CONFIG_DEVPTS_MULTIPLE_INSTANCES: needed for pts inside container" - -ERROR_CGROUP_FREEZER="CONFIG_CGROUP_FREEZER: needed to freeze containers" - -ERROR_UTS_NS="CONFIG_UTS_NS: needed to unshare hostnames and uname info" -ERROR_NET_NS="CONFIG_NET_NS: needed for unshared network" - -ERROR_VETH="CONFIG_VETH: needed for internal (inter-container) networking" -ERROR_MACVLAN="CONFIG_MACVLAN: needed for internal (inter-container) networking" - -src_configure() { - econf \ - --localstatedir=/var \ - --bindir=/usr/sbin \ - --docdir=/usr/share/doc/${PF} \ - --with-config-path=/etc/lxc \ - $(use_enable doc) \ - $(use_enable examples) \ - || die "configure failed" -} - -src_install() { - emake DESTDIR="${D}" install || die "install failed" - - dodoc AUTHORS CONTRIBUTING MAINTAINERS \ - NEWS TODO README doc/FAQ.txt || die "dodoc failed" - - # If the documentation is going to be rebuilt, the Makefiles will - # install the man pages themselves; if we're not going to, we - # still need to install them, as they are provided with the - # tarball in recent versions. - if ! use doc; then - doman doc/*.{1,5,7} || die - fi - - rm -r "${D}"/usr/sbin/lxc-{setcap,ls} \ - "${D}"/usr/share/man/man1/lxc-ls.1 \ - || die "unable to remove extraenous content" - - keepdir /etc/lxc - - find "${D}" -name '*.la' -delete - - use vanilla && return 0 - - # Gentoo-specific additions! - newinitd "${FILESDIR}/${PN}.initd" ${PN} -} - -pkg_postinst() { - if ! use vanilla; then - elog "There is an init script provided with the package now; no documentation" - elog "is currently available though, so please check out /etc/init.d/lxc ." - elog "You _should_ only need to symlink it to /etc/init.d/lxc.configname" - elog "to start the container defined into /etc/lxc/configname.conf ." - elog "For further information about LXC development see" - elog "http://blog.flameeyes.eu/tag/lxc" # remove once proper doc is available - elog "" - fi - ewarn "To use the lxc-debian and lxc-fedora commands, you need respectively" - ewarn "dev-util/debootstrap and sys-apps/yum." -} -- cgit v1.2.3-65-gdbad