#!/bin/sh # # 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 # # Source function library . /etc/rc.d/init.d/functions start() { if [ -f "/var/lock/subsys/cgred" ] ; then msg_already_running "CGroup Rules Engine Daemon" return fi if [ ! -s /etc/cgrules.conf ]; then nls "CGroup Rules Engine Daemon not configured" return 6 fi if ! grep -qs "^cgroup" /proc/mounts ; then nls "Cannot find cgroups, is cgconfig service running?" return 1 fi msg_staring "CGroup Rules Engine Daemon" # Read in configuration options. OPTIONS="" if [ -f "/etc/sysconfig/cgred.conf" ] ; then . /etc/sysconfig/cgred.conf OPTIONS="$NODAEMON $LOG" [ -n "$LOG_FILE" ] && OPTIONS="$OPTIONS --logfile=$LOG_FILE" [ -n "$SOCKET_USER" ] && OPTIONS="$OPTIONS -u $SOCKET_USER" [ -n "$SOCKET_GROUP" ] && OPTIONS="$OPTIONS -g $SOCKET_GROUP" fi daemon --check cgred --pidfile /var/run/cgred.pid /sbin/cgrulesengd $OPTIONS RETVAL=$? if [ $RETVAL -ne 0 ]; then return 7 fi [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cgred echo "`pidof cgrulesengd`" > /var/run/cgred.pid } stop() { if [ -f /var/lock/subsys/cgred ]; then msg_stopping "CGroup Rules Engine Daemon" killproc -p /var/run/cgred.pid cgrulesengd -TERM RETVAL=$? if [ $RETVAL -eq 0 ] ; then rm -f /var/lock/subsys/cgred rm -f /var/run/cgred.pid fi else msg_not_running "CGroup Rules Engine Daemon" fi } RETVAL=0 # See how we are called case "$1" in start) start RETVAL=$? ;; stop) stop RETVAL=$? ;; status) status -p /var/run/cgred.pid cgred RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f /var/lock/subsys/cgred ] ; then stop start fi ;; reload|flash) if [ -f /var/lock/subsys/cgred ] ; then show "Reloading rules configuration..." # SIGUSR2 kill -s 12 `cat ${pidfile}` RETVAL=$? if [ $RETVAL -eq 0 ] ; then fail else ok fi else msg_not_running "cgred" fi ;; *) msg_usage "$0 {start|stop|status|restart|condrestart|reload}" exit 3 ;; esac exit $RETVAL