Advertisement
rockdrilla

/etc/init.d/cgred [rev.0]

Nov 10th, 2013
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.32 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:            cgrulesengd
  4. # Required-Start:      $local_fs $syslog $cgconfig
  5. # Required-Stop:       $local_fs $syslog
  6. # Should-Start:        
  7. # Should-Stop:        
  8. # Short-Description:   start and stop the cgroups rules engine daemon
  9. # Description:         CGroup Rules Engine is a tool \
  10. #                      for automatically using cgroups to classify processes
  11. ### END INIT INFO
  12.  
  13. NAME=cgred
  14. DESCR='cgroup rules engine daemon'
  15. CONF_RULES=/etc/cgrules.conf
  16. DEFAULTS=/etc/default/cgred
  17. PIDFILE=/run/${NAME}.pid
  18. CGRED_BIN=/usr/sbin/cgrulesengd
  19. PROCNAME=cgrulesengd
  20.  
  21. . /lib/lsb/init-functions
  22.  
  23. test -x ${CGRED_BIN} || {
  24.     log_failure_msg "${NAME}: missing executable ${CGRED_BIN}"
  25.     return 1
  26. }
  27.  
  28. OPTIONS=''
  29. test -s ${DEFAULTS} && . ${DEFAULTS}
  30.  
  31. OPTIONS="${NODAEMON} ${LOG}"
  32. test -n "${LOG_FILE}" && OPTIONS="${OPTIONS} --logfile=${LOG_FILE}"
  33. test -n "${SOCKET_USER}" && OPTIONS="${OPTIONS} -u ${SOCKET_USER}"
  34. test -n "${SOCKET_GROUP}" && OPTIONS="${OPTIONS} -g ${SOCKET_GROUP}"
  35.  
  36. DAEMON_OPT="--oknodo --quiet --pidfile ${PIDFILE} --exec ${CGRED_BIN} --retry 5"
  37.  
  38. start() {
  39. #   test -s ${PIDFILE} && {
  40. #       P=$(cat ${PIDFILE})
  41. #       log_warning_msg "${NAME}: already running with pid $P"
  42. #       return 0
  43. #   }
  44.  
  45.     test -s ${CONF_RULES} || {
  46.         log_failure_msg "${NAME}: not configured"
  47.         return 1
  48.     }
  49.  
  50.     egrep -qe "^cgroup" /proc/mounts 2>/dev/null || {
  51.         log_failure_msg "${NAME}: cannot find cgroups, is cgconfig service running?"
  52.         return 1
  53.     }
  54.  
  55.     start-stop-daemon ${DAEMON_OPT} --make-pidfile --start -- ${OPTIONS} || {
  56.         log_failure_msg "${NAME}: failed to start"
  57.         return 1
  58.     }
  59.  
  60.     log_success_msg "${NAME}: ${DESCR} is started"
  61.     return 0
  62. }
  63.  
  64. stop() {
  65.     test -s ${PIDFILE} || {
  66.         log_warning_msg "${NAME}: already stopped"
  67.         return 0
  68.     }
  69.  
  70.     start-stop-daemon ${DAEMON_OPT} --stop || {
  71.         log_failure_msg "${NAME}: failed to stop"
  72.         return 1
  73.     }
  74.  
  75.     housekeep
  76.  
  77.     log_success_msg "${NAME}: ${DESCR} has been stopped"
  78.     return 0
  79. }
  80.  
  81. restart() {
  82.     stop && sleep 1
  83.     start
  84. }
  85.  
  86. reload() {
  87.     status || {
  88. #       log_failure_msg "${NAME}: not running"
  89.         return 1
  90.     }
  91.  
  92.     pkill -s USR1 -F ${PIDFILE} && {
  93.         log_success_msg "${NAME}: reloading rules"
  94.     } || {
  95.         log_failure_msg "${NAME}: failed to reload rules"
  96.         return 1
  97.     }
  98.  
  99.     return 0
  100. }
  101.  
  102. status() {
  103.     start-stop-daemon ${DAEMON_OPT} --status
  104.     retval=$?
  105.     case "${retval}" in
  106.     0)
  107.         log_failure_msg "${NAME}: running"
  108.     ;;
  109.     1)
  110.         log_failure_msg "${NAME}: stopped; detected stale pid file"
  111. #       log_warning_msg "${NAME}: housekeeping"
  112. #       housekeep
  113.     ;;
  114.     3)
  115.         log_failure_msg "${NAME}: stopped"
  116.     ;;
  117.     *)
  118.         log_failure_msg "${NAME}: unable to determine service status"
  119.     ;;
  120.     esac
  121.  
  122.     return ${retval}
  123. }
  124.  
  125. housekeep() {
  126.     rm -f ${PIDFILE}
  127. }
  128.  
  129. usage() {
  130.     echo "Usage: $0 {start|stop|status|restart|reload}" >&2
  131.     exit 2
  132. }
  133.  
  134. RETVAL=0
  135. case "$1" in
  136. start)
  137.     start
  138.     RETVAL=$?
  139. ;;
  140. stop)
  141.     stop
  142.     RETVAL=$?
  143. ;;
  144. restart)
  145.     restart
  146.     RETVAL=$?
  147. ;;
  148. reload)
  149.     reload
  150.     RETVAL=$?
  151. ;;
  152. status)
  153.     status
  154.     RETVAL=$?
  155. ;;
  156. *)
  157.     usage
  158. ;;
  159. esac
  160.  
  161. exit ${RETVAL}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement