summaryrefslogtreecommitdiffstats
path: root/main/lxc
diff options
context:
space:
mode:
Diffstat (limited to 'main/lxc')
-rw-r--r--main/lxc/0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch142
-rw-r--r--main/lxc/APKBUILD16
-rw-r--r--main/lxc/bb-rm.patch16
-rw-r--r--main/lxc/lxc.initd172
4 files changed, 246 insertions, 100 deletions
diff --git a/main/lxc/0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch b/main/lxc/0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch
new file mode 100644
index 000000000..50e6cccf1
--- /dev/null
+++ b/main/lxc/0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch
@@ -0,0 +1,142 @@
+From 3f3c1b2ad94338ba974477f53b2ee6f462aa77ae Mon Sep 17 00:00:00 2001
+From: Natanael Copa <ncopa@alpinelinux.org>
+Date: Tue, 13 Nov 2012 13:48:57 +0100
+Subject: [PATCH] lxc-start: add option -p, --pidfile=FILE for use with
+ --daemon
+
+Add option to create a pidfile for lxc-start daemon. This is helpful
+for init scripts and process monitors.
+
+Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
+---
+ doc/lxc-start.sgml.in | 12 ++++++++++++
+ src/lxc/arguments.h | 1 +
+ src/lxc/lxc_start.c | 24 ++++++++++++++++++++++++
+ 3 files changed, 37 insertions(+)
+
+diff --git a/doc/lxc-start.sgml.in b/doc/lxc-start.sgml.in
+index 2b6778f..bd875d6 100644
+--- a/doc/lxc-start.sgml.in
++++ b/doc/lxc-start.sgml.in
+@@ -53,6 +53,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ <arg choice="opt">-f <replaceable>config_file</replaceable></arg>
+ <arg choice="opt">-c <replaceable>console_file</replaceable></arg>
+ <arg choice="opt">-d</arg>
++ <arg choice="opt">-p <replaceable>pid_file</replaceable></arg>
+ <arg choice="opt">-s KEY=VAL</arg>
+ <arg choice="opt">-C</arg>
+ <arg choice="opt">command</arg>
+@@ -109,6 +110,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ <varlistentry>
+ <term>
++ <option>-p, --pidfile <replaceable>pid_file</replaceable></option>
++ </term>
++ <listitem>
++ <para>
++ Create a pidfile when running as daemon.
++ </para>
++ </listitem>
++ </varlistentry>
++
++ <varlistentry>
++ <term>
+ <option>-f, --rcfile <replaceable>config_file</replaceable></option>
+ </term>
+ <listitem>
+diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h
+index 40f0d6c..789ccd9 100644
+--- a/src/lxc/arguments.h
++++ b/src/lxc/arguments.h
+@@ -45,6 +45,7 @@ struct lxc_arguments {
+ int daemonize;
+ const char *rcfile;
+ const char *console;
++ const char *pidfile;
+
+ /* for lxc-checkpoint/restart */
+ const char *statefile;
+diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
+index 81a5774..a031ee1 100644
+--- a/src/lxc/lxc_start.c
++++ b/src/lxc/lxc_start.c
+@@ -62,6 +62,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
+ case 'f': args->rcfile = arg; break;
+ case 'C': args->close_all_fds = 1; break;
+ case 's': return lxc_config_define_add(&defines, arg);
++ case 'p': args->pidfile = arg; break;
+ }
+ return 0;
+ }
+@@ -72,6 +73,7 @@ static const struct option my_longopts[] = {
+ {"define", required_argument, 0, 's'},
+ {"console", required_argument, 0, 'c'},
+ {"close-all-fds", no_argument, 0, 'C'},
++ {"pidfile", required_argument, 0, 'p'},
+ LXC_COMMON_OPTIONS
+ };
+
+@@ -85,6 +87,7 @@ lxc-start start COMMAND in specified container NAME\n\
+ Options :\n\
+ -n, --name=NAME NAME for name of the container\n\
+ -d, --daemon daemonize the container\n\
++ -p, --pidfile=FILE Create pidfile when daemonized\n\
+ -f, --rcfile=FILE Load configuration file FILE\n\
+ -c, --console=FILE Set the file output for the container console\n\
+ -C, --close-all-fds If any fds are inherited, close them\n\
+@@ -95,6 +98,7 @@ Options :\n\
+ .parser = my_parser,
+ .checker = NULL,
+ .daemonize = 0,
++ .pidfile = NULL,
+ };
+
+ int main(int argc, char *argv[])
+@@ -200,6 +204,7 @@ int main(int argc, char *argv[])
+ }
+
+ if (my_args.daemonize) {
++ FILE *pid_fp;
+ /* do an early check for needed privs, since otherwise the
+ * user won't see the error */
+
+@@ -208,10 +213,26 @@ int main(int argc, char *argv[])
+ return err;
+ }
+
++ if (my_args.pidfile != NULL) {
++ pid_fp = fopen(my_args.pidfile, "w");
++ if (pid_fp == NULL) {
++ SYSERROR("failed to create '%s'", my_args.name);
++ return err;
++ }
++ }
++
+ if (daemon(0, 0)) {
+ SYSERROR("failed to daemonize '%s'", my_args.name);
+ return err;
+ }
++
++ if (my_args.pidfile != NULL) {
++ if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
++ SYSERROR("failed to write '%s'", my_args.pidfile);
++ return err;
++ }
++ fclose(pid_fp);
++ }
+ }
+
+ if (my_args.close_all_fds)
+@@ -230,6 +251,9 @@ int main(int argc, char *argv[])
+ err = -1;
+ }
+
++ if (my_args.daemonize && my_args.pidfile)
++ unlink(my_args.pidfile);
++
+ return err;
+ }
+
+--
+1.8.0
+
diff --git a/main/lxc/APKBUILD b/main/lxc/APKBUILD
index b275fad1f..1e7264513 100644
--- a/main/lxc/APKBUILD
+++ b/main/lxc/APKBUILD
@@ -1,7 +1,7 @@
# Contributor: William Pitcock <nenolod@dereferenced.org>
-# Maintainer: William Pitcock <nenolod@dereferenced.org>
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lxc
-pkgver=0.8.0_rc2
+pkgver=0.8.0
_mypkgver=${pkgver/_rc/-rc}
pkgrel=0
pkgdesc="linux containers - tools"
@@ -14,6 +14,8 @@ makedepends="$depends_dev"
install=""
subpackages="$pkgname-dev $pkgname-doc"
source="http://lxc.sourceforge.net/download/lxc/$pkgname-$_mypkgver.tar.gz
+ bb-rm.patch
+ 0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch
lxc.initd
setup-lxc-template
setup-lxc-guest
@@ -34,7 +36,9 @@ build() {
cd "$_builddir"
./configure --prefix=/usr \
--sysconfdir=/etc \
- --localstatedir=/var
+ --localstatedir=/var \
+ --disable-apparmor \
+ || reeturn 1
make || return 1
}
@@ -46,7 +50,9 @@ package() {
install -Dm755 "$srcdir"/setup-lxc-guest "$pkgdir"/usr/bin/setup-lxc-guest
}
-md5sums="9bd6988542fd7dd198d056ef3a2db9f6 lxc-0.8.0-rc2.tar.gz
-e66c3cf8e70168b07060746a4e65b671 lxc.initd
+md5sums="7304fa57146ce687f749b5df876bb20d lxc-0.8.0.tar.gz
+f0f675456a1751aded10aa428bda9e16 bb-rm.patch
+1bf081cd9d66c65f3611ed4af58ef48f 0001-lxc-start-add-option-p-pidfile-FILE-for-use-with-dae.patch
+3c80cb6623a93e942773d5f10cc983d3 lxc.initd
45d0f604310e58a1359f1745a4739843 setup-lxc-template
c3f7fd7e85d40c4a4b1b427048ff9652 setup-lxc-guest"
diff --git a/main/lxc/bb-rm.patch b/main/lxc/bb-rm.patch
new file mode 100644
index 000000000..b354d48c4
--- /dev/null
+++ b/main/lxc/bb-rm.patch
@@ -0,0 +1,16 @@
+diff --git a/src/lxc/lxc-destroy.in b/src/lxc/lxc-destroy.in
+index 846266c..f8f4b48 100644
+--- a/src/lxc/lxc-destroy.in
++++ b/src/lxc/lxc-destroy.in
+@@ -122,9 +122,9 @@ if [ -n "$rootdev" ]; then
+ btrfs subvolume delete "$rootdev"
+ else
+ # In case rootfs is not under $lxc_path/$lxc_name, remove it
+- rm -rf --one-file-system --preserve-root $rootdev
++ find $rootdev -xdev -delete
+ fi
+ fi
+ fi
+ # recursively remove the container to remove old container configuration
+-rm -rf --one-file-system --preserve-root $lxc_path/$lxc_name
++find $lxc_path/$lxc_name -xdev -delete
diff --git a/main/lxc/lxc.initd b/main/lxc/lxc.initd
index 86bae5f75..a77ba0e86 100644
--- a/main/lxc/lxc.initd
+++ b/main/lxc/lxc.initd
@@ -1,114 +1,96 @@
#!/sbin/runscript
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 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 $
+# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/files/lxc.initd.2,v 1.5 2012/07/21 05:07:15 flameeyes Exp $
CONTAINER=${SVCNAME#*.}
-CONFIGFILE=${CONFIGFILE:-/etc/lxc/${CONTAINER}.conf}
+command="/usr/bin/lxc-start"
+pidfile="/var/run/lxc/$CONTAINER.pid"
+extra_started_commands="reboot"
-lxc_get_var() {
- awk 'BEGIN { FS="[ \t]*=[ \t]*" } $1 == "'$1'" { print $2; exit }' ${CONFIGFILE}
+depend() {
+ need localmount
}
-cgroup_get_mount() {
- mount | awk '$5 == "cgroup" { print $3; exit }'
+lxc_get_configfile() {
+ if [ -f "/etc/lxc/${CONTAINER}.conf" ]; then
+ echo "/etc/lxc/${CONTAINER}.conf"
+ elif [ -f "/etc/lxc/${CONTAINER}/config" ]; then
+ echo "/etc/lxc/${CONTAINER}/config"
+ else
+ eerror "Unable to find a suitable configuration file."
+ eerror "If you set up the container in a non-standard"
+ eerror "location, please set the CONFIGFILE variable."
+ return 1
+ fi
}
-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
+lxc_get_var() {
+ awk 'BEGIN { FS="[ \t]*=[ \t]*" } $1 == "'$1'" { print $2; exit }' ${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}
+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
+ CONFIGFILE=${CONFIGFILE:-$(lxc_get_configfile)}
+
+ # no need to output anything, the function takes care of that.
+ [ -z "${CONFIGFILE}" ] && return 1
+
+ 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
}
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 $?
+ checkconfig || return 1
+ rm -f /var/log/lxc/${CONTAINER}.log
+
+ rootpath=$(lxc_get_var lxc.rootfs)
+ checkpath -d ${pidfile%/*}
+ ebegin "Starting ${CONTAINER}"
+ start-stop-daemon --start $command \
+ --pidfile $pidfile \
+ --wait 500 \
+ -- \
+ --daemon \
+ --pidfile $pidfile \
+ --name ${CONTAINER} \
+ --rcfile ${CONFIGFILE} \
+ --logpriority WARN \
+ --logfile /var/log/lxc/${CONTAINER}.log
+ 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
+ checkconfig || return 1
+
+ if ! [ -d /sys/fs/cgroup/cpuset/lxc/${CONTAINER} ]; then
+ ewarn "${CONTAINER} doesn't seem to be started."
+ return 0
+ fi
+
+ ebegin "Shutting down system in ${CONTAINER}"
+ start-stop-daemon --stop --pidfile ${pidfile} \
+ --retry ${POWEROFF_SIGNAL:-SIGUSR2}/${TIMEOUT:-30} \
+ --progress
+ eend $?
+
+ ebegin "Stopping ${CONTAINER}"
+ lxc-stop -n ${CONTAINER}
+ eend $?
+}
- ebegin "Stopping ${CONTAINER}"
- lxc-stop -n ${CONTAINER}
- eend $?
+reboot() {
+ checkconfig || return 1
+ ebegin "Sending reboot signal to $CONTAINER"
+ start-stop-daemon --signal ${RESTART_SIG:-SIGTERM} \
+ --pidfile ${pidfile}
+ eend $?
}