1 |
commit: 20df56f0b2a01bd2f8a70b8fb3fbd051c1aab8d8 |
2 |
Author: Patrick Lauer <patrick <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Nov 12 21:19:55 2011 +0000 |
4 |
Commit: William Hubbs <williamh <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Nov 17 22:22:59 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=20df56f0 |
7 |
|
8 |
Add CGroup support |
9 |
|
10 |
X-Gentoo-Bug: 390297 |
11 |
X-Gentoo-Bug: http://bugs.gentoo.org/show_bug.cgi?id=390297 |
12 |
|
13 |
--- |
14 |
etc/rc.conf.Linux | 7 +++++++ |
15 |
sh/runscript.sh.in | 22 ++++++++++++++++++++++ |
16 |
2 files changed, 29 insertions(+), 0 deletions(-) |
17 |
|
18 |
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux |
19 |
index 9b5859a..585da3c 100644 |
20 |
--- a/etc/rc.conf.Linux |
21 |
+++ b/etc/rc.conf.Linux |
22 |
@@ -1,3 +1,10 @@ |
23 |
+# Set the control group for this service. |
24 |
+# If you do not set this, the default setting is the value of |
25 |
+# RC_SVCNAME. |
26 |
+# This setting is ignored if you do not have CONFIG_CGROUPS active in |
27 |
+# your kernel. |
28 |
+# RC_CGROUP="foo" |
29 |
+ |
30 |
############################################################################## |
31 |
# LINUX SPECIFIC OPTIONS |
32 |
|
33 |
|
34 |
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in |
35 |
index f86a510..73b4a59 100644 |
36 |
--- a/sh/runscript.sh.in |
37 |
+++ b/sh/runscript.sh.in |
38 |
@@ -189,6 +189,16 @@ fi |
39 |
# Load any system overrides |
40 |
sourcex -e "@SYSCONFDIR@/rc.conf" |
41 |
|
42 |
+# Attach to CGroup - dir existing is enough for us |
43 |
+if [ -d /sys/fs/cgroup/ ]; then |
44 |
+ # use RC_SVCNAME unless overridden in conf.d |
45 |
+ SVC_CGROUP=${RC_CGROUP:-$RC_SVCNAME} |
46 |
+ mkdir -p /sys/fs/cgroup/${SVC_CGROUP} |
47 |
+ # now attach self to cgroup - any children of this process will inherit this |
48 |
+ echo $$ > /sys/fs/cgroup/${SVC_CGROUP}/tasks |
49 |
+ # TODO: set res limits from conf.d |
50 |
+fi |
51 |
+ |
52 |
# Apply any ulimit defined |
53 |
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT} |
54 |
|
55 |
@@ -291,3 +301,15 @@ while [ -n "$1" ]; do |
56 |
eerror "$RC_SVCNAME: unknown function \`$1'" |
57 |
exit 1 |
58 |
done |
59 |
+ |
60 |
+# CGroup cleanup |
61 |
+if [ -d /sys/fs/cgroup/ ]; then |
62 |
+ # use RC_SVCNAME unless overridden in conf.d |
63 |
+ SVC_CGROUP=${RC_CGROUP:-$RC_SVCNAME} |
64 |
+ # reattach to root cgroup |
65 |
+ echo $$ > /sys/fs/cgroup/tasks |
66 |
+ # remove cgroup if empty, will fail if any task attached |
67 |
+ rmdir /sys/fs/cgroup/${SVC_CGROUP} 2>/dev/null |
68 |
+fi |
69 |
+ |
70 |
+exit 0 |