Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # Start/Stop the workload manager
- #
- # Copyright IBM Corporation. 2008
- #
- # Authors: Balbir Singh <balbir@linux.vnet.ibm.com>
- # This program is free software; you can redistribute it and/or modify it
- # under the terms of version 2.1 of the GNU Lesser General Public License
- # as published by the Free Software Foundation.
- #
- # This program is distributed in the hope that it would be useful, but
- # WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- #
- # cgconfig Control Groups Configuration Startup
- # chkconfig: - 5 95
- # description: This script runs the cgconfigparser utility to parse and setup
- # the control group filesystem. It uses /etc/cgconfig.conf
- # and parses the configuration specified in there.
- ### BEGIN INIT INFO
- # Provides: cgconfig
- # Required-Start:
- # Required-Stop:
- # Should-Start: ypbind
- # Should-Stop: ypbind
- # Short-Description: Create and setup control group filesystem(s)
- # Description: Create and setup control group filesystem(s)
- ### END INIT INFO
- NAME=cgconfig
- CONFIG=/etc/cgconfig.conf
- CONF_RULES=/etc/cgrules.conf
- DEFAULTS=/etc/default/${NAME}
- LOCK=/run/lock/${NAME}.lock
- CGCONFIGPARSER=/usr/sbin/cgconfigparser
- CGROOT=/sys/fs/cgroup
- # sanity checks
- test -x ${CGCONFIGPARSER} || exit 0
- # source LSB routines
- . /lib/lsb/init-functions
- # read the config
- CREATE_DEFAULT=yes
- test -f ${DEFAULTS} && . ${DEFAULTS}
- test -n "${CGROUP_LOGLEVEL}" && export CGROUP_LOGLEVEL
- create_default_groups() {
- defaultcgroup=
- test -s ${CONF_RULES} && {
- L=$(grep -m1 '^\*[[:space:]]\+' ${CONF_RULES})
- T=$(mktemp)
- echo "$L" > $T
- read user ctrl defaultcgroup < $T
- rm $T
- test -n "${defaultcgroup}" -a "${defaultcgroup}" = "*" && {
- log_warning_msg "${CONF_RULES} incorrect; overriding it"
- defaultcgroup=
- }
- }
- test -z "${defaultcgroup}" && {
- defaultcgroup=sysdefault/
- }
- # find all mounted subsystems and create comma-separated list
- # of controllers.
- controllers=$(lssubsys 2>/dev/null | tr '\n' ',' | sed -e 's/.$//')
- # create the default group, ignore errors when the default group
- # already exists.
- cgcreate -f 664 -d 775 -g ${controllers}:${defaultcgroup} 2>/dev/null
- # special rule for cpusets
- echo ${controllers} | grep -q -w cpuset && {
- cpus=$(cgget -nv -r cpuset.cpus /)
- cgset -r cpuset.cpus=${cpus} ${defaultcgroup}
- mems=$(cgget -nv -r cpuset.mems /)
- cgset -r cpuset.mems=${mems} ${defaultcgroup}
- }
- # classify everything to default cgroup. Ignore errors, some processes
- # may exit after ps is run and before cgclassify moves them.
- cgclassify -g ${controllers}:${defaultcgroup} $(ps --no-headers -eL o tid) \
- 2>/dev/null || :
- }
- start() {
- test -f ${LOCK} && {
- log_warning_msg "${NAME}: lock file already exists"
- return 0
- }
- test -s ${CONFIG} || {
- log_failure_msg "${NAME}: ${CONFIG} is not configured"
- return 6
- }
- mountpoint -q ${CGROOT} || {
- mount -t tmpfs cgroup_root ${CGROOT} -o mode=0755 || {
- log_failure_msg "${NAME}: failed to mount cgroup_root"
- return 1
- }
- }
- ${CGCONFIGPARSER} -l ${CONFIG} || {
- log_failure_msg "${NAME}: failed to parse ${CONFIG}"
- return 1
- }
- test ${CREATE_DEFAULT} = "yes" && {
- create_default_groups || {
- log_failure_msg "${NAME}: failed to set up default groups"
- return 1
- }
- }
- umask 0077
- touch ${LOCK} || {
- log_failure_msg "${NAME}: failed to create lock file"
- return 1
- }
- log_success_msg "${NAME}: starting"
- return 0
- }
- stop() {
- # cgclear -l ${CONFIG} || {
- cgclear || {
- log_failure_msg "${NAME}: failed to clear cgroups"
- return 1
- }
- mountpoint -q ${CGROOT} && {
- umount ${CGROOT} || {
- log_failure_msg "${NAME}: failed to unmount cgroup_root"
- return 1
- }
- }
- rm -f ${LOCK}
- log_success_msg "${NAME}: stopping"
- return 0
- }
- trapped() {
- # do nothing
- :
- }
- usage() {
- echo "$0 <start|stop|restart|condrestart|status>"
- exit 2
- }
- common() {
- trap "trapped ABRT" ABRT
- trap "trapped QUIT" QUIT
- trap "trapped TERM" TERM
- trap "trapped INT" INT
- }
- restart() {
- common
- stop
- start
- }
- RETVAL=0
- case $1 in
- 'stop')
- common
- stop
- RETVAL=$?
- ;;
- 'start')
- common
- start
- RETVAL=$?
- ;;
- 'restart'|'reload')
- restart
- RETVAL=$?
- ;;
- 'condrestart')
- test -f ${LOCK} && {
- restart
- RETVAL=$?
- }
- ;;
- 'force-restart'|'force-reload')
- rm -f ${LOCK}
- restart
- RETVAL=$?
- ;;
- 'status')
- test -f ${LOCK} && {
- log_success_msg "${NAME}: running"
- RETVAL=0
- } || {
- log_failure_msg "${NAME}: stopped"
- RETVAL=3
- }
- ;;
- *)
- usage
- ;;
- esac
- exit ${RETVAL}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement