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