summaryrefslogtreecommitdiffstats
path: root/testing/lxc
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-03-21 20:22:08 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2011-03-21 20:22:08 +0000
commitb2debab5a57c76adff79049ff47fe06a434b25de (patch)
tree7a7ec1ab8aeddc453f16860a592a71058856847b /testing/lxc
parent84349021dcf0ad20fa990e06868e2ee252c3ca56 (diff)
downloadaports-b2debab5a57c76adff79049ff47fe06a434b25de.tar.bz2
aports-b2debab5a57c76adff79049ff47fe06a434b25de.tar.xz
testing/lxc: add init.d script from gentoo
Diffstat (limited to 'testing/lxc')
-rw-r--r--testing/lxc/APKBUILD9
-rw-r--r--testing/lxc/lxc.initd114
2 files changed, 120 insertions, 3 deletions
diff --git a/testing/lxc/APKBUILD b/testing/lxc/APKBUILD
index 95856e1d0..042ae13c0 100644
--- a/testing/lxc/APKBUILD
+++ b/testing/lxc/APKBUILD
@@ -3,7 +3,7 @@
pkgname=lxc
pkgver=0.7.4
_mypkgver=${pkgver/_rc/-rc}
-pkgrel=1
+pkgrel=2
pkgdesc="linux containers - tools"
url="http://lxc.sourceforge.net/"
arch="all"
@@ -13,7 +13,8 @@ depends_dev="libcap-dev"
makedepends="$depends_dev"
install=""
subpackages="$pkgname-dev $pkgname-doc"
-source="http://lxc.sourceforge.net/download/lxc/$pkgname-$_mypkgver.tar.gz"
+source="http://lxc.sourceforge.net/download/lxc/$pkgname-$_mypkgver.tar.gz
+ lxc.initd"
_builddir="${srcdir}/${pkgname}-${_mypkgver}"
prepare() {
@@ -37,6 +38,8 @@ build() {
package() {
cd "$_builddir"
make DESTDIR="$pkgdir" install || return 1
+ install -Dm755 "$srcdir"/lxc.initd "$pkgdir"/etc/init.d/lxc
}
-md5sums="51bb5d7d9d22e2c98490aed47fc02ad9 lxc-0.7.4.tar.gz"
+md5sums="51bb5d7d9d22e2c98490aed47fc02ad9 lxc-0.7.4.tar.gz
+e66c3cf8e70168b07060746a4e65b671 lxc.initd"
diff --git a/testing/lxc/lxc.initd b/testing/lxc/lxc.initd
new file mode 100644
index 000000000..86bae5f75
--- /dev/null
+++ b/testing/lxc/lxc.initd
@@ -0,0 +1,114 @@
+#!/sbin/runscript
+# Copyright 1999-2011 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.3 2011/02/26 18:02:51 flameeyes Exp $
+
+CONTAINER=${SVCNAME#*.}
+CONFIGFILE=${CONFIGFILE:-/etc/lxc/${CONTAINER}.conf}
+
+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() {
+ if [ ${CONTAINER} = ${SVCNAME} ]; then
+ eerror "You have to create an init script for each container:"
+ 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
+}
+
+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
+ ELFCLASS64:ELFCLASS64:) setarch=;;
+ ELFCLASS32:ELFCLASS32:) setarch=;;
+ ELFCLASS32:ELFCLASS64:) setarch=linux64;;
+ ELFCLASS64:ELFCLASS32:) setarch=linux32;;
+ esac
+
+ ebegin "Starting ${CONTAINER}"
+ ${setarch} lxc-start -l WARN -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
+
+ 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}
+ eend $?
+
+ sleep 15
+
+ missingprocs=$(pgrep -P ${init_pid})
+
+ if [ -n "${missingprocs}" ]; then
+ ewarn "Something failed to properly shut down in ${CONTAINER}"
+ fi
+
+ ebegin "Stopping ${CONTAINER}"
+ lxc-stop -n ${CONTAINER}
+ eend $?
+}