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.
This commit is contained in:
William Hubbs
2011-11-19 18:15:46 -06:00
parent 453d13296d
commit d8bbeb184f
5 changed files with 38 additions and 21 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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}