Rev 4 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/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: - 29 71# 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# 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 INFOprefix=/usr;exec_prefix=/usr;sbindir=/sbinCGRED_BIN=$sbindir/cgrulesengdCGRED_CONF=/etc/cgrules.conf# Sanity checks[ -x $CGRED_BIN ] || exit 1# Source function library & LSB routines. /etc/rc.d/init.d/functionslog_success_msg () {echo -n $*; success "$*"; echo}log_failure_msg () {echo -n $*; failure "$*"; echo}log_warning_msg () {echo -n $*; warning "$*"; echo}# Read in configuration options.if [ -f "/etc/sysconfig/cgred.conf" ] ; then. /etc/sysconfig/cgred.confOPTIONS="$NODAEMON $LOG"if [ -n "$LOG_FILE" ]; thenOPTIONS="$OPTIONS --logfile=$LOG_FILE"fiif [ -n "$SOCKET_USER" ]; thenOPTIONS="$OPTIONS -u $SOCKET_USER"fiif [ -n "$SOCKET_GROUP" ]; thenOPTIONS="$OPTIONS -g $SOCKET_GROUP"fielseOPTIONS=""fi# For convenienceprocessname=cgrulesengdservicename=cgredlockfile="/var/lock/subsys/$servicename"pidfile=/var/run/cgred.pidstart(){echo -n $"Starting CGroup Rules Engine Daemon: "if [ -f "$lockfile" ]; thenlog_failure_msg "$servicename is already running with PID `cat ${pidfile}`"return 0fiif ! grep "^cgroup" /proc/mounts &>/dev/null; thenecholog_failure_msg $"Cannot find cgroups, is cgconfig service running?"return 1fidaemon --check $servicename --pidfile $pidfile $CGRED_BIN $OPTIONSretval=$?echoif [ $retval -ne 0 ]; thenreturn 7fitouch "$lockfile"if [ $? -ne 0 ]; thenreturn 1fiecho "`pidof $processname`" > $pidfile[[ -x /sbin/restorecon ]] && /sbin/restorecon $pidfilereturn 0}stop(){echo -n $"Stopping CGroup Rules Engine Daemon..."if [ ! -f $pidfile ]; thenlog_success_msgreturn 0fikillproc -p $pidfile -TERM "$processname"retval=$?echoif [ $retval -ne 0 ]; thenreturn 1firm -f "$lockfile" "$pidfile"return 0}RETVAL=0# See how we are calledcase "$1" instart)startRETVAL=$?;;stop)stopRETVAL=$?;;status)status -p $pidfile $servicenameRETVAL=$?;;restart)stopstartRETVAL=$?;;condrestart)if [ -f "$lockfile" ]; thenstopstartRETVAL=$?fi;;reload|flash)if [ -f "$lockfile" ]; thenecho $"Reloading rules configuration..."kill -s 12 `cat ${pidfile}`RETVAL=$?if [ $RETVAL -eq 0 ] ; thenlog_success_msgelselog_failure_msgfielselog_failure_msg "$servicename is not running."fi;;*)echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"RETVAL=2;;esacexit $RETVAL