]>
Commit | Line | Data |
---|---|---|
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 | |
13 | CREATE_DEFAULT=yes | |
14 | [ -f /etc/sysconfig/cgconfig ] && . /etc/sysconfig/cgconfig | |
15 | ||
16 | create_default_groups() { | |
2ba2a72e | 17 | local defaultcgroup controllers |
04ae980e | 18 | if [ -f /etc/cgrules.conf ]; then |
382db189 JR |
19 | defaultcgroup=$(awk '/^\*[\t ]+/ { print $3; exit }' /etc/cgrules.conf) |
20 | if [ -n "$defaultcgroup" -a "$defaultcgroup" = "*" ]; then | |
ffc5c83f | 21 | # nls "/etc/cgrules.conf incorrect. Overriding it" |
382db189 JR |
22 | defaultcgroup= |
23 | fi | |
24 | fi | |
25 | ||
26 | if [ -z $defaultcgroup ]; then | |
27 | defaultcgroup=sysdefault/ | |
28 | fi | |
29 | ||
04ae980e JR |
30 | # |
31 | # Find all mounted subsystems and create comma-separated list | |
32 | # of controllers. | |
33 | # | |
fcf1aa30 | 34 | controllers=$(lssubsys 2>/dev/null | awk '{ if (v) v=v","$0 ; else v=$0 } END { printf "%s", v }') |
04ae980e JR |
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 | |
2ba2a72e ER |
46 | local cpus mems |
47 | cpus=$(cgget -nv -r cpuset.cpus /) | |
04ae980e | 48 | cgset -r cpuset.cpus=$cpus $defaultcgroup |
2ba2a72e | 49 | mems=$(cgget -nv -r cpuset.mems /) |
04ae980e JR |
50 | cgset -r cpuset.mems=$mems $defaultcgroup |
51 | fi | |
52 | ||
53 | # | |
54 | # Classify everything to default cgroup. Ignore errors, some processes | |
55 | # may exit after ps is run and before cgclassify moves them. | |
56 | # | |
2ba2a72e | 57 | cgclassify -g $controllers:$defaultcgroup $(ps --no-headers -eL o tid) 2>/dev/null || : |
382db189 JR |
58 | } |
59 | ||
60 | start() { | |
61 | # Check if the service is already running? | |
62 | if [ -f /var/lock/subsys/cgconfig ]; then | |
63 | msg_already_running "cgconfig" | |
64 | return | |
65 | fi | |
382db189 | 66 | if [ ! -s /etc/cgconfig.conf ]; then |
04ae980e | 67 | nls "/etc/cgconfig.conf is not configured" |
2ba2a72e ER |
68 | RETVAL=6 |
69 | return | |
382db189 | 70 | fi |
ffc5c83f JR |
71 | msg_starting "cgconfig"; busy |
72 | local out | |
2ba2a72e | 73 | out=$(/sbin/cgconfigparser -l /etc/cgconfig.conf 2>&1) |
ffc5c83f JR |
74 | RETVAL=$? |
75 | if [ $RETVAL -ne 0 ]; then | |
76 | fail | |
77 | [ "$out" ] && echo >&2 "$out" | |
78 | exit $RETVAL | |
382db189 JR |
79 | fi |
80 | ||
04ae980e | 81 | if is_yes "$CREATE_DEFAULT"; then |
382db189 JR |
82 | create_default_groups |
83 | fi | |
ffc5c83f JR |
84 | RETVAL=$? |
85 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cgconfig | |
382db189 JR |
86 | ok |
87 | } | |
88 | ||
89 | stop() { | |
2ba2a72e | 90 | if [ ! -f /var/lock/subsys/cgconfig ]; then |
382db189 | 91 | msg_not_running "cgconfig" |
2ba2a72e | 92 | return |
382db189 | 93 | fi |
2ba2a72e ER |
94 | |
95 | msg_stopping "cgconfig" | |
96 | cgclear | |
97 | rm -f /var/lock/subsys/cgconfig | |
98 | ok | |
382db189 JR |
99 | } |
100 | ||
2ba2a72e ER |
101 | condrestart() { |
102 | if [ ! -f /var/lock/subsys/cgconfig ]; then | |
103 | msg_not_running "cgconfig" | |
104 | RETVAL=$1 | |
105 | return | |
106 | fi | |
382db189 | 107 | |
2ba2a72e ER |
108 | stop |
109 | start | |
110 | } | |
111 | ||
112 | RETVAL=0 | |
382db189 JR |
113 | case "$1" in |
114 | start) | |
115 | start | |
116 | ;; | |
117 | stop) | |
2ba2a72e | 118 | stop |
382db189 | 119 | ;; |
2ba2a72e | 120 | restart) |
382db189 JR |
121 | stop |
122 | start | |
123 | ;; | |
2ba2a72e ER |
124 | try-restart) |
125 | condrestart 0 | |
126 | ;; | |
127 | force-reload) | |
128 | condrestart 7 | |
382db189 JR |
129 | ;; |
130 | status) | |
131 | if [ -f /var/lock/subsys/cgconfig ] ; then | |
132 | echo "Running" | |
133 | exit 0 | |
134 | else | |
135 | echo "Stopped" | |
136 | exit 3 | |
137 | fi | |
138 | ;; | |
139 | *) | |
2ba2a72e | 140 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}" |
382db189 JR |
141 | exit 3 |
142 | ;; | |
143 | esac | |
144 | ||
145 | exit $RETVAL |