]> git.pld-linux.org Git - packages/libcgroup.git/blame - cgconfig.init
- started work on PLD init scripts
[packages/libcgroup.git] / cgconfig.init
CommitLineData
382db189
JR
1#!/bin/sh
2#
3# cgconfig Control Groups Configuration Startup
4# chkconfig: - 5 95
5# description: This script runs the cgconfigparser utility to parse and setup \
6# the control group filesystem. It uses /etc/cgconfig.conf \
7# and parses the configuration specified in there.
8
9# Source function library
10. /etc/rc.d/init.d/functions
11
12# read the config
13CREATE_DEFAULT=yes
14[ -f /etc/sysconfig/cgconfig ] && . /etc/sysconfig/cgconfig
15
16create_default_groups() {
17 local defaultcgroup
18
19 if [ -f /etc/cgrules.conf ]; then
20 defaultcgroup=$(awk '/^\*[\t ]+/ { print $3; exit }' /etc/cgrules.conf)
21 if [ -n "$defaultcgroup" -a "$defaultcgroup" = "*" ]; then
22 log_warning_msg "/etc/cgrules.conf incorrect"
23 log_warning_msg "Overriding it"
24 defaultcgroup=
25 fi
26 fi
27
28 if [ -z $defaultcgroup ]; then
29 defaultcgroup=sysdefault/
30 fi
31
32 #
33 # Find all mounted subsystems and create comma-separated list
34 # of controllers.
35 #
36 controllers=`lssubsys 2>/dev/null | tr '\n' ',' | sed s/.$//`
37
38 #
39 # Create the default group, ignore errors when the default group
40 # already exists.
41 #
42 cgcreate -f 664 -d 775 -g $controllers:$defaultcgroup 2>/dev/null
43
44 #
45 # special rule for cpusets
46 #
47 if echo $controllers | grep -q -w cpuset; then
48 cpus=`cgget -nv -r cpuset.cpus /`
49 cgset -r cpuset.cpus=$cpus $defaultcgroup
50 mems=`cgget -nv -r cpuset.mems /`
51 cgset -r cpuset.mems=$mems $defaultcgroup
52 fi
53
54 #
55 # Classify everything to default cgroup. Ignore errors, some processes
56 # may exit after ps is run and before cgclassify moves them.
57 #
58 cgclassify -g $controllers:$defaultcgroup `ps --no-headers -eL o tid` 2>/dev/null || :
59}
60
61start() {
62 # Check if the service is already running?
63 if [ -f /var/lock/subsys/cgconfig ]; then
64 msg_already_running "cgconfig"
65 return
66 fi
67
68 msg_starting "cgconfig"
69 if [ ! -s /etc/cgconfig.conf ]; then
70 log_failure_msg "/etc/cgconfig.conf is not configured"
71 return 6
72 fi
73
74 /sbin/cgconfigparser -l /etc/cgconfig.conf
75 retval=$?
76 if [ $retval -ne 0 ]; then
77 log_failure_msg "Failed to parse /etc/cgconfig.conf"
78 return 1
79 fi
80
81 if [ $CREATE_DEFAULT = "yes" ]; then
82 create_default_groups
83 fi
84
85 touch /var/lock/subsys/cgconfig
86 retval=$?
87 if [ $retval -ne 0 ]; then
88 log_failure_msg "Failed to touch /var/lock/subsys/cgconfig"
89 return 1
90 fi
91 ok
92}
93
94stop() {
95 if [ -f /var/lock/subsys/cgconfig ]; then
96 msg_stopping "cgconfig"
97 cgclear
98 rm -f /var/lock/subsys/cgconfig
99 ok
100 else
101 msg_not_running "cgconfig"
102 fi
103}
104
105RETVAL=0
106
107case "$1" in
108 start)
109 start
110 ;;
111 stop)
112 stop;
113 ;;
114 restart|reload)
115 stop
116 start
117 ;;
118 condrestart)
119 if [ -f /var/lock/subsys/cgconfig ] ; then
120 stop
121 start
122 fi
123 ;;
124 status)
125 if [ -f /var/lock/subsys/cgconfig ] ; then
126 echo "Running"
127 exit 0
128 else
129 echo "Stopped"
130 exit 3
131 fi
132 ;;
133 *)
134 msg_usage "$0 {start|stop|restart|condrestart|status}"
135 exit 3
136 ;;
137esac
138
139exit $RETVAL
This page took 0.056619 seconds and 4 git commands to generate.