#!/bin/sh
#
# cgred CGroups Rules Engine Daemon
-# chkconfig: 2345 14 86
+# chkconfig: 2345 02 98
# description: This is a daemon for automatically classifying processes \
# into cgroups based on UID/GID.
#
# processname: cgrulesengd
-# pidfile: /var/run/cgred.pid
+# pidfile: /var/run/cgrulesengd.pid
#
# Source function library
. /etc/rc.d/init.d/functions
+# Read in configuration options.
+[ -f /etc/sysconfig/cgred ] && . /etc/sysconfig/cgred
+
start() {
- if [ -f "/var/lock/subsys/cgred" ] ; then
+ 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
+ RETVAL=6
+ return
fi
- if ! grep -qs "^cgroup" /proc/mounts ; then
+ if ! grep -qs "^cgroup" /proc/mounts; then
nls "Cannot find cgroups, is cgconfig service running?"
- return 1
+ RETVAL=1
+ return
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
+ msg_starting "CGroup Rules Engine Daemon"
- daemon --check cgred --pidfile /var/run/cgred.pid /sbin/cgrulesengd $OPTIONS
+ daemon --pidfile /var/run/cgrulesengd.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
+ touch /var/lock/subsys/cgred
+ pidof cgrulesengd > /var/run/cgrulesengd.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
+ if [ ! -f /var/lock/subsys/cgred ]; then
+ msg_not_running "CGroup Rules Engine Daemon"
+ return
+ fi
+
+ msg_stopping "CGroup Rules Engine Daemon"
+ killproc --pidfile /var/run/cgrulesengd.pid cgrulesengd -TERM
+ RETVAL=$?
+ rm -f /var/lock/subsys/cgred /var/run/cgrulesengd.pid
+}
+
+reload() {
+ if [ ! -f /var/lock/subsys/cgred ] ; then
+ msg_not_running "CGroup Rules Engine Daemon"
+ return
+ fi
+
+ show "Reloading rules configuration..."
+ # SIGUSR2
+ kill -s 12 $(cat ${pidfile})
+ RETVAL=$?
+ if [ $RETVAL -eq 0 ]; then
+ fail
else
+ ok
+ fi
+}
+
+condrestart() {
+ if [ ! -f /var/lock/subsys/cgred ]; then
msg_not_running "CGroup Rules Engine Daemon"
+ RETVAL=$1
+ return
fi
+
+ stop
+ start
}
RETVAL=0
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)
+ reload
;;
- 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
+ try-restart)
+ condrestart 0
+ ;;
+ force-reload)
+ condrestart 7
+ ;;
+ status)
+ status --pidfile /var/run/cgrulesengd.pid cgrulesengd
+ RETVAL=$?
;;
*)
- msg_usage "$0 {start|stop|status|restart|condrestart|reload}"
+ msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
exit 3
;;
esac