Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > e8c6c611ace9cc724ad93617ca00a396 > files > 14

cgroup-0.38-5.mga5.i586.rpm

#!/bin/bash
#
# Start/Stop the CGroups Rules Engine Daemon
#
# Copyright Red Hat Inc. 2008
#
# Authors:	Steve Olivieri <sjo@redhat.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.
#
# cgred		CGroups Rules Engine Daemon
# chkconfig:	- 14 86
# description:	This is a daemon for automatically classifying processes \
#		into cgroups based on UID/GID.
#
# processname: cgrulesengd
# pidfile: /var/run/cgred.pid
#
### BEGIN INIT INFO
# Provides:		cgrulesengd
# Required-Start:	$local_fs $syslog $cgconfig
# Required-Stop:	$local_fs $syslog
# Default-Stop:
# Should-Start:		
# Should-Stop:		
# Short-Description:	start and stop the cgroups rules engine daemon
# Description:		CGroup Rules Engine is a tool for automatically using \
#			cgroups to classify processes
### END INIT INFO

prefix=/usr;exec_prefix=/usr;sbindir=/sbin
CGRED_BIN=$sbindir/cgrulesengd
CGRED_CONF=/etc/cgrules.conf

# Sanity checks
[ -x $CGRED_BIN ] || exit 1

# Source function library & LSB routines
. /etc/rc.d/init.d/functions
. /lib/lsb/init-functions

# Read in configuration options.
if [ -f "/etc/sysconfig/cgred.conf" ] ; then
	. /etc/sysconfig/cgred.conf
	OPTIONS="$NODAEMON $LOG"
	if [ -n "$LOG_FILE" ]; then
		OPTIONS="$OPTIONS --logfile=$LOG_FILE"
	fi
	if [ -n "$SOCKET_USER" ]; then
		OPTIONS="$OPTIONS -u $SOCKET_USER"
	fi
	if [ -n "$SOCKET_GROUP" ]; then
		OPTIONS="$OPTIONS -g $SOCKET_GROUP"
	fi
else
	OPTIONS=""
fi

# For convenience
processname=cgrulesengd
servicename=cgred
lockfile="/var/lock/subsys/$servicename"
pidfile=/var/run/cgred.pid

start()
{
	gprintf "Starting CGroup Rules Engine Daemon: "
	if [ -f "$lockfile" ]; then
		log_failure_msg "%s is already running with PID `cat %s`" "$servicename" "${pidfile}"
		return 0
	fi
	if [ ! -s $CGRED_CONF ]; then
		log_failure_msg "not configured"
		return 6
	fi
	if ! grep "^cgroup" /proc/mounts &>/dev/null; then
		echo
		log_failure_msg $"Cannot find cgroups, is cgconfig service running?"
		return 1
	fi
	daemon --check $servicename --pidfile $pidfile $CGRED_BIN $OPTIONS
	retval=$?
	echo
	if [ $retval -ne 0 ]; then
		return 7
	fi
	touch "$lockfile"
	if [ $? -ne 0 ]; then
		return 1
	fi
	echo "`pidof $processname`" > $pidfile
	return 0
}

stop()
{
	gprintf "Stopping CGroup Rules Engine Daemon..."
	if [ ! -f $pidfile ]; then
		log_success_msg
		return 0
	fi
	killproc -p $pidfile -TERM "$processname"
	retval=$?
	echo
	if [ $retval -ne 0 ]; then
		return 1
	fi
	rm -f "$lockfile" "$pidfile"
	return 0
}

RETVAL=0

# See how we are called
case "$1" in
	start)
		start
		RETVAL=$?
		;;
	stop)
		stop
		RETVAL=$?
		;;
	status)
		status -p $pidfile $servicename
		RETVAL=$?
		;;
	restart)
		stop
		start
		RETVAL=$?
		;;
	condrestart)
		if [ -f "$lockfile" ]; then
			stop
			start
			RETVAL=$?
		fi
		;;
	reload|flash)
		if [ -f "$lockfile" ]; then
			gprintf "Reloading rules configuration...\n"
			kill -s 12 `cat ${pidfile}`
			RETVAL=$?
			if [ $RETVAL -eq 0 ] ; then
				log_success_msg
			else
				log_failure_msg
			fi
		else
			log_failure_msg "%s is not running." "$servicename"
		fi
		;;
	*)
		gprintf "Usage: %s {start|stop|status|restart|condrestart|reload}\n" "$0"
		RETVAL=2
		;;
esac

exit $RETVAL