summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Shvetsov <alexxy@gentoo.org>2019-04-22 17:48:41 +0300
committerAlexey Shvetsov <alexxy@gentoo.org>2019-04-22 17:48:41 +0300
commit681c0364b0b3877c811e0db49bf4c55d7103d1cd (patch)
tree92aa780f67312faa783d1a40868223dcf40f7274 /app-emulation/lxc
parentapp-crypt/gpgme: stable 1.13.0 for sparc, bug #682352 (diff)
downloadgentoo-681c0364b0b3877c811e0db49bf4c55d7103d1cd.tar.gz
gentoo-681c0364b0b3877c811e0db49bf4c55d7103d1cd.tar.bz2
gentoo-681c0364b0b3877c811e0db49bf4c55d7103d1cd.zip
app-emulation/lxc: Fix init.d
Closes: https://bugs.gentoo.org/675540 Package-Manager: Portage-2.3.64, Repoman-2.3.12 Signed-off-by: Alexey Shvetsov <alexxy@gentoo.org>
Diffstat (limited to 'app-emulation/lxc')
-rw-r--r--app-emulation/lxc/files/lxc.initd.8131
-rw-r--r--app-emulation/lxc/lxc-3.1.0-r1.ebuild (renamed from app-emulation/lxc/lxc-3.1.0.ebuild)4
2 files changed, 133 insertions, 2 deletions
diff --git a/app-emulation/lxc/files/lxc.initd.8 b/app-emulation/lxc/files/lxc.initd.8
new file mode 100644
index 000000000000..727f6d504fb3
--- /dev/null
+++ b/app-emulation/lxc/files/lxc.initd.8
@@ -0,0 +1,131 @@
+#!/sbin/openrc-run
+# Copyright 1999-2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+CONTAINER=${SVCNAME#*.}
+
+LXC_PATH=`lxc-config lxc.lxcpath`
+
+lxc_get_configfile() {
+ if [ -f "${LXC_PATH}/${CONTAINER}.conf" ]; then
+ echo "${LXC_PATH}/${CONTAINER}.conf"
+ elif [ -f "${LXC_PATH}/${CONTAINER}/config" ]; then
+ echo "${LXC_PATH}/${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
+}
+
+[ $CONTAINER != $SVCNAME ] && CONFIGFILE=${CONFIGFILE:-$(lxc_get_configfile)}
+
+lxc_get_var() {
+ awk 'BEGIN { FS="[ \t]*=[ \t]*" } $1 == "'$1'" { print $2; exit }' ${CONFIGFILE}
+}
+
+lxc_get_net_link_type() {
+ awk 'BEGIN { FS="[ \t]*=[ \t]*"; _link=""; _type="" }
+ $1 == "lxc.network.type" {_type=$2;}
+ $1 == "lxc.network.link" {_link=$2;}
+ match($1, /lxc\.net\.[[:digit:]]+\.type/) {_type=$2;}
+ match($1, /lxc\.net\.[[:digit:]]+\.link/) {_link=$2;}
+ {if(_link != "" && _type != ""){
+ printf("%s:%s\n", _link, _type );
+ _link=""; _type="";
+ }; }' <${CONFIGFILE}
+}
+
+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
+
+ # no need to output anything, the function takes care of that.
+ [ -z "${CONFIGFILE}" ] && return 1
+
+ utsname=$(lxc_get_var lxc.uts.name)
+ if [ -z "$utsname" ] ; then
+ utsname=$(lxc_get_var lxc.utsname)
+ fi
+
+ 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
+ use lxcfs
+
+ local _x _if
+ for _x in $(lxc_get_net_link_type); do
+ _if=${_x%:*}
+ case "${_x##*:}" in
+ # when the network type is set to phys, we can make use of a
+ # network service (for instance to set it up before we disable
+ # the net_admin capability), but we might also not set it up
+ # at all on the host and leave the net_admin capable service
+ # to take care of it.
+ phys) use net.${_if} ;;
+ *) need net.${_if} ;;
+ esac
+ done
+}
+
+start() {
+ checkconfig || return 1
+ rm -f /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; always use setarch
+ # when required, as that makes it easier to deal with
+ # x32-based containers.
+ case $(scanelf -BF '%a#f' ${rootpath}/sbin/init) in
+ EM_X86_64) setarch=linux64;;
+ EM_386) setarch=linux32;;
+ esac
+
+ ebegin "Starting LXC container ${CONTAINER}"
+ env -i ${setarch} $(which lxc-start) -n ${CONTAINER} -f ${CONFIGFILE} -d -o /var/log/lxc/${CONTAINER}.log
+ sleep 1
+
+ # lxc-start -d will _always_ report a correct startup, even if it
+ # failed, so rather than trust that, check that the cgroup exists.
+ # fix for LXC 3.1
+
+ STATE="$(lxc-info -s -H ${CONTAINER})"
+ [ "$STATE" = "RUNNING" ]
+
+ eend $?
+}
+
+stop() {
+ checkconfig || return 1
+
+ STATE="$(lxc-info -s -H ${CONTAINER})"
+
+ if ! [ "$STATE" = "RUNNING" ]; then
+ ewarn "${CONTAINER} doesn't seem to be started."
+ return 0
+ fi
+
+ # 30s should be enough to shut everything down
+ # lxc-stop will return back anyway as soon as successful shutdown
+ # after 30s, lxc-stop sends SIGKILL (dirty shotdown)
+ ebegin "Stopping LXC container ${CONTAINER}"
+ lxc-stop -t 30 -n ${CONTAINER}
+ eend $?
+}
diff --git a/app-emulation/lxc/lxc-3.1.0.ebuild b/app-emulation/lxc/lxc-3.1.0-r1.ebuild
index 29c023f65277..abe9c6c7cb4f 100644
--- a/app-emulation/lxc/lxc-3.1.0.ebuild
+++ b/app-emulation/lxc/lxc-3.1.0-r1.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2018 Gentoo Authors
+# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
@@ -134,7 +134,7 @@ src_install() {
find "${D}" -name '*.la' -delete
# Gentoo-specific additions!
- newinitd "${FILESDIR}/${PN}.initd.7" ${PN}
+ newinitd "${FILESDIR}/${PN}.initd.8" ${PN}
# Remember to compare our systemd unit file with the upstream one
# config/init/systemd/lxc.service.in