]> git.pld-linux.org Git - packages/libcgroup.git/blob - cgconfig.init
- up to 1.40rc1
[packages/libcgroup.git] / cgconfig.init
1 #!/bin/sh
2 #
3 # cgconfig      Control Groups Configuration Startup
4 # chkconfig:    2345 01 99
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
13 [ -f /etc/sysconfig/cgconfig ] && . /etc/sysconfig/cgconfig
14
15 mount_cgroup() {
16         if [ -n "`grep /sys/fs/cgroup /proc/mounts`" ]; then
17                 return 0
18         fi
19
20         # kernel provides cgroups?
21         if [ ! -e /proc/cgroups ]; then
22                 return 0
23         fi
24
25         run_cmd "Mounting /sys/fs/cgroup" mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
26 }
27
28 umount_cgroup() {
29         # If /sys/fs/cgroup is not mounted, we don't bother
30         if [ -z "`grep /sys/fs/cgroup /proc/mounts`" ]; then
31                 return 0
32         fi
33
34         # Don't try to get too smart, just optimistically try to umount all
35         # that we think we mounted
36         run_cmd "Unmounting /sys/fs/cgroup" umount /sys/fs/cgroup
37         return $?
38 }
39
40 start() {
41         # Check if the service is already running?
42         if [ -f /var/lock/subsys/cgconfig ]; then
43                 msg_already_running "cgconfig"
44                 return
45         fi
46         if [ ! -s /etc/cgconfig.conf ]; then
47                 nls "/etc/cgconfig.conf is not configured"
48                 RETVAL=6
49                 return
50         fi
51         mount_cgroup
52         msg_starting "cgconfig"; busy
53         local out
54         out=$(/sbin/cgconfigparser -l /etc/cgconfig.conf 2>&1)
55         RETVAL=$?
56         if [ $RETVAL -ne 0 ]; then
57                 fail
58                 [ "$out" ] && echo >&2 "$out"
59                 exit $RETVAL
60         fi
61
62         RETVAL=$?
63         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cgconfig
64         ok
65 }
66
67 stop() {
68         if [ ! -f /var/lock/subsys/cgconfig ]; then
69                 msg_not_running "cgconfig"
70                 return
71         fi
72
73         msg_stopping "cgconfig"
74         cgclear
75         RETVAL=$?
76         cgclear
77         rm -f /var/lock/subsys/cgconfig
78         ok
79         umount_cgroup
80 }
81
82 condrestart() {
83         if [ ! -f /var/lock/subsys/cgconfig ]; then
84                 msg_not_running "cgconfig"
85                 RETVAL=$1
86                 return
87         fi
88
89         stop
90         start
91 }
92
93 RETVAL=0
94 case "$1" in
95   start)
96         start
97         ;;
98   stop)
99         stop
100         ;;
101   restart)
102         stop
103         start
104         ;;
105   try-restart)
106         condrestart 0
107         ;;
108   force-reload)
109         condrestart 7
110         ;;
111   status)
112         if [ -f /var/lock/subsys/cgconfig ] ; then
113                 echo "Running"
114                 exit 0
115         else
116                 echo "Stopped"
117                 exit 3
118         fi
119         ;;
120   *)
121         msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
122         exit 3
123         ;;
124 esac
125
126 exit $RETVAL
This page took 0.058703 seconds and 3 git commands to generate.