Gentoo Archives: gentoo-commits

From: William Hubbs <williamh@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/openrc:master commit in: init.d/, sh/, etc/
Date: Sun, 20 Nov 2011 20:24:36
Message-Id: d8bbeb184f462199582fa265c9b681288884ecd9.WilliamH@gentoo
1 commit: d8bbeb184f462199582fa265c9b681288884ecd9
2 Author: William Hubbs <williamh <AT> gentoo <DOT> org>
3 AuthorDate: Sun Nov 20 00:15:46 2011 +0000
4 Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
5 CommitDate: Sun Nov 20 20:07:46 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=d8bbeb18
7
8 CGroups: create the openrc cgroup hierarchy
9
10 Openrc will create a cgroup hierarchy called openrc which will have all
11 services it starts and all subsystems attached to it. If you need other
12 groups/hierarchies, please use libcgroup.
13
14 ---
15 etc/rc.conf.Linux | 7 -------
16 init.d/sysfs.in | 15 +++++++++++++--
17 sh/Makefile | 4 ++--
18 sh/cgroup-release-agent.sh.in | 10 ++++++++++
19 sh/runscript.sh.in | 23 +++++++++++++----------
20 5 files changed, 38 insertions(+), 21 deletions(-)
21
22 diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
23 index 963fc68..9b5859a 100644
24 --- a/etc/rc.conf.Linux
25 +++ b/etc/rc.conf.Linux
26 @@ -1,10 +1,3 @@
27 -# Set the control group for this service.
28 -# If you do not set this, the default setting is the value of
29 -# RC_SVCNAME.
30 -# This setting is ignored if you do not have CONFIG_CGROUPS active in
31 -# your kernel.
32 -# rc_cgroup="foo"
33 -
34 ##############################################################################
35 # LINUX SPECIFIC OPTIONS
36
37
38 diff --git a/init.d/sysfs.in b/init.d/sysfs.in
39 index a536d5f..d57c388 100644
40 --- a/init.d/sysfs.in
41 +++ b/init.d/sysfs.in
42 @@ -62,13 +62,24 @@ mount_misc()
43 fi
44
45 # Setup Kernel Support for cgroup
46 - if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then
47 - if grep -qs cgroup /proc/filesystems; then
48 + if [ -d /sys/fs/cgroup ]; then
49 + if grep -qs cgroup /proc/filesystems && \
50 + ! mountinfo -q /sys/fs/cgroup; then
51 ebegin "Mounting cgroup filesystem"
52 mount -n -t tmpfs -o nodev,noexec,nosuid \
53 cgroup /sys/fs/cgroup
54 eend $?
55 fi
56 + if ! mountinfo -q /sys/fs/cgroup/openrc; then
57 + ebegin "creating openrc control group"
58 + mkdir /sys/fs/cgroup/openrc
59 + mount -n -t cgroup -o nodev,noexec,nosuid \
60 + openrc /sys/fs/cgroup/openrc
61 + echo 1 > /sys/fs/cgroup/openrc/notify_on_release
62 + echo @LIBEXECDIR@/sh/cgroup-release-agent.sh \
63 + > /sys/fs/cgroup/openrc/release_agent
64 + eend
65 + fi
66 fi
67 }
68
69
70 diff --git a/sh/Makefile b/sh/Makefile
71 index f714780..15b24d0 100644
72 --- a/sh/Makefile
73 +++ b/sh/Makefile
74 @@ -12,8 +12,8 @@ include ${MK}/os.mk
75 SRCS-FreeBSD=
76 BIN-FreeBSD=
77
78 -SRCS-Linux= init-early.sh.in udhcpc-hook.sh.in
79 -BIN-Linux= init-early.sh udhcpc-hook.sh
80 +SRCS-Linux= cgroup-release-agent.sh.in init-early.sh.in udhcpc-hook.sh.in
81 +BIN-Linux= cgroup-release-agent.sh init-early.sh udhcpc-hook.sh
82
83 SRCS-NetBSD= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in
84 BIN-NetBSD= ifwatchd-carrier.sh ifwatchd-nocarrier.sh
85
86 diff --git a/sh/cgroup-release-agent.sh.in b/sh/cgroup-release-agent.sh.in
87 new file mode 100644
88 index 0000000..c3174fe
89 --- /dev/null
90 +++ b/sh/cgroup-release-agent.sh.in
91 @@ -0,0 +1,10 @@
92 +#!@SHELL@
93 +#
94 +# This is run by the kernel after the last task is removed from a
95 +# control group in the openrc hierarchy.
96 +
97 +cgroup=/sys/fs/cgroup/openrc
98 +PATH=/bin:/usr/bin:/sbin:/usr/sbin
99 +if [ -d ${cgroup}/$1 ]; then
100 + rmdir ${cgroup}/$1
101 +fi
102
103 diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
104 index 706a1f7..4032cb8 100644
105 --- a/sh/runscript.sh.in
106 +++ b/sh/runscript.sh.in
107 @@ -148,6 +148,19 @@ start()
108 service_inactive && _inactive=true
109 mark_service_inactive
110 fi
111 + if [ "$RC_UNAME" = Linux ]; then
112 + local cgroup=/sys/fs/cgroup/openrc
113 + local svc_cgroup=${cgroup}/${RC_SVCNAME}
114 + if mountinfo -q ${cgroup}; then
115 + mkdir ${svc_cgroup}
116 + for f in cpuset.cpus cpuset.mems; do
117 + if [ -f ${cgroup}/${f} ]; then
118 + cp ${cgroup}/${f} ${svc_cgroup}
119 + fi
120 + done
121 + echo $$ > ${svc_cgroup}/tasks
122 + fi
123 + fi
124 eval start-stop-daemon --start \
125 --exec $command \
126 ${procname:+--name} $procname \
127 @@ -189,16 +202,6 @@ fi
128 # Load any system overrides
129 sourcex -e "@SYSCONFDIR@/rc.conf"
130
131 -# Attach to CGroup - dir existing is enough for us
132 -if [ -d /sys/fs/cgroup -a -n "${rc_cgroup}" ]; then
133 - if [ -d /sys/fs/cgroup/${rc_cgroup} ]; then
134 - # attach self to cgroup - any children of this process will inherit this
135 - echo $$ > /sys/fs/cgroup/${rc_cgroup}/tasks
136 - else
137 - eerror "Control group /sys/fs/cgroup/${rc_cgroup} does not exist."
138 - fi
139 -fi
140 -
141 # Apply any ulimit defined
142 [ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}