summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Lauer <patrick@gentoo.org>2011-11-12 22:19:55 +0100
committerWilliam Hubbs <williamh@gentoo.org>2011-11-17 16:22:59 -0600
commit20df56f0b2a01bd2f8a70b8fb3fbd051c1aab8d8 (patch)
tree0b11c534d13cf24ca5efe1ff47642f7d64bbd0ca
parent66e99b6d637edc33047398b467f2b22bc2f04b60 (diff)
downloadopenrc-20df56f0b2a01bd2f8a70b8fb3fbd051c1aab8d8.tar.gz
openrc-20df56f0b2a01bd2f8a70b8fb3fbd051c1aab8d8.tar.bz2
openrc-20df56f0b2a01bd2f8a70b8fb3fbd051c1aab8d8.tar.xz
Add CGroup support
X-Gentoo-Bug: 390297 X-Gentoo-Bug: http://bugs.gentoo.org/show_bug.cgi?id=390297
-rw-r--r--etc/rc.conf.Linux7
-rw-r--r--sh/runscript.sh.in22
2 files changed, 29 insertions, 0 deletions
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 9b5859a..585da3c 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -1,3 +1,10 @@
+# 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/sh/runscript.sh.in b/sh/runscript.sh.in
index f86a510..73b4a59 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -189,6 +189,16 @@ fi
# Load any system overrides
sourcex -e "@SYSCONFDIR@/rc.conf"
+# Attach to CGroup - dir existing is enough for us
+if [ -d /sys/fs/cgroup/ ]; then
+ # use RC_SVCNAME unless overridden in conf.d
+ SVC_CGROUP=${RC_CGROUP:-$RC_SVCNAME}
+ mkdir -p /sys/fs/cgroup/${SVC_CGROUP}
+ # now attach self to cgroup - any children of this process will inherit this
+ echo $$ > /sys/fs/cgroup/${SVC_CGROUP}/tasks
+ # TODO: set res limits from conf.d
+fi
+
# Apply any ulimit defined
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
@@ -291,3 +301,15 @@ while [ -n "$1" ]; do
eerror "$RC_SVCNAME: unknown function \`$1'"
exit 1
done
+
+# CGroup cleanup
+if [ -d /sys/fs/cgroup/ ]; then
+ # use RC_SVCNAME unless overridden in conf.d
+ SVC_CGROUP=${RC_CGROUP:-$RC_SVCNAME}
+ # reattach to root cgroup
+ echo $$ > /sys/fs/cgroup/tasks
+ # remove cgroup if empty, will fail if any task attached
+ rmdir /sys/fs/cgroup/${SVC_CGROUP} 2>/dev/null
+fi
+
+exit 0