Advertisement
rockdrilla

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

Nov 9th, 2013
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.11 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Start/Stop the workload manager
  4. #
  5. # Copyright IBM Corporation. 2008
  6. #
  7. # Authors:     Balbir Singh <balbir@linux.vnet.ibm.com>
  8. # This program is free software; you can redistribute it and/or modify it
  9. # under the terms of version 2.1 of the GNU Lesser General Public License
  10. # as published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it would be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. #
  16. # cgconfig Control Groups Configuration Startup
  17. # chkconfig: - 5 95
  18. # description: This script runs the cgconfigparser utility to parse and setup
  19. #              the control group filesystem. It uses /etc/cgconfig.conf
  20. #              and parses the configuration specified in there.
  21.  
  22. ### BEGIN INIT INFO
  23. # Provides:             cgconfig
  24. # Required-Start:
  25. # Required-Stop:
  26. # Should-Start:         ypbind
  27. # Should-Stop:          ypbind
  28. # Short-Description:    Create and setup control group filesystem(s)
  29. # Description:          Create and setup control group filesystem(s)
  30. ### END INIT INFO
  31.  
  32. NAME=cgconfig
  33. CONFIG=/etc/cgconfig.conf
  34. CONF_RULES=/etc/cgrules.conf
  35. DEFAULTS=/etc/default/${NAME}
  36. LOCK=/run/lock/${NAME}.lock
  37. CGCONFIGPARSER=/usr/sbin/cgconfigparser
  38. CGROOT=/sys/fs/cgroup
  39.  
  40. # sanity checks
  41. test -x ${CGCONFIGPARSER} || exit 0
  42.  
  43. # source LSB routines
  44. . /lib/lsb/init-functions
  45.  
  46. # read the config
  47. CREATE_DEFAULT=yes
  48. test -f ${DEFAULTS} && . ${DEFAULTS}
  49. test -n "${CGROUP_LOGLEVEL}" && export CGROUP_LOGLEVEL
  50.  
  51. create_default_groups() {
  52.     defaultcgroup=
  53.  
  54.     test -s ${CONF_RULES} && {
  55.         L=$(grep -m1 '^\*[[:space:]]\+' ${CONF_RULES})
  56.         T=$(mktemp)
  57.         echo "$L" > $T
  58.         read user ctrl defaultcgroup < $T
  59.         rm $T
  60.         test -n "${defaultcgroup}" -a "${defaultcgroup}" = "*" && {
  61.             log_warning_msg "${CONF_RULES} incorrect; overriding it"
  62.             defaultcgroup=
  63.         }
  64.     }
  65.  
  66.     test -z "${defaultcgroup}" && {
  67.         defaultcgroup=sysdefault/
  68.     }
  69.  
  70.     # find all mounted subsystems and create comma-separated list
  71.     # of controllers.
  72.     controllers=$(lssubsys 2>/dev/null | tr '\n' ',' | sed -e 's/.$//')
  73.  
  74.     # create the default group, ignore errors when the default group
  75.     # already exists.
  76.     cgcreate -f 664 -d 775 -g ${controllers}:${defaultcgroup} 2>/dev/null
  77.  
  78.     # special rule for cpusets
  79.     echo ${controllers} | grep -q -w cpuset && {
  80.         cpus=$(cgget -nv -r cpuset.cpus /)
  81.         cgset -r cpuset.cpus=${cpus} ${defaultcgroup}
  82.         mems=$(cgget -nv -r cpuset.mems /)
  83.         cgset -r cpuset.mems=${mems} ${defaultcgroup}
  84.     }
  85.  
  86.     # classify everything to default cgroup. Ignore errors, some processes
  87.     # may exit after ps is run and before cgclassify moves them.
  88.     cgclassify -g ${controllers}:${defaultcgroup} $(ps --no-headers -eL o tid) \
  89.     2>/dev/null || :
  90. }
  91.  
  92. start() {
  93.     test -f ${LOCK} && {
  94.         log_warning_msg "${NAME}: lock file already exists"
  95.         return 0
  96.     }
  97.  
  98.     test -s ${CONFIG} || {
  99.         log_failure_msg "${NAME}: ${CONFIG} is not configured"
  100.         return 6
  101.     }
  102.  
  103.     mountpoint -q ${CGROOT} || {
  104.         mount -t tmpfs cgroup_root ${CGROOT} -o mode=0755 || {
  105.             log_failure_msg "${NAME}: failed to mount cgroup_root"
  106.             return 1
  107.         }
  108.     }
  109.  
  110.     ${CGCONFIGPARSER} -l ${CONFIG} || {
  111.         log_failure_msg "${NAME}: failed to parse ${CONFIG}"
  112.         return 1
  113.     }
  114.  
  115.     test ${CREATE_DEFAULT} = "yes" && {
  116.         create_default_groups || {
  117.             log_failure_msg "${NAME}: failed to set up default groups"
  118.             return 1
  119.         }
  120.     }
  121.  
  122.     umask 0077
  123.     touch ${LOCK} || {
  124.         log_failure_msg "${NAME}: failed to create lock file"
  125.         return 1
  126.     }
  127.  
  128.     log_success_msg "${NAME}: starting"
  129.     return 0
  130. }
  131.  
  132. stop() {
  133. #    cgclear -l ${CONFIG} || {
  134.     cgclear || {
  135.         log_failure_msg "${NAME}: failed to clear cgroups"
  136.         return 1
  137.     }
  138.  
  139.     mountpoint -q ${CGROOT} && {
  140.         umount ${CGROOT} || {
  141.             log_failure_msg "${NAME}: failed to unmount cgroup_root"
  142.             return 1
  143.         }
  144.     }
  145.  
  146.     rm -f ${LOCK}
  147.  
  148.     log_success_msg "${NAME}: stopping"
  149.     return 0
  150. }
  151.  
  152. trapped() {
  153.     # do nothing
  154.     :
  155. }
  156.  
  157. usage() {
  158.     echo "$0 <start|stop|restart|condrestart|status>"
  159.     exit 2
  160. }
  161.  
  162. common() {
  163.     trap "trapped ABRT" ABRT
  164.     trap "trapped QUIT" QUIT
  165.     trap "trapped TERM" TERM
  166.     trap "trapped INT"   INT
  167. }
  168.  
  169. restart() {
  170.     common
  171.     stop
  172.     start
  173. }
  174.  
  175. RETVAL=0
  176.  
  177. case $1 in
  178. 'stop')
  179.     common
  180.     stop
  181.     RETVAL=$?
  182. ;;
  183. 'start')
  184.     common
  185.     start
  186.     RETVAL=$?
  187. ;;
  188. 'restart'|'reload')
  189.     restart
  190.     RETVAL=$?
  191. ;;
  192. 'condrestart')
  193.     test -f ${LOCK} && {
  194.         restart
  195.         RETVAL=$?
  196.     }
  197. ;;
  198. 'force-restart'|'force-reload')
  199.     rm -f ${LOCK}
  200.     restart
  201.     RETVAL=$?
  202. ;;
  203. 'status')
  204.     test -f ${LOCK} && {
  205.         log_success_msg "${NAME}: running"
  206.         RETVAL=0
  207.     } || {
  208.         log_failure_msg "${NAME}: stopped"
  209.         RETVAL=3
  210.     }
  211. ;;
  212. *)
  213.     usage
  214. ;;
  215. esac
  216.  
  217. exit ${RETVAL}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement