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