updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / libcgroup / cgconfig
blobb75af60d78a859be9509f659608bd36e9a1c1553
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
6 . /etc/conf.d/cgconfig
8 # From cgconfig init.d script
9 create_default_groups() {
10 declare defaultcgroup
12 if [ -f /etc/cgrules.conf ]; then
13 grep -m1 '^\*[[:space:]]\+' /etc/cgrules.conf | \
14 read user ctrl defaultcgroup
15 if [ -n $defaultcgroup -a $defaultcgroup = "*" ]; then
16 defaultcgroup=
20 if [ -z $defaultcgroup ]; then
21 defaultcgroup=sysdefault/
25 # Find all mounted subsystems and create comma-separated list
26 # of controllers.
28 controllers=$(lssubsys 2>/dev/null | tr '\n' ',' | sed s/.$//)
31 # Create the default group, ignore errors when the default group
32 # already exists.
34 cgcreate -f 664 -d 775 -g $controllers:$defaultcgroup 2>/dev/null
37 # special rule for cpusets
39 if echo $controllers | grep -q -w cpuset; then
40 cpus=$(cgget -nv -r cpuset.cpus /)
41 cgset -r cpuset.cpus=$cpus $defaultcgroup
42 mems=$(cgget -nv -r cpuset.mems /)
43 cgset -r cpuset.mems=$mems $defaultcgroup
47 # special rule for cpus
49 if echo $controllers | grep -q -w cpu; then
50 rt_runtime_us=$(cgget -nv -r cpu.rt_runtime_us /)
51 cgset -r cpu.rt_runtime_us=$rt_runtime_us $defaultcgroup
55 # Classify everything to default cgroup. Ignore errors, some processes
56 # may exit after ps is run and before cgclassify moves them.
58 classify_all -g $controllers:$defaultcgroup || :
61 classify_all() {
62 cgclassify "$@" $(ps --no-headers -eL o tid) 2>/dev/null
65 case "$1" in
66 start)
67 stat_busy "Starting CGroups configuration"
68 /sbin/cgconfigparser -l /etc/cgconfig.conf
69 if [ $? -gt 0 ]; then
70 stat_fail
71 else
72 if [ $CREATE_DEFAULT == "yes" ]; then
73 create_default_groups
75 if [ $CLASSIFY == "yes" ]; then
76 classify_all
78 add_daemon cgconfig
79 stat_done
82 stop)
83 stat_busy "Clearing CGroups configuration"
84 cgclear
85 if [ $? -gt 0 ]; then
86 stat_fail
87 else
88 rm_daemon cgconfig
89 stat_done
92 restart)
93 $0 stop
94 sleep 1
95 $0 start
98 echo "usage: $0 {start|stop|restart}"
99 esac
101 # vim:set ft=sh: