Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 99 lines (86 sloc) 2.401 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

. /etc/conf.d/cgconfig

# From cgconfig init.d script
create_default_groups() {
        declare defaultcgroup

        if [ -f /etc/cgrules.conf ]
        then
read user ctrl defaultcgroup <<< \
                $(grep -m1 ^\* /etc/cgrules.conf)
            if [[ -n $defaultcgroup && $defaultcgroup = "*" ]]
            then
defaultcgroup=
            fi
fi

if [ -z $defaultcgroup ]
        then
defaultcgroup=sysdefault/
        fi

        #
        # Find all mounted subsystems and create comma-separated list
        # of controllers.
        #
        controllers=$(lssubsys 2>/dev/null | tr '\n' ',' | sed s/.$//)

        #
        # Create the default group, ignore errors when the default group
        # already exists.
        #
        cgcreate -g $controllers:$defaultcgroup 2>/dev/null

        #
        # special rule for cpusets
        #
        if echo $controllers | grep -q -w cpuset; then
cpus=$(cgget -nv -r cpuset.cpus /)
                cgset -r cpuset.cpus=$cpus $defaultcgroup
                mems=$(cgget -nv -r cpuset.mems /)
                cgset -r cpuset.mems=$mems $defaultcgroup
        fi

        #
        # special rule for cpus
        #
        if echo $controllers | grep -q -w cpu; then
rt_runtime_us=$(cgget -nv -r cpu.rt_runtime_us /)
                cgset -r cpu.rt_runtime_us=$rt_runtime_us $defaultcgroup
        fi

        #
        # 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 || :
}

case "$1" in
  start)
    stat_busy "Starting CGroups configuration"
    /usr/sbin/cgconfigparser -l /etc/cgconfig.conf
    if [ $? -gt 0 ]; then
stat_fail
    else
if [ $CREATE_DEFAULT == "yes" ]; then
create_default_groups
      fi
add_daemon cgconfig
      stat_done
    fi
    ;;
  stop)
    stat_busy "Clearing CGroups configuration"
    cgclear
    if [ $? -gt 0 ]; then
stat_fail
    else
rm_daemon cgconfig
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac

# vim:set ft=sh:
Something went wrong with that request. Please try again.