Since the cgroup directory is now automounted only this patch (or something equivalent) is needed to automatically create per-initscript CGroup directories diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index 5853212..0122e47 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -188,6 +188,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 the svcname unless overriden in conf.d + SVC_CGROUP=${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}
Created attachment 292315 [details] CGroup patch
And then you want to clean up when the init script is stopped and the cgroup is empty: diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index 859cfa8..d1f5e95 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -280,3 +280,15 @@ while [ -n "$1" ]; do eerror "$RC_SVCNAME: unknown function \`$1'" exit 1 done + +# CGroup cleanup +if [ -d /sys/fs/cgroup/ ]; then + # use the svcname unless overriden in conf.d + SVC_CGROUP=${CGROUP:-$RC_SVCNAME} + # reattach ourself 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 +# need to exit cleanly +exit 0
Created attachment 292317 [details] CGroup Cleanup patch
This has been added in commit 20df56f.
Do you sure it is working? the run-script.sh::start() function is overridden by most services, so the cgroup assignment never reached. At my system only acpid which has no start() in its init.d script is assigned. I think the run-script.sh:start() additions should go in its own function and be called directly by script main. Or add a new callback *_pre_internal() and use it: --- + if [ "$(command -v "$1_pre_internal")" = "$1_pre_internal" ] + then + "$1"_pre_internal || exit $? + fi if [ "$(command -v "$1_pre")" = "$1_pre" ] then "$1"_pre || exit $? fi "$1" || exit $? ---
Also, any reason for the change of /sys/fs/cgroup->/sys/fs/cgroup/openrc?
(In reply to comment #5) > Do you sure it is working? > > the run-script.sh::start() function is overridden by most services, so the > cgroup assignment never reached. Most services should be rewritten to be compliant with openrc's stop/start functions in runscript.sh. This is being tracked in bug #367793. To see how this should be done, see man runscript. (In reply to comment #6) > Also, any reason for the change of /sys/fs/cgroup->/sys/fs/cgroup/openrc? The kernel documentation states that /sys/fs/cgroup is a tmpfs, then the cgroup file systems are mounted under that. See the examples in /usr/src/linux/Documentation/cgroups/cgroups.txt.
Thank for your response! (In reply to comment #7) > (In reply to comment #5) > > Do you sure it is working? > > > > the run-script.sh::start() function is overridden by most services, so the > > cgroup assignment never reached. > > Most services should be rewritten to be compliant with openrc's stop/start > functions in runscript.sh. This is being tracked in bug #367793. To see how > this should be done, see man runscript. I don't think user should be able to override this even if it implement the start(). If openrc decides that every server leaves in its own cgroup, it should be enforced.
(In reply to comment #8) > (In reply to comment #7) > > (In reply to comment #5) > > > Do you sure it is working? > > > > > > the run-script.sh::start() function is overridden by most services, so the > > > cgroup assignment never reached. > > > > Most services should be rewritten to be compliant with openrc's stop/start > > functions in runscript.sh. This is being tracked in bug #367793. To see how > > this should be done, see man runscript. > > I don't think user should be able to override this even if it implement the > start(). If openrc decides that every server leaves in its own cgroup, it > should be enforced. I do not understand what you mean. Openrc creates a control group which will contain all of the daemons that openrc starts. If a sys admin wants to manipulate control groups, they can use the tools in dev-libs/libcgroup
(In reply to comment #9) > I do not understand what you mean. > > Openrc creates a control group which will contain all of the daemons that > openrc starts. If a sys admin wants to manipulate control groups, they can use > the tools in dev-libs/libcgroup Do you say that a init.d script cannot have start() function? As if it has, it will override runservice.sh start() function and the cgroup assignment will be skipped.
I see that this was removed [1] Why? Any alternative? [1] http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commitdiff;h=ed4605bf9ff63effe0d09811a3e708d5e3a75378
(In reply to comment #11) > I see that this was removed [1] > > Why? > Any alternative? Actually this is now back, in git, and should be supported in the latest stable (0.9.8.2). The issue at the time I removed it was that I had been unable to determine how to mount a cgroup with no subsystems attached to it. The part I still need to add is automatically adding the services openrc starts to the openrc control group.
(In reply to comment #12) > The part I still need to add is automatically adding the services openrc starts > to the openrc control group. This what I referring to.