File initd_cgconfig of Package libcgroup1.import4148
#!/bin/bash
#
# Start/Stop the workload manager
#
# Copyright IBM Corporation. 2008
#
# Copyright (c) 2008, Jiri Slaby <jslaby@suse.cz>
#
# 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: 2345 80 20
# 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: $local_fs $remote_fs $syslog $time
# Required-Stop: $local_fs $remote_fs $syslog $time
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop the WLM configuration
# Description: This script allows us to create a default configuration
### END INIT INFO
CGCONFIG_BIN=/usr/sbin/cgconfigparser
test -x $CGCONFIG_BIN || exit 5
PATH=/bin:/usr/bin:/sbin:/usr/sbin:.
MOUNTS_FILE=/proc/mounts
PROC_CGROUPS_FILE=/proc/cgroups
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
#
. /lib/lsb/init-functions
parse_mounts() {
while read name mountpt fs opts other; do
if echo $name | grep -q $CGROUP_FS; then
maxindex=$(($maxindex+1))
MOUNTPOINT[$maxindex]=$mountpt
MOUNTOPTS[$maxindex]=$opts
fi
done < $MOUNTS_FILE
return 0;
}
umount_fs() {
for i in `seq 1 $maxindex`; do
umount ${MOUNTPOINT[$i]}
rmdir ${MOUNTPOINT[$i]}
done
}
start() {
if [ -f /var/lock/subsys/$servicename ]; then
log_warning_msg "lock file already exists"
return 1
fi
#log_progress_msg "Starting cgconfig service: "
$CGCONFIG_BIN -l $CONFIG_FILE
[ $? -ne 0 ] && return 7
touch /var/lock/subsys/$servicename
defaultcgroup=
if [ -f /etc/cgrules.conf ]; then
read user ctrl defaultcgroup <<< \
`grep -m1 '^*' /etc/cgrules.conf`
if [ "X$defaultcgroup" = "X*" ]; then
log_warning_msg "/etc/cgrules.conf default cgroup" \
"incorrect. Overriding it"
defaultcgroup=
fi
fi
if [ -z $defaultcgroup ]; then
defaultcgroup=sysdefault/
fi
#
# Create a default class for tasks to return back to
#
parse_mounts
for i in `seq 1 $maxindex`; do
#
# Ignore if directory already exists
#
mkdir ${MOUNTPOINT[$i]}/$defaultcgroup 2> /dev/null
chmod a+rw ${MOUNTPOINT[$i]}/$defaultcgroup/tasks
#
# special rule for cpusets
#
if echo ${MOUNTOPTS[$i]} | grep -q -w cpuset; then
cat ${MOUNTPOINT[$i]}/cpuset.cpus > \
${MOUNTPOINT[$i]}/$defaultcgroup/cpuset.cpus
cat ${MOUNTPOINT[$i]}/cpuset.mems > \
${MOUNTPOINT[$i]}/$defaultcgroup/cpuset.mems
fi
#
# classify everything to default cgroup
#
for j in `ps --no-headers -eL o tid`; do
echo $j > ${MOUNTPOINT[$i]}/$defaultcgroup/tasks \
2>/dev/null
done
done
return 0
}
move_all_to_init_class() {
for i in `seq 1 $maxindex`; do
cd ${MOUNTPOINT[$i]}
if ! grep -wq ${MOUNTPOINT[$i]} /proc/mounts; then
log_failure_msg "resource control filesystem not mounted"
exit 1
fi
for i in `find . -depth -type d`; do
case $i in
'.')
;;
*)
class=${i#./*}
#log_progress_msg "Removing class $class"
sed -nu p < ./$i/tasks > tasks
rmdir $i
;;
esac
done
cd - > /dev/null
done
}
stop() {
move_all_to_init_class
umount_fs
rm -f /var/lock/subsys/$servicename
}
trapped() {
true
}
common() {
#
# main script work done here
#
trap "trapped ABRT" ABRT
trap "trapped QUIT" QUIT
trap "trapped TERM" TERM
trap "trapped INT" INT
parse_mounts
}
restart() {
common
stop
start
}
case $1 in
'stop')
echo -n "Stopping service $servicename"
common
stop
rc_failed 0
rc_status -v
;;
'start')
echo -n "Starting service $servicename"
common
start
rc_status -v
;;
'restart')
restart
rc_status
;;
'reload')
restart
rc_status -v
;;
'condrestart')
test -f /var/lock/subsys/$servicename && restart
rc_status
;;
'status')
echo -n "Checking for service $servicename"
if [ -f /var/lock/subsys/$servicename ] ; then
rc_failed 0
else
rc_failed 3
fi
rc_status -v
;;
*)
echo "$0 <start|stop|restart|condrestart|status>"
exit 1
;;
esac