aboutsummaryrefslogtreecommitdiff
path: root/sh/rc-cgroup.sh.in
diff options
context:
space:
mode:
authorAlexander Vershilov <qnikst@gentoo.org>2013-02-03 16:01:16 -0600
committerWilliam Hubbs <w.d.hubbs@gmail.com>2013-02-16 01:28:35 -0600
commitb46747f9981337470353014bfa34e9f9f8bace34 (patch)
tree35143d1903a83ec63f20a3f2aac6a91cc46a94c4 /sh/rc-cgroup.sh.in
parent86dbd757e94fe5402efea03f9f8725a71533297a (diff)
Add module for cgroup processing
sh/rc-cgroup.sh.in: new script to handle cgroup processing sh/rc-cgroup.sh.in: do not use grep or cut (modification by William Hubbs) sh/runscript.sh.in: use the cgroup script
Diffstat (limited to 'sh/rc-cgroup.sh.in')
-rw-r--r--sh/rc-cgroup.sh.in59
1 files changed, 59 insertions, 0 deletions
diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
new file mode 100644
index 00000000..09b9b564
--- /dev/null
+++ b/sh/rc-cgroup.sh.in
@@ -0,0 +1,59 @@
+#@SHELL@
+# Copyright (c) 2012 Alexander Vershilov <qnikst@gentoo.org>
+# Released under the 2-clause BSD license.
+
+cgroup_find_path()
+{
+ local OIFS n name dir result
+ [ -n "$1" ] || return 0
+ OIFS="$IFS"
+ IFS=":"
+ while read n name dir; do
+ [ "$name" = "$1" ] && result="$dir"
+ done < /proc/1/cgroup
+ IFS="$OIFS"
+ echo $result
+}
+
+# prepare values to be attached inside cgroups
+cgroup_prepare()
+{
+ local h=$(cgroup_find_path "$1")
+ cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}"
+ [ -d ${cgroup} ] || mkdir -p ${cgroup}
+ return 0
+}
+
+cgroup_set_value()
+{
+ [ -f "$cgroup/${1}" -a -n "$2" ] && echo $2 > "${cgroup}/${1}"
+ return 0
+}
+
+cgroup_add_process()
+{
+ [ -f "${cgroup}"/tasks ] && echo 0 > "${cgroup}"/tasks
+ return 0
+}
+
+cgroup_set_limits()
+{
+ openrc_cgroup=/sys/fs/cgroup/openrc
+ if [ -d ${openrc_cgroup} ]; then
+ cgroup=${openrc_cgroup}/${RC_SVCNAME}
+ mkdir -p ${cgroup}
+ [ -f "${cgroup}"/tasks ] && echo 0 > "${cgroup}"/tasks
+ fi
+
+ if [ -d /sys/fs/cgroup/cpu ]; then
+ local share
+
+ share=${rc_cgroup_cpu_shares:-$RC_CGROUP_CPU_SHARES}
+ if [ -n "$share" ]; then
+ cgroup_prepare "cpu"
+ cgroup_set_value "cpu.shares" $share
+ cgroup_add_process
+ fi
+ fi
+ return 0
+}