public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/openrc:master commit in: init.d/, sh/, etc/
@ 2011-11-20 20:24 William Hubbs
  0 siblings, 0 replies; only message in thread
From: William Hubbs @ 2011-11-20 20:24 UTC (permalink / raw
  To: gentoo-commits

commit:     d8bbeb184f462199582fa265c9b681288884ecd9
Author:     William Hubbs <williamh <AT> gentoo <DOT> org>
AuthorDate: Sun Nov 20 00:15:46 2011 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Sun Nov 20 20:07:46 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=d8bbeb18

CGroups: create the openrc cgroup hierarchy

Openrc will create a cgroup hierarchy called openrc which will have all
services it starts and all subsystems attached to it. If you need other
groups/hierarchies, please use libcgroup.

---
 etc/rc.conf.Linux             |    7 -------
 init.d/sysfs.in               |   15 +++++++++++++--
 sh/Makefile                   |    4 ++--
 sh/cgroup-release-agent.sh.in |   10 ++++++++++
 sh/runscript.sh.in            |   23 +++++++++++++----------
 5 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 963fc68..9b5859a 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -1,10 +1,3 @@
-# Set the control group for this service.
-# If you do not set this, the default setting is the value of
-# RC_SVCNAME.
-# This setting is ignored if you do not have CONFIG_CGROUPS active in
-# your kernel.
-# rc_cgroup="foo"
-
 ##############################################################################
 # LINUX SPECIFIC OPTIONS
 

diff --git a/init.d/sysfs.in b/init.d/sysfs.in
index a536d5f..d57c388 100644
--- a/init.d/sysfs.in
+++ b/init.d/sysfs.in
@@ -62,13 +62,24 @@ mount_misc()
 	fi
 
 	# Setup Kernel Support for cgroup
-	if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then
-		if grep -qs cgroup /proc/filesystems; then
+	if [ -d /sys/fs/cgroup ]; then
+		if grep -qs cgroup /proc/filesystems && \
+			! mountinfo -q /sys/fs/cgroup; then
 			ebegin "Mounting cgroup filesystem"
 			mount -n -t tmpfs -o  nodev,noexec,nosuid \
 				cgroup /sys/fs/cgroup
 			eend $?
 		fi
+		if ! mountinfo -q /sys/fs/cgroup/openrc; then
+			ebegin "creating openrc control group"
+			mkdir /sys/fs/cgroup/openrc
+			mount -n -t cgroup -o  nodev,noexec,nosuid \
+				openrc /sys/fs/cgroup/openrc
+			echo 1 > /sys/fs/cgroup/openrc/notify_on_release
+			echo @LIBEXECDIR@/sh/cgroup-release-agent.sh \
+				> /sys/fs/cgroup/openrc/release_agent
+			eend
+		fi
 	fi
 }
 

diff --git a/sh/Makefile b/sh/Makefile
index f714780..15b24d0 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -12,8 +12,8 @@ include ${MK}/os.mk
 SRCS-FreeBSD=
 BIN-FreeBSD=
 
-SRCS-Linux=	init-early.sh.in udhcpc-hook.sh.in
-BIN-Linux=	init-early.sh udhcpc-hook.sh
+SRCS-Linux=	cgroup-release-agent.sh.in init-early.sh.in udhcpc-hook.sh.in
+BIN-Linux=	cgroup-release-agent.sh init-early.sh udhcpc-hook.sh
 
 SRCS-NetBSD=	ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in
 BIN-NetBSD=	ifwatchd-carrier.sh ifwatchd-nocarrier.sh

diff --git a/sh/cgroup-release-agent.sh.in b/sh/cgroup-release-agent.sh.in
new file mode 100644
index 0000000..c3174fe
--- /dev/null
+++ b/sh/cgroup-release-agent.sh.in
@@ -0,0 +1,10 @@
+#!@SHELL@
+#
+# This is run by the kernel after the last task is removed from a
+# control group in the openrc hierarchy.
+
+cgroup=/sys/fs/cgroup/openrc
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+if [ -d ${cgroup}/$1 ]; then
+	rmdir ${cgroup}/$1
+fi

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 706a1f7..4032cb8 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -148,6 +148,19 @@ start()
 		service_inactive && _inactive=true
 		mark_service_inactive
 	fi
+	if [ "$RC_UNAME" = Linux ]; then
+		local cgroup=/sys/fs/cgroup/openrc
+		local svc_cgroup=${cgroup}/${RC_SVCNAME}
+		if mountinfo -q ${cgroup}; then
+			mkdir ${svc_cgroup}
+			for f in cpuset.cpus cpuset.mems; do
+					if [ -f ${cgroup}/${f} ]; then
+							cp ${cgroup}/${f} ${svc_cgroup}
+						fi
+					done
+			echo $$ > ${svc_cgroup}/tasks
+		fi
+	fi
 	eval start-stop-daemon --start \
 		--exec $command \
 		${procname:+--name} $procname \
@@ -189,16 +202,6 @@ fi
 # Load any system overrides
 sourcex -e "@SYSCONFDIR@/rc.conf"
 
-# Attach to CGroup - dir existing is enough for us
-if [ -d /sys/fs/cgroup -a -n "${rc_cgroup}" ]; then
-	if [ -d /sys/fs/cgroup/${rc_cgroup} ]; then
-		# attach self to cgroup - any children of this process will inherit this
-		echo $$ > /sys/fs/cgroup/${rc_cgroup}/tasks
-	else
-		eerror "Control group /sys/fs/cgroup/${rc_cgroup} does not exist."
-	fi
-fi
-
 # Apply any ulimit defined
 [ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
 



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-11-20 20:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-20 20:24 [gentoo-commits] proj/openrc:master commit in: init.d/, sh/, etc/ William Hubbs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox