]> git.pld-linux.org Git - packages/libcgroup.git/blob - cgred.init
- 0.38.rc1
[packages/libcgroup.git] / cgred.init
1 #!/bin/sh
2 #
3 # cgred         CGroups Rules Engine Daemon
4 # chkconfig:    2345 02 98
5 # description:  This is a daemon for automatically classifying processes \
6 #               into cgroups based on UID/GID.
7 #
8 # processname:  cgrulesengd
9 # pidfile:      /var/run/cgrulesengd.pid
10 #
11
12 # Source function library
13 . /etc/rc.d/init.d/functions
14
15 # Read in configuration options.
16 [ -f /etc/sysconfig/cgred ] && . /etc/sysconfig/cgred
17
18 start() {
19         if [ -f /var/lock/subsys/cgred ]; then
20                 msg_already_running "CGroup Rules Engine Daemon"
21                 return
22         fi
23
24         if [ ! -s /etc/cgrules.conf ]; then
25                 nls "CGroup Rules Engine Daemon not configured"
26                 RETVAL=6
27                 return
28         fi
29         if ! grep -qs "^cgroup" /proc/mounts; then
30                 nls "Cannot find cgroups, is cgconfig service running?"
31                 RETVAL=1
32                 return
33         fi
34
35         msg_starting "CGroup Rules Engine Daemon"
36
37         daemon --pidfile /var/run/cgrulesengd.pid /sbin/cgrulesengd $OPTIONS
38         RETVAL=$?
39         if [ $RETVAL -ne 0 ]; then
40                 return 7
41         fi
42         touch /var/lock/subsys/cgred
43         pidof cgrulesengd > /var/run/cgrulesengd.pid
44 }
45
46 stop() {
47         if [ ! -f /var/lock/subsys/cgred ]; then
48                 msg_not_running "CGroup Rules Engine Daemon"
49                 return
50         fi
51
52         msg_stopping "CGroup Rules Engine Daemon"
53         killproc --pidfile /var/run/cgrulesengd.pid cgrulesengd -TERM
54         RETVAL=$?
55         rm -f /var/lock/subsys/cgred /var/run/cgrulesengd.pid
56 }
57
58 reload() {
59         if [ ! -f /var/lock/subsys/cgred ] ; then
60                 msg_not_running "CGroup Rules Engine Daemon"
61                 return
62         fi
63
64         show "Reloading rules configuration..."
65         # SIGUSR2
66         kill -s 12 $(cat ${pidfile})
67         RETVAL=$?
68         if [ $RETVAL -eq 0 ]; then
69                 fail
70         else
71                 ok
72         fi
73 }
74
75 condrestart() {
76         if [ ! -f /var/lock/subsys/cgred ]; then
77                 msg_not_running "CGroup Rules Engine Daemon"
78                 RETVAL=$1
79                 return
80         fi
81
82         stop
83         start
84 }
85
86 RETVAL=0
87 # See how we are called
88 case "$1" in
89   start)
90         start
91         ;;
92   stop)
93         stop
94         ;;
95   restart)
96         stop
97         start
98         ;;
99   reload)
100         reload
101         ;;
102   try-restart)
103         condrestart 0
104         ;;
105   force-reload)
106         condrestart 7
107         ;;
108   status)
109         status --pidfile /var/run/cgrulesengd.pid cgrulesengd
110         RETVAL=$?
111         ;;
112   *)
113         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
114         exit 3
115         ;;
116 esac
117
118 exit $RETVAL
This page took 0.038497 seconds and 3 git commands to generate.