aboutsummaryrefslogtreecommitdiffstats
path: root/main/lxc/lxc.initd
diff options
context:
space:
mode:
authorStuart Cardall <developer@it-offshore.co.uk>2017-11-13 01:41:04 +0000
committerJakub Jirutka <jakub@jirutka.cz>2017-11-26 01:17:35 +0100
commit41dbf71a6f4eb9a2be1bca68f0270e97bd52b77f (patch)
tree7f15ca4de4b52249efffe0d58a69efc866679fae /main/lxc/lxc.initd
parentf55cfeb9c139bce7dcde2d1ecae902d9e7019ada (diff)
main/lxc: fix running systemd based containers under OpenRC
* systemd based containers require the /sys/fs/cgroup/systemd cgroup for lxc-console and services inside the containers to work * systemd_ctr() based on recommendations from lxc: https://github.com/lxc/lxc/issues/1704#issuecomment-330935480 Committer note: I did few minor modifications.
Diffstat (limited to 'main/lxc/lxc.initd')
-rw-r--r--main/lxc/lxc.initd37
1 files changed, 35 insertions, 2 deletions
diff --git a/main/lxc/lxc.initd b/main/lxc/lxc.initd
index 7d39817944d..26ddaed5f06 100644
--- a/main/lxc/lxc.initd
+++ b/main/lxc/lxc.initd
@@ -3,10 +3,17 @@
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-emulation/lxc/files/lxc.initd.2,v 1.5 2012/07/21 05:07:15 flameeyes Exp $
+extra_started_commands="reboot"
+
+description="Linux Containers (LXC)"
+description_reboot="Reboot containers"
+
CONTAINER=${SVCNAME#*.}
+: ${lxc_group:=$LXC_GROUP}
+: ${systemd_container:=no}
+
command="/usr/bin/lxc-start"
pidfile="/var/run/lxc/$CONTAINER.pid"
-extra_started_commands="reboot"
depend() {
need localmount sysfs
@@ -51,15 +58,39 @@ checkconfig() {
fi
}
+systemd_ctr() {
+ local cmd="$1"
+ # Required for lxc-console and services inside systemd containers.
+ local cgroup=/sys/fs/cgroup/systemd
+ local mnt_opts='rw,nosuid,nodev,noexec,relatime,none,name=systemd'
+
+ case "$cmd" in
+ mount)
+ checkpath -d $cgroup
+ if ! mount | grep $cgroup >/dev/null; then
+ mount -t cgroup -o $mnt_opts cgroup $cgroup
+ fi
+ ;;
+ unmount)
+ if mount | grep $cgroup >/dev/null; then
+ umount $cgroup
+ fi
+ ;;
+ esac
+}
+
_autostart() {
ebegin "$1 LXC containers"
shift
- lxc-autostart --group "${LXC_GROUP:-onboot,}" "$@"
+ lxc-autostart --group "$lxc_group" "$@"
eend $?
}
start() {
checkconfig || return 1
+ if yesno "$systemd_container"; then
+ systemd_ctr mount
+ fi
if [ -z "$CONTAINER" ]; then
_autostart "Starting"
return
@@ -97,6 +128,8 @@ start() {
stop() {
checkconfig || return 1
+ systemd_ctr unmount
+
if [ -z "$CONTAINER" ]; then
_autostart "Stopping" --shutdown --timeout ${LXC_TIMEOUT:-30}
return