Subversion Repositories configs

Rev

Rev 9 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#!/bin/bash
2
#
3
# Start/Stop the workload manager
4
#
5
# Copyright IBM Corporation. 2008
6
#
7
# Authors:     Balbir Singh <balbir@linux.vnet.ibm.com>
8
# This program is free software; you can redistribute it and/or modify it
9
# under the terms of version 2.1 of the GNU Lesser General Public License
10
# as published by the Free Software Foundation.
11
#
12
# This program is distributed in the hope that it would be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
#
16
# cgconfig Control Groups Configuration Startup
17
# chkconfig: - 5 95
18
# description: This script runs the cgconfigparser utility to parse and setup
19
#              the control group filesystem. It uses /etc/cgconfig.conf
20
#              and parses the configuration specified in there.
21
 
22
### BEGIN INIT INFO
23
# Provides:             cgconfig
24
# Required-Start:
25
# Required-Stop:
26
# Should-Start:         ypbind
27
# Should-Stop:          ypbind
28
# Short-Description:    Create and setup control group filesystem(s)
29
# Description:          Create and setup control group filesystem(s)
30
### END INIT INFO
31
 
32
# get correct location of binaries from configure
33
prefix=/usr;exec_prefix=/usr;sbindir=/sbin
34
CGCONFIGPARSER_BIN=$sbindir/cgconfigparser
35
CONFIG_FILE=/etc/cgconfig.conf
36
servicename=cgconfig
37
lockfile=/var/lock/subsys/$servicename
38
 
39
#
40
# Source LSB routines
41
#
42
. /etc/rc.d/init.d/functions
43
log_success_msg () {
44
    echo -n $*; success "$*"; echo
45
}
46
log_failure_msg () {
47
    echo -n $*; failure "$*"; echo
48
}
49
log_warning_msg () {
50
    echo -n $*; warning "$*"; echo
51
}
52
 
53
# read the config
54
CREATE_DEFAULT=yes
55
if [ -e /etc/sysconfig/cgconfig ]; then
56
        . /etc/sysconfig/cgconfig
57
fi
58
 
59
create_default_groups() {
60
	defaultcgroup=
61
 
62
        if [ -f /etc/cgrules.conf ]; then
63
	    read user ctrl defaultcgroup <<< \
64
		    $(grep -m1 '^\*[[:space:]]\+' /etc/cgrules.conf)
65
            if [ -n "$defaultcgroup" -a "$defaultcgroup" = "*" ]; then
66
                log_warning_msg "/etc/cgrules.conf incorrect"
67
                log_warning_msg "Overriding it"
68
                defaultcgroup=
69
            fi
70
        fi
71
 
72
        if [ -z $defaultcgroup ]
73
        then
74
            defaultcgroup=sysdefault/
75
        fi
76
 
77
        #
78
        # Find all mounted subsystems and create comma-separated list
79
        # of controllers.
80
        #
81
        controllers=`lssubsys 2>/dev/null | tr '\n' ',' | sed s/.$//`
82
 
83
        #
84
        # Create the default group, ignore errors when the default group
85
        # already exists.
86
        #
87
        cgcreate -f 664 -d 775 -g $controllers:$defaultcgroup 2>/dev/null
88
 
89
        #
90
        # special rule for cpusets
91
        #
92
        if echo $controllers | grep -q -w cpuset; then
93
                cpus=`cgget -nv -r cpuset.cpus /`
94
                cgset -r cpuset.cpus=$cpus $defaultcgroup
95
                mems=`cgget -nv -r cpuset.mems /`
96
                cgset -r cpuset.mems=$mems $defaultcgroup
97
        fi
98
 
99
        #
100
        # Classify everything to default cgroup. Ignore errors, some processes
101
        # may exit after ps is run and before cgclassify moves them.
102
        #
103
        cgclassify -g $controllers:$defaultcgroup `ps --no-headers -eL o tid` \
104
                 2>/dev/null || :
105
}
106
 
107
start() {
108
        echo -n "Starting cgconfig service: "
109
	if [ -f "$lockfile" ]; then
110
            log_warning_msg "lock file already exists"
111
            return 0
112
        fi
113
 
114
        if [ $? -eq 0 ]; then
115
                if [ ! -s $CONFIG_FILE ]; then
116
                    log_failure_msg $CONFIG_FILE "is not configured"
117
                    return 6
118
                fi
119
 
120
                $CGCONFIGPARSER_BIN -l $CONFIG_FILE
121
                retval=$?
122
                if [ $retval -ne 0 ]; then
123
                    log_failure_msg "Failed to parse " $CONFIG_FILE
124
                    return 1
125
                fi
126
        fi
127
 
128
        if [ $CREATE_DEFAULT = "yes" ]; then
129
                create_default_groups
130
        fi
131
 
132
        touch "$lockfile"
133
        retval=$?
134
        if [ $retval -ne 0 ]; then
135
            log_failure_msg "Failed to touch $lockfile"
136
            return 1
137
        fi
138
        log_success_msg
139
        return 0
140
}
141
 
142
stop() {
143
    echo -n "Stopping cgconfig service: "
144
    cgclear
145
    rm -f "$lockfile"
146
    log_success_msg
147
    return 0
148
}
149
 
150
trapped() {
151
    #
152
    # Do nothing
153
    #
154
    true
155
}
156
 
157
usage() {
158
    echo "$0 <start|stop|restart|condrestart|status>"
159
    exit 2
160
}
161
 
162
common() {
163
    #
164
    # main script work done here
165
    #
166
    trap "trapped ABRT" ABRT
167
    trap "trapped QUIT" QUIT
168
    trap "trapped TERM" TERM
169
    trap "trapped INT"   INT
170
}
171
 
172
restart() {
173
	common
174
	stop
175
	start
176
}
177
 
178
RETVAL=0
179
 
180
case $1 in
181
    'stop')
182
        common
183
        stop
184
        RETVAL=$?
185
        ;;
186
    'start')
187
        common
188
        start
189
        RETVAL=$?
190
        ;;
191
    'restart'|'reload')
192
	restart
193
        RETVAL=$?
194
        ;;
195
    'condrestart')
196
        if [ -f "$lockfile" ]; then
197
            restart
198
            RETVAL=$?
199
        fi
200
        ;;
201
    'status')
202
        if [ -f "$lockfile" ]; then
203
            echo "Running"
204
            exit 0
205
        else
206
            echo "Stopped"
207
            exit 3
208
        fi
209
	;;
210
    *)
211
        usage
212
        ;;
213
esac
214
 
215
exit $RETVAL