2013-02-20 04:22:49 +05:30
|
|
|
#!@SHELL@
|
2013-02-04 03:31:16 +05:30
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
2013-02-18 02:44:06 +05:30
|
|
|
cgroup_set_values()
|
2013-02-04 03:31:16 +05:30
|
|
|
{
|
2013-02-18 02:44:06 +05:30
|
|
|
[ -n "$1" -a -n "$2" -a -d "/sys/fs/cgroup/$1" ] || return 0
|
|
|
|
|
|
|
|
local controller="$1" h=$(cgroup_find_path "$1")
|
2013-02-04 03:31:16 +05:30
|
|
|
cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}"
|
2013-02-18 02:44:06 +05:30
|
|
|
[ -d "$cgroup" ] || mkdir -p "$cgroup"
|
2013-02-04 03:31:16 +05:30
|
|
|
|
2013-02-18 02:44:06 +05:30
|
|
|
set -- $2
|
|
|
|
local name val
|
|
|
|
while [ -n "$1" -a "$controller" != "cpuacct" ]; do
|
|
|
|
case "$1" in
|
|
|
|
$controller.*)
|
|
|
|
if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then
|
|
|
|
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
|
|
|
|
echo $val > "$cgroup/$name"
|
|
|
|
fi
|
|
|
|
name=$1
|
|
|
|
val=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
val="$val $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then
|
|
|
|
veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
|
|
|
|
echo $val > "$cgroup/$name"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$cgroup/tasks" ]; then
|
|
|
|
veinfo "$RC_SVCNAME: adding to $cgroup/tasks"
|
|
|
|
echo 0 > "$cgroup/tasks"
|
|
|
|
fi
|
2013-02-04 03:31:16 +05:30
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
cgroup_set_limits()
|
|
|
|
{
|
|
|
|
openrc_cgroup=/sys/fs/cgroup/openrc
|
2013-02-18 02:44:06 +05:30
|
|
|
if [ -d "$openrc_cgroup" ]; then
|
|
|
|
cgroup="$openrc_cgroup/$RC_SVCNAME"
|
|
|
|
mkdir -p "$cgroup"
|
|
|
|
[ -f "$cgroup/tasks" ] && echo 0 > "$cgroup/tasks"
|
2013-02-04 03:31:16 +05:30
|
|
|
fi
|
|
|
|
|
2013-02-18 02:44:06 +05:30
|
|
|
local blkio="${rc_cgroup_blkio:-$RC_CGROUP_BLKIO}"
|
|
|
|
[ -n "$blkio" ] && cgroup_set_values blkio "$blkio"
|
|
|
|
|
|
|
|
local cpu="${rc_cgroup_cpu:-$RC_CGROUP_CPU}"
|
|
|
|
[ -n "$cpu" ] && cgroup_set_values cpu "$cpu"
|
|
|
|
|
|
|
|
local cpuacct="${rc_cgroup_cpuacct:-$RC_CGROUP_CPUACCT}"
|
|
|
|
[ -n "$cpuacct" ] && cgroup_set_values cpuacct "$cpuacct"
|
|
|
|
|
|
|
|
local cpuset="${rc_cgroup_cpuset:-$RC_CGROUP_cpuset}"
|
|
|
|
[ -n "$cpuset" ] && cgroup_set_values cpuset "$cpuset"
|
|
|
|
|
|
|
|
local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}"
|
|
|
|
[ -n "$devices" ] && cgroup_set_values devices "$devices"
|
|
|
|
|
|
|
|
local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}"
|
|
|
|
[ -n "$memory" ] && cgroup_set_values memory "$memory"
|
|
|
|
|
|
|
|
local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}"
|
|
|
|
[ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio"
|
2013-02-04 03:31:16 +05:30
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|