aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2015-04-28 15:07:21 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2015-05-01 09:04:07 -0500
commitc709e6077c6eda3f4f7e7222298213413254ee0f (patch)
tree3cf552342888f64b12a41fc462c0715f3012fd2a
parenta27d577da8cf4f1c7f9784a043ecf02d71a81ca6 (diff)
Add support for systemd-nspawn containers
This adds support for running OpenRC in a container created by the systemd-nspawn utility. This fixes #52. X-Gentoo-Bug: 548058 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=548058
-rw-r--r--etc/rc.conf.Linux17
-rw-r--r--sh/openrc-run.sh.in5
-rw-r--r--src/librc/librc.c2
-rw-r--r--src/librc/rc.h.in1
4 files changed, 16 insertions, 9 deletions
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 79bd9713..a8ad58b1 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -2,14 +2,15 @@
# LINUX SPECIFIC OPTIONS
# This is the subsystem type. Valid options on Linux:
-# "" - nothing special
-# "lxc" - Linux Containers
-# "openvz" - Linux OpenVZ
-# "prefix" - Prefix
-# "uml" - Usermode Linux
-# "vserver" - Linux vserver
-# "xen0" - Xen0 Domain
-# "xenU" - XenU Domain
+# "" - nothing special
+# "lxc" - Linux Containers
+# "openvz" - Linux OpenVZ
+# "prefix" - Prefix
+# "uml" - Usermode Linux
+# "vserver" - Linux vserver
+# "systemd-nspawn" - Container created by the systemd-nspawn utility
+# "xen0" - Xen0 Domain
+# "xenU" - XenU Domain
# If this is commented out, automatic detection will be used.
#
# This should be set to the value representing the environment this file is
diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index a6d2c0b8..e279f116 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -34,7 +34,10 @@ sourcex()
sourcex "@LIBEXECDIR@/sh/functions.sh"
sourcex "@LIBEXECDIR@/sh/rc-functions.sh"
-[ "$RC_SYS" != "PREFIX" ] && sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh"
+case $RC_SYS in
+ PREFIX|SYSTEMD-NSPAWN) ;;
+ *) sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh";;
+esac
# Support LiveCD foo
if sourcex -e "/sbin/livecd-functions.sh"; then
diff --git a/src/librc/librc.c b/src/librc/librc.c
index ca51aa61..03448e79 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -294,6 +294,8 @@ rc_sys_v1(void)
return RC_SYS_OPENVZ; /* old test */
else if (file_regex("/proc/1/environ", "container=lxc"))
return RC_SYS_LXC;
+ else if (file_regex("/proc/1/environ", "container=systemd-nspawn"))
+ return RC_SYS_SYSTEMD_NSPAWN;
#endif
return NULL;
diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 58d8eb57..13e1b5b9 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -332,6 +332,7 @@ bool rc_service_daemons_crashed(const char *);
#define RC_SYS_OPENVZ "OPENVZ"
#define RC_SYS_LXC "LXC"
#define RC_SYS_PREFIX "PREFIX"
+#define RC_SYS_SYSTEMD_NSPAWN "SYSTEMD-NSPAWN"
#define RC_SYS_UML "UML"
#define RC_SYS_VSERVER "VSERVER"
#define RC_SYS_XEN0 "XEN0"