]> git.pld-linux.org Git - packages/libcgroup.git/blame - cgconfig.init
- initscript uses ps, add procps dep
[packages/libcgroup.git] / cgconfig.init
CommitLineData
382db189
JR
1#!/bin/sh
2#
3# cgconfig Control Groups Configuration Startup
ee76fe06 4# chkconfig: 2345 05 95
382db189
JR
5# description: This script runs the cgconfigparser utility to parse and setup \
6# the control group filesystem. It uses /etc/cgconfig.conf \
7# and parses the configuration specified in there.
8
9# Source function library
10. /etc/rc.d/init.d/functions
11
12# read the config
13CREATE_DEFAULT=yes
14[ -f /etc/sysconfig/cgconfig ] && . /etc/sysconfig/cgconfig
15
16create_default_groups() {
04ae980e 17 if [ -f /etc/cgrules.conf ]; then
382db189
JR
18 defaultcgroup=$(awk '/^\*[\t ]+/ { print $3; exit }' /etc/cgrules.conf)
19 if [ -n "$defaultcgroup" -a "$defaultcgroup" = "*" ]; then
ffc5c83f 20 # nls "/etc/cgrules.conf incorrect. Overriding it"
382db189
JR
21 defaultcgroup=
22 fi
23 fi
24
25 if [ -z $defaultcgroup ]; then
26 defaultcgroup=sysdefault/
27 fi
28
04ae980e
JR
29 #
30 # Find all mounted subsystems and create comma-separated list
31 # of controllers.
32 #
fcf1aa30 33 controllers=$(lssubsys 2>/dev/null | awk '{ if (v) v=v","$0 ; else v=$0 } END { printf "%s", v }')
04ae980e
JR
34
35 #
36 # Create the default group, ignore errors when the default group
37 # already exists.
38 #
39 cgcreate -f 664 -d 775 -g $controllers:$defaultcgroup 2>/dev/null
40
41 #
42 # special rule for cpusets
43 #
44 if echo $controllers | grep -q -w cpuset; then
45 cpus=`cgget -nv -r cpuset.cpus /`
46 cgset -r cpuset.cpus=$cpus $defaultcgroup
47 mems=`cgget -nv -r cpuset.mems /`
48 cgset -r cpuset.mems=$mems $defaultcgroup
49 fi
50
51 #
52 # Classify everything to default cgroup. Ignore errors, some processes
53 # may exit after ps is run and before cgclassify moves them.
54 #
55 cgclassify -g $controllers:$defaultcgroup `ps --no-headers -eL o tid` 2>/dev/null || :
382db189
JR
56}
57
58start() {
59 # Check if the service is already running?
60 if [ -f /var/lock/subsys/cgconfig ]; then
61 msg_already_running "cgconfig"
62 return
63 fi
382db189 64 if [ ! -s /etc/cgconfig.conf ]; then
04ae980e 65 nls "/etc/cgconfig.conf is not configured"
382db189
JR
66 return 6
67 fi
ffc5c83f
JR
68 msg_starting "cgconfig"; busy
69 local out
70 out=`/sbin/cgconfigparser -l /etc/cgconfig.conf 2>&1`
71 RETVAL=$?
72 if [ $RETVAL -ne 0 ]; then
73 fail
74 [ "$out" ] && echo >&2 "$out"
75 exit $RETVAL
382db189
JR
76 fi
77
04ae980e 78 if is_yes "$CREATE_DEFAULT"; then
382db189
JR
79 create_default_groups
80 fi
ffc5c83f
JR
81 RETVAL=$?
82 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cgconfig
382db189
JR
83 ok
84}
85
86stop() {
87 if [ -f /var/lock/subsys/cgconfig ]; then
88 msg_stopping "cgconfig"
89 cgclear
90 rm -f /var/lock/subsys/cgconfig
91 ok
92 else
93 msg_not_running "cgconfig"
94 fi
95}
96
97RETVAL=0
98
99case "$1" in
100 start)
101 start
102 ;;
103 stop)
104 stop;
105 ;;
106 restart|reload)
107 stop
108 start
109 ;;
110 condrestart)
111 if [ -f /var/lock/subsys/cgconfig ] ; then
112 stop
113 start
114 fi
115 ;;
116 status)
117 if [ -f /var/lock/subsys/cgconfig ] ; then
118 echo "Running"
119 exit 0
120 else
121 echo "Stopped"
122 exit 3
123 fi
124 ;;
125 *)
126 msg_usage "$0 {start|stop|restart|condrestart|status}"
127 exit 3
128 ;;
129esac
130
131exit $RETVAL
This page took 0.084019 seconds and 4 git commands to generate.