Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ### 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 INFO
- NAME=cgred
- DESCR='cgroup rules engine daemon'
- CONF_RULES=/etc/cgrules.conf
- DEFAULTS=/etc/default/cgred
- PIDFILE=/run/${NAME}.pid
- CGRED_BIN=/usr/sbin/cgrulesengd
- PROCNAME=cgrulesengd
- . /lib/lsb/init-functions
- test -x ${CGRED_BIN} || {
- log_failure_msg "${NAME}: missing executable ${CGRED_BIN}"
- return 1
- }
- OPTIONS=''
- test -s ${DEFAULTS} && . ${DEFAULTS}
- OPTIONS="${NODAEMON} ${LOG}"
- test -n "${LOG_FILE}" && OPTIONS="${OPTIONS} --logfile=${LOG_FILE}"
- test -n "${SOCKET_USER}" && OPTIONS="${OPTIONS} -u ${SOCKET_USER}"
- test -n "${SOCKET_GROUP}" && OPTIONS="${OPTIONS} -g ${SOCKET_GROUP}"
- DAEMON_OPT="--oknodo --quiet --pidfile ${PIDFILE} --exec ${CGRED_BIN} --retry 5"
- start() {
- # test -s ${PIDFILE} && {
- # P=$(cat ${PIDFILE})
- # log_warning_msg "${NAME}: already running with pid $P"
- # return 0
- # }
- test -s ${CONF_RULES} || {
- log_failure_msg "${NAME}: not configured"
- return 1
- }
- egrep -qe "^cgroup" /proc/mounts 2>/dev/null || {
- log_failure_msg "${NAME}: cannot find cgroups, is cgconfig service running?"
- return 1
- }
- start-stop-daemon ${DAEMON_OPT} --make-pidfile --start -- ${OPTIONS} || {
- log_failure_msg "${NAME}: failed to start"
- return 1
- }
- log_success_msg "${NAME}: ${DESCR} is started"
- return 0
- }
- stop() {
- test -s ${PIDFILE} || {
- log_warning_msg "${NAME}: already stopped"
- return 0
- }
- start-stop-daemon ${DAEMON_OPT} --stop || {
- log_failure_msg "${NAME}: failed to stop"
- return 1
- }
- housekeep
- log_success_msg "${NAME}: ${DESCR} has been stopped"
- return 0
- }
- restart() {
- stop && sleep 1
- start
- }
- reload() {
- status || {
- # log_failure_msg "${NAME}: not running"
- return 1
- }
- pkill -s USR1 -F ${PIDFILE} && {
- log_success_msg "${NAME}: reloading rules"
- } || {
- log_failure_msg "${NAME}: failed to reload rules"
- return 1
- }
- return 0
- }
- status() {
- start-stop-daemon ${DAEMON_OPT} --status
- retval=$?
- case "${retval}" in
- 0)
- log_failure_msg "${NAME}: running"
- ;;
- 1)
- log_failure_msg "${NAME}: stopped; detected stale pid file"
- # log_warning_msg "${NAME}: housekeeping"
- # housekeep
- ;;
- 3)
- log_failure_msg "${NAME}: stopped"
- ;;
- *)
- log_failure_msg "${NAME}: unable to determine service status"
- ;;
- esac
- return ${retval}
- }
- housekeep() {
- rm -f ${PIDFILE}
- }
- usage() {
- echo "Usage: $0 {start|stop|status|restart|reload}" >&2
- exit 2
- }
- RETVAL=0
- case "$1" in
- start)
- start
- RETVAL=$?
- ;;
- stop)
- stop
- RETVAL=$?
- ;;
- restart)
- restart
- RETVAL=$?
- ;;
- reload)
- reload
- RETVAL=$?
- ;;
- status)
- status
- RETVAL=$?
- ;;
- *)
- usage
- ;;
- esac
- exit ${RETVAL}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement