Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ### BEGIN INIT INFO
- # Provides: cgconfig
- # Required-Start: $local_fs $syslog
- # Required-Stop: $local_fs $syslog
- # Should-Start:
- # Should-Stop:
- # Short-Description: create and setup control group filesystem(s)
- # Description: Create and setup control group filesystem(s)
- ### END INIT INFO
- NAME=cgconfig
- CONFIG=/etc/cgconfig.conf
- CONF_D=/etc/cgroups.d
- CONF_RULES=/etc/cgrules.conf
- DEFAULTS=/etc/default/${NAME}
- LOCKFILE=/run/lock/${NAME}.lock
- CGPARSER_BIN=/usr/sbin/cgconfigparser
- CGROOT=/sys/fs/cgroup
- . /lib/lsb/init-functions
- test -x ${CGPARSER_BIN} || {
- log_failure_msg "${NAME}: missing executable ${CGPARSER_BIN}"
- return 1
- }
- CREATE_DEFAULT=yes
- test -s ${DEFAULTS} && . ${DEFAULTS}
- test -n "${CGROUP_LOGLEVEL}" && export CGROUP_LOGLEVEL
- create_default_groups() {
- defaultcgroup=
- test -s ${CONF_RULES} && {
- L=$(grep -m1 '^\*[[:space:]]\+' ${CONF_RULES})
- T=$(mktemp)
- echo "$L" > $T
- read user ctrl defaultcgroup < $T
- rm $T
- test -n "${defaultcgroup}" -a "${defaultcgroup}" = "*" && {
- log_warning_msg "${CONF_RULES} incorrect; overriding it"
- defaultcgroup=
- }
- }
- test -z "${defaultcgroup}" && {
- defaultcgroup=default/
- }
- # find all mounted subsystems and create comma-separated list
- # of controllers.
- controllers=$(lssubsys 2>/dev/null | tr '\n' ',' | sed -e 's/.$//')
- # create the default group, ignore errors when the default group
- # already exists.
- cgcreate -f 664 -d 775 -g ${controllers}:${defaultcgroup} 2>/dev/null
- # special rule for cpusets
- echo ${controllers} | grep -q -w cpuset && {
- cpus=$(cgget -nv -r cpuset.cpus /)
- cgset -r cpuset.cpus=${cpus} ${defaultcgroup}
- mems=$(cgget -nv -r cpuset.mems /)
- cgset -r cpuset.mems=${mems} ${defaultcgroup}
- }
- # classify everything to default cgroup. Ignore errors, some processes
- # may exit after ps is run and before cgclassify moves them.
- cgclassify -g ${controllers}:${defaultcgroup} $(ps --no-headers -eL o tid) \
- 2>/dev/null || :
- }
- start() {
- test -f ${LOCKFILE} && {
- log_warning_msg "${NAME}: already running"
- return 0
- }
- test -s ${CONFIG} || {
- log_failure_msg "${NAME}: not configured"
- return 6
- }
- mountpoint -q ${CGROOT} || {
- mount -t tmpfs cgroup_root ${CGROOT} -o mode=0755 || {
- log_failure_msg "${NAME}: failed to mount cgroup_root"
- return 1
- }
- }
- ${CGPARSER_BIN} -l ${CONFIG} || {
- log_failure_msg "${NAME}: failed to parse ${CONFIG}"
- return 1
- }
- test ${CREATE_DEFAULT} = "yes" && {
- create_default_groups || {
- log_failure_msg "${NAME}: failed to set up default groups"
- return 1
- }
- }
- umask 0077
- touch ${LOCKFILE} || {
- log_failure_msg "${NAME}: failed to create lock file"
- return 1
- }
- log_success_msg "${NAME}: starting"
- return 0
- }
- stop() {
- # cgclear -l ${CONFIG} || {
- cgclear || {
- log_failure_msg "${NAME}: failed to clear cgroups"
- return 1
- }
- mountpoint -q ${CGROOT} && {
- umount ${CGROOT} || {
- log_failure_msg "${NAME}: failed to unmount cgroup_root"
- return 1
- }
- }
- rm -f ${LOCKFILE}
- log_success_msg "${NAME}: stopping"
- return 0
- }
- restart() {
- stop && sleep 1
- start
- }
- status() {
- test -f ${LOCKFILE} && {
- log_success_msg "${NAME}: running"
- } || {
- log_failure_msg "${NAME}: stopped"
- return 3
- }
- return 0
- }
- usage() {
- echo "Usage: $0 {start|stop|status|restart|reload|force-reload}" >&2
- exit 2
- }
- RETVAL=0
- case "$1" in
- stop)
- stop
- RETVAL=$?
- ;;
- start)
- start
- RETVAL=$?
- ;;
- restart|reload)
- restart
- RETVAL=$?
- ;;
- force-reload)
- rm -f ${LOCKFILE}
- restart
- RETVAL=$?
- ;;
- status)
- status
- RETVAL=$?
- ;;
- *)
- usage
- ;;
- esac
- exit ${RETVAL}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement