Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > d05f6404dc47873ab7005b8d2a404f13 > files > 12

libcgroup-0.36.2-7.fc14.x86_64.rpm

#!/bin/bash
#
# 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:
# Should-Stop:
# Short-Description:    start and stop the WLM configuration
# Description:          This script allows us to create a default configuration
### END INIT INFO

# get correct location of binaries from configure
prefix=/usr;exec_prefix=/usr;sbindir=/sbin
CGCONFIGPARSER_BIN=$sbindir/cgconfigparser
CGROUP_FS=cgroup
CONFIG_FILE=/etc/cgconfig.conf

# support multiple mount points
declare -a MOUNTPOINT
declare -a MOUNTOPTS
maxindex=0
servicename=cgconfig

#
# Source LSB routines
#
. /etc/rc.d/init.d/functions
log_success_msg () {
    echo -n $*; success "$*"; echo
}
log_failure_msg () {
    echo -n $*; failure "$*"; echo
}
log_warning_msg () {
    echo -n $*; warning "$*"; echo
}

# read the config
CREATE_DEFAULT=yes
if [ -e /etc/sysconfig/cgconfig ]; then
        . /etc/sysconfig/cgconfig
fi

create_default_groups() {
        declare defaultcgroup

        if [ -f /etc/cgrules.conf ]
        then
            read user ctrl defaultcgroup <<< \
		`grep -m1 '^\*[[:space:]]\+' /etc/cgrules.conf`
            if [[ -n $defaultcgroup && $defaultcgroup = "*" ]]
            then
                log_warning_msg "/etc/cgrules.conf incorrect"
                log_warning_msg "Overriding it"
                defaultcgroup=
            fi
        fi

        if [ -z $defaultcgroup ]
        then
            defaultcgroup=sysdefault/
        fi

        #
        # Find all mounted subsystems and create comma-separated list
        # of controllers.
        #
        controllers=`lssubsys 2>/dev/null | tr '\n' ',' | sed s/.$//`

        #
        # Create the default group, ignore errors when the default group
        # already exists.
        #
        cgcreate -g $controllers:$defaultcgroup 2>/dev/null

        #
        # special rule for cpusets
        #
        if echo $controllers | grep -q -w cpuset; then
                cpus=`cgget -nv -r cpuset.cpus /`
                cgset -r cpuset.cpus=$cpus $defaultcgroup
                mems=`cgget -nv -r cpuset.mems /`
                cgset -r cpuset.mems=$mems $defaultcgroup
        fi

        #
        # 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() {
        echo -n "Starting cgconfig service: "
	if [ -f /var/lock/subsys/$servicename ]
        then
            log_warning_msg "lock file already exists"
            return
        fi

        if [ $? -eq 0 ]
        then
                if [ ! -s $CONFIG_FILE ]
                then
                    log_failure_msg $CONFIG_FILE "is not configured"
                    return 6
                fi

                $CGCONFIGPARSER_BIN -l $CONFIG_FILE
                retval=$?
                if [ $retval -ne 0 ]
                then
                    log_failure_msg "Failed to parse " $CONFIG_FILE
                    return $retval
                fi
        fi

        if [ $CREATE_DEFAULT == "yes" ]; then
                create_default_groups
        fi

        touch /var/lock/subsys/$servicename
        retval=$?
        if [ $retval -ne 0 ]
        then
            log_failure_msg "Failed to touch " /var/lock/subsys/$servicename
            return $retval
        fi
        log_success_msg
        return 0
}

stop() {
    echo -n "Stopping cgconfig service: "
    cgclear
    rm -f /var/lock/subsys/$servicename
    log_success_msg
}

trapped() {
    #
    # Do nothing
    #
    true
}

usage() {
    echo "$0 <start|stop|restart|condrestart|status>"
    exit 1
}

common() {
    #
    # main script work done here
    #
    trap "trapped ABRT" ABRT
    trap "trapped QUIT" QUIT
    trap "trapped TERM" TERM
    trap "trapped INT"   INT
}

case $1 in
    'stop')
        common
        stop;
        ;;
    'start')
        common
        start;
        ;;
    'restart')
        common
	stop
        start
        ;;
    'reload')
        common
	stop
        start
        ;;
    'condrestart')
        if [ -f /var/lock/subsys/$servicename ] ; then
            stop
            start
        fi
        ;;
    'status')
        if [ -f /var/lock/subsys/$servicename ] ; then
            echo "Running"
            exit 0
        else
            echo "Stopped"
            exit 3
        fi
	;;
    *)
        usage
        ;;
esac