]>
Commit | Line | Data |
---|---|---|
382db189 JR |
1 | #!/bin/sh |
2 | # | |
3 | # cgred CGroups Rules Engine Daemon | |
4 | # chkconfig: - 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/cgred.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 | msg_staring "CGroup Rules Engine Daemon" | |
22 | if [ ! -s /etc/cgrules.conf ]; then | |
23 | log_failure_msg "not configured" | |
24 | return 6 | |
25 | fi | |
26 | if ! grep -qs "^cgroup" /proc/mounts ; then | |
27 | log_failure_msg "Cannot find cgroups, is cgconfig service running?" | |
28 | return 1 | |
29 | fi | |
30 | # Read in configuration options. | |
31 | OPTIONS="" | |
32 | if [ -f "/etc/sysconfig/cgred.conf" ] ; then | |
33 | . /etc/sysconfig/cgred.conf | |
34 | ||
35 | OPTIONS="$NODAEMON $LOG" | |
36 | [ -n "$LOG_FILE" ] && OPTIONS="$OPTIONS --logfile=$LOG_FILE" | |
37 | [ -n "$SOCKET_USER" ] && OPTIONS="$OPTIONS -u $SOCKET_USER" | |
38 | [ -n "$SOCKET_GROUP" ] && OPTIONS="$OPTIONS -g $SOCKET_GROUP" | |
39 | fi | |
40 | ||
41 | daemon --check cgred --pidfile /var/run/cgred.pid /sbin/cgrulesengd $OPTIONS | |
42 | RETVAL=$? | |
43 | if [ $RETVAL -ne 0 ]; then | |
44 | return 7 | |
45 | fi | |
46 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cgred | |
47 | echo "`pidof cgrulesengd`" > /var/run/cgred.pid | |
48 | } | |
49 | ||
50 | stop() { | |
51 | if [ -f /var/lock/subsys/cgred ]; then | |
52 | msg_stopping "CGroup Rules Engine Daemon" | |
53 | killproc -p /var/run/cgred.pid cgrulesengd -TERM | |
54 | RETVAL=$? | |
55 | if [ $RETVAL -eq 0 ] ; then | |
56 | rm -f /var/lock/subsys/cgred | |
57 | rm -f /var/run/cgred.pid | |
58 | fi | |
59 | else | |
60 | msg_not_running "CGroup Rules Engine Daemon" | |
61 | fi | |
62 | } | |
63 | ||
64 | RETVAL=0 | |
65 | # See how we are called | |
66 | case "$1" in | |
67 | start) | |
68 | start | |
69 | RETVAL=$? | |
70 | ;; | |
71 | stop) | |
72 | stop | |
73 | RETVAL=$? | |
74 | ;; | |
75 | status) | |
76 | status -p /var/run/cgred.pid cgred | |
77 | RETVAL=$? | |
78 | ;; | |
79 | restart) | |
80 | stop | |
81 | start | |
82 | ;; | |
83 | condrestart) | |
84 | if [ -f /var/lock/subsys/cgred ] ; then | |
85 | stop | |
86 | start | |
87 | fi | |
88 | ;; | |
89 | reload|flash) | |
90 | if [ -f /var/lock/subsys/cgred ] ; then | |
91 | show "Reloading rules configuration..." | |
92 | # SIGUSR2 | |
93 | kill -s 12 `cat ${pidfile}` | |
94 | RETVAL=$? | |
95 | if [ $RETVAL -eq 0 ] ; then | |
96 | fail | |
97 | else | |
98 | ok | |
99 | fi | |
100 | else | |
101 | msg_not_running "cgred" | |
102 | fi | |
103 | ;; | |
104 | *) | |
105 | msg_usage "$0 {start|stop|status|restart|condrestart|reload}" | |
106 | exit 3 | |
107 | ;; | |
108 | esac | |
109 | ||
110 | exit $RETVAL |