#!/bin/sh # # cgred CGroups Rules Engine Daemon # chkconfig: 2345 02 98 # description: This is a daemon for automatically classifying processes \ # into cgroups based on UID/GID. # # processname: cgrulesengd # 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 msg_already_running "CGroup Rules Engine Daemon" return fi if [ ! -s /etc/cgrules.conf ]; then nls "CGroup Rules Engine Daemon not configured" RETVAL=6 return fi if ! grep -qs "^cgroup" /proc/mounts; then nls "Cannot find cgroups, is cgconfig service running?" RETVAL=1 return fi msg_starting "CGroup Rules Engine Daemon" daemon --pidfile /var/run/cgrulesengd.pid /sbin/cgrulesengd $OPTIONS RETVAL=$? if [ $RETVAL -ne 0 ]; then return 7 fi touch /var/lock/subsys/cgred pidof cgrulesengd > /var/run/cgrulesengd.pid } stop() { 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 # See how we are called case "$1" in start) start ;; stop) stop ;; restart) stop start ;; reload) reload ;; try-restart) condrestart 0 ;; force-reload) condrestart 7 ;; status) status --pidfile /var/run/cgrulesengd.pid cgrulesengd RETVAL=$? ;; *) msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}" exit 3 ;; esac exit $RETVAL