Subversion Repositories configs

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 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
8 - 36
CONFIG_DIR=/etc/cgconfig.d
3 - 37
servicename=cgconfig
38
lockfile=/var/lock/subsys/$servicename
39
 
40
#
41
# Source LSB routines
42
#
43
. /etc/rc.d/init.d/functions
44
log_success_msg () {
45
    echo -n $*; success "$*"; echo
46
}
47
log_failure_msg () {
48
    echo -n $*; failure "$*"; echo
49
}
50
log_warning_msg () {
51
    echo -n $*; warning "$*"; echo
52
}
53
 
54
# read the config
55
CREATE_DEFAULT=yes
56
if [ -e /etc/sysconfig/cgconfig ]; then
57
        . /etc/sysconfig/cgconfig
58
fi
59
 
60
create_default_groups() {
61
	defaultcgroup=
62
 
63
        if [ -f /etc/cgrules.conf ]; then
64
	    read user ctrl defaultcgroup <<< \
65
		    $(grep -m1 '^\*[[:space:]]\+' /etc/cgrules.conf)
66
            if [ -n "$defaultcgroup" -a "$defaultcgroup" = "*" ]; then
67
                log_warning_msg "/etc/cgrules.conf incorrect"
68
                log_warning_msg "Overriding it"
69
                defaultcgroup=
70
            fi
71
        fi
72
 
73
        if [ -z $defaultcgroup ]
74
        then
75
            defaultcgroup=sysdefault/
76
        fi
77
 
78
        #
79
        # Find all mounted subsystems and create comma-separated list
80
        # of controllers.
81
        #
82
        controllers=`lssubsys 2>/dev/null | tr '\n' ',' | sed s/.$//`
83
 
84
        #
85
        # Create the default group, ignore errors when the default group
86
        # already exists.
87
        #
88
        cgcreate -f 664 -d 775 -g $controllers:$defaultcgroup 2>/dev/null
89
 
90
        #
91
        # special rule for cpusets
92
        #
93
        if echo $controllers | grep -q -w cpuset; then
94
                cpus=`cgget -nv -r cpuset.cpus /`
95
                cgset -r cpuset.cpus=$cpus $defaultcgroup
96
                mems=`cgget -nv -r cpuset.mems /`
97
                cgset -r cpuset.mems=$mems $defaultcgroup
98
        fi
99
 
100
        #
101
        # Classify everything to default cgroup. Ignore errors, some processes
102
        # may exit after ps is run and before cgclassify moves them.
103
        #
104
        cgclassify -g $controllers:$defaultcgroup `ps --no-headers -eL o tid` \
105
                 2>/dev/null || :
106
}
107
 
108
start() {
109
        echo -n "Starting cgconfig service: "
110
	if [ -f "$lockfile" ]; then
111
            log_warning_msg "lock file already exists"
112
            return 0
113
        fi
114
 
115
        if [ $? -eq 0 ]; then
116
                if [ ! -s $CONFIG_FILE ]; then
117
                    log_failure_msg $CONFIG_FILE "is not configured"
118
                    return 6
119
                fi
120
 
8 - 121
                $CGCONFIGPARSER_BIN -l $CONFIG_FILE -L $CONFIG_DIR
3 - 122
                retval=$?
123
                if [ $retval -ne 0 ]; then
8 - 124
                    log_failure_msg "Failed to parse " $CONFIG_FILE " or " $CONFIG_DIR
3 - 125
                    return 1
126
                fi
127
        fi
128
 
129
        if [ $CREATE_DEFAULT = "yes" ]; then
130
                create_default_groups
131
        fi
132
 
133
        touch "$lockfile"
134
        retval=$?
135
        if [ $retval -ne 0 ]; then
136
            log_failure_msg "Failed to touch $lockfile"
137
            return 1
138
        fi
139
        log_success_msg
140
        return 0
141
}
142
 
143
stop() {
144
    echo -n "Stopping cgconfig service: "
145
    cgclear
146
    rm -f "$lockfile"
147
    log_success_msg
148
    return 0
149
}
150
 
151
trapped() {
152
    #
153
    # Do nothing
154
    #
155
    true
156
}
157
 
158
usage() {
159
    echo "$0 <start|stop|restart|condrestart|status>"
160
    exit 2
161
}
162
 
163
common() {
164
    #
165
    # main script work done here
166
    #
167
    trap "trapped ABRT" ABRT
168
    trap "trapped QUIT" QUIT
169
    trap "trapped TERM" TERM
170
    trap "trapped INT"   INT
171
}
172
 
173
restart() {
174
	common
175
	stop
176
	start
177
}
178
 
179
RETVAL=0
180
 
181
case $1 in
182
    'stop')
183
        common
184
        stop
185
        RETVAL=$?
186
        ;;
187
    'start')
188
        common
189
        start
190
        RETVAL=$?
191
        ;;
192
    'restart'|'reload')
193
	restart
194
        RETVAL=$?
195
        ;;
196
    'condrestart')
197
        if [ -f "$lockfile" ]; then
198
            restart
199
            RETVAL=$?
200
        fi
201
        ;;
202
    'status')
203
        if [ -f "$lockfile" ]; then
204
            echo "Running"
205
            exit 0
206
        else
207
            echo "Stopped"
208
            exit 3
209
        fi
210
	;;
211
    *)
212
        usage
213
        ;;
214
esac
215
 
216
exit $RETVAL