View difference between Paste ID: RCHa3uqR and iitiBqsk
SHOW: | | - or go back to the newest paste.
1
#!/bin/sh
2-
#
2+
3-
# Start/Stop the workload manager
3+
# Provides:            cgconfig
4-
#
4+
# Required-Start:      $local_fs $syslog
5-
# Copyright IBM Corporation. 2008
5+
# Required-Stop:       $local_fs $syslog
6-
#
6+
# Should-Start:        
7-
# Authors:     Balbir Singh <balbir@linux.vnet.ibm.com>
7+
# Should-Stop:         
8-
# This program is free software; you can redistribute it and/or modify it
8+
# Short-Description:   create and setup control group filesystem(s)
9-
# under the terms of version 2.1 of the GNU Lesser General Public License
9+
# Description:         Create and setup control group filesystem(s)
10-
# as published by the Free Software Foundation.
10+
11-
#
11+
12-
# This program is distributed in the hope that it would be useful, but
12+
13-
# WITHOUT ANY WARRANTY; without even the implied warranty of
13+
14-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
CONF_D=/etc/cgroups.d
15-
#
15+
16-
# cgconfig Control Groups Configuration Startup
16+
17-
# chkconfig: - 5 95
17+
LOCKFILE=/run/lock/${NAME}.lock
18-
# description: This script runs the cgconfigparser utility to parse and setup
18+
CGPARSER_BIN=/usr/sbin/cgconfigparser
19-
#              the control group filesystem. It uses /etc/cgconfig.conf
19+
20-
#              and parses the configuration specified in there.
20+
21
. /lib/lsb/init-functions
22
23-
# Provides:             cgconfig
23+
test -x ${CGPARSER_BIN} || {
24-
# Required-Start:
24+
    log_failure_msg "${NAME}: missing executable ${CGPARSER_BIN}"
25-
# Required-Stop:
25+
    return 1
26-
# Should-Start:         ypbind
26+
27-
# Should-Stop:          ypbind
27+
28-
# Short-Description:    Create and setup control group filesystem(s)
28+
29-
# Description:          Create and setup control group filesystem(s)
29+
test -s ${DEFAULTS} && . ${DEFAULTS}
30
31
test -n "${CGROUP_LOGLEVEL}" && export CGROUP_LOGLEVEL
32
33
create_default_groups() {
34
    defaultcgroup=
35
36-
LOCK=/run/lock/${NAME}.lock
36+
37-
CGCONFIGPARSER=/usr/sbin/cgconfigparser
37+
38
        T=$(mktemp)
39
        echo "$L" > $T
40-
# sanity checks
40+
41-
test -x ${CGCONFIGPARSER} || exit 0
41+
42
        test -n "${defaultcgroup}" -a "${defaultcgroup}" = "*" && {
43-
# source LSB routines
43+
44
            defaultcgroup=
45
        }
46-
# read the config
46+
47
48-
test -f ${DEFAULTS} && . ${DEFAULTS}
48+
49
        defaultcgroup=default/
50
    }
51
52
    # find all mounted subsystems and create comma-separated list
53
    # of controllers.
54
    controllers=$(lssubsys 2>/dev/null | tr '\n' ',' | sed -e 's/.$//')
55
56
    # create the default group, ignore errors when the default group
57
    # already exists.
58
    cgcreate -f 664 -d 775 -g ${controllers}:${defaultcgroup} 2>/dev/null
59
60
    # special rule for cpusets
61
    echo ${controllers} | grep -q -w cpuset && {
62
        cpus=$(cgget -nv -r cpuset.cpus /)
63
        cgset -r cpuset.cpus=${cpus} ${defaultcgroup}
64
        mems=$(cgget -nv -r cpuset.mems /)
65
        cgset -r cpuset.mems=${mems} ${defaultcgroup}
66
    }
67-
        defaultcgroup=sysdefault/
67+
68
    # classify everything to default cgroup. Ignore errors, some processes
69
    # may exit after ps is run and before cgclassify moves them.
70
    cgclassify -g ${controllers}:${defaultcgroup} $(ps --no-headers -eL o tid) \
71
    2>/dev/null || :
72
}
73
74
start() {
75
    test -f ${LOCKFILE} && {
76
        log_warning_msg "${NAME}: already running"
77
        return 0
78
    }
79
80
    test -s ${CONFIG} || {
81
        log_failure_msg "${NAME}: not configured"
82
        return 6
83
    }
84
85
    mountpoint -q ${CGROOT} || {
86
        mount -t tmpfs cgroup_root ${CGROOT} -o mode=0755 || {
87
            log_failure_msg "${NAME}: failed to mount cgroup_root"
88
            return 1
89
        }
90
    }
91
92
    ${CGPARSER_BIN} -l ${CONFIG} || {
93-
    test -f ${LOCK} && {
93+
94-
        log_warning_msg "${NAME}: lock file already exists"
94+
95
    }
96
97
    test ${CREATE_DEFAULT} = "yes" && {
98
        create_default_groups || {
99-
        log_failure_msg "${NAME}: ${CONFIG} is not configured"
99+
100
            return 1
101
        }
102
    }
103
104
    umask 0077
105
    touch ${LOCKFILE} || {
106
        log_failure_msg "${NAME}: failed to create lock file"
107
        return 1
108
    }
109
110-
    ${CGCONFIGPARSER} -l ${CONFIG} || {
110+
111
    return 0
112
}
113
114
stop() {
115
#   cgclear -l ${CONFIG} || {
116
    cgclear || {
117
        log_failure_msg "${NAME}: failed to clear cgroups"
118
        return 1
119
    }
120
121
    mountpoint -q ${CGROOT} && {
122
        umount ${CGROOT} || {
123-
    touch ${LOCK} || {
123+
124
            return 1
125
        }
126
    }
127
128
    rm -f ${LOCKFILE}
129
130
    log_success_msg "${NAME}: stopping"
131
    return 0
132
}
133-
#    cgclear -l ${CONFIG} || {
133+
134
restart() {
135
    stop && sleep 1
136
    start
137
}
138
139
status() {
140
    test -f ${LOCKFILE} && {
141
        log_success_msg "${NAME}: running"
142
    } || {
143
        log_failure_msg "${NAME}: stopped"
144
        return 3
145
    }
146-
    rm -f ${LOCK}
146+
147
}
148
149
usage() {
150
    echo "Usage: $0 {start|stop|status|restart|reload|force-reload}" >&2
151
    exit 2
152-
trapped() {
152+
153-
    # do nothing
153+
154-
    :
154+
155
case "$1" in
156
stop)
157
    stop
158-
    echo "$0 <start|stop|restart|condrestart|status>"
158+
159
;;
160
start)
161
    start
162-
common() {
162+
163-
    trap "trapped ABRT" ABRT
163+
164-
    trap "trapped QUIT" QUIT
164+
restart|reload)
165-
    trap "trapped TERM" TERM
165+
166-
    trap "trapped INT"   INT
166+
167
;;
168
force-reload)
169
    rm -f ${LOCKFILE}
170-
    common
170+
171
    RETVAL=$?
172
;;
173
status)
174
    status
175
    RETVAL=$?
176
;;
177-
case $1 in
177+
178-
'stop')
178+
179-
    common
179+
180
esac
181
182
exit ${RETVAL}