]>
Commit | Line | Data |
---|---|---|
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 | 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 | rm -f /var/lock/subsys/cgred /var/run/cgrulesengd.pid | |
63 | } | |
64 | ||
65 | reload() { | |
66 | if [ ! -f /var/lock/subsys/cgred ] ; then | |
67 | msg_not_running "CGroup Rules Engine Daemon" | |
68 | return | |
69 | fi | |
70 | ||
71 | show "Reloading rules configuration..." | |
72 | # SIGUSR2 | |
73 | kill -s 12 $(cat ${pidfile}) | |
74 | RETVAL=$? | |
75 | if [ $RETVAL -eq 0 ]; then | |
76 | fail | |
77 | else | |
78 | ok | |
79 | fi | |
80 | } | |
81 | ||
82 | condrestart() { | |
83 | if [ ! -f /var/lock/subsys/cgred ]; then | |
84 | msg_not_running "CGroup Rules Engine Daemon" | |
85 | RETVAL=$1 | |
86 | return | |
87 | fi | |
88 | ||
89 | stop | |
90 | start | |
91 | } | |
92 | ||
93 | RETVAL=0 | |
94 | # See how we are called | |
95 | case "$1" in | |
96 | start) | |
97 | start | |
98 | ;; | |
99 | stop) | |
100 | stop | |
101 | ;; | |
102 | restart) | |
103 | stop | |
104 | start | |
105 | ;; | |
106 | reload) | |
107 | reload | |
108 | ;; | |
109 | try-restart) | |
110 | condrestart 0 | |
111 | ;; | |
112 | force-reload) | |
113 | condrestart 7 | |
114 | ;; | |
115 | status) | |
116 | status --pidfile /var/run/cgrulesengd.pid cgrulesengd | |
117 | RETVAL=$? | |
118 | ;; | |
119 | *) | |
120 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}" | |
121 | exit 3 | |
122 | ;; | |
123 | esac | |
124 | ||
125 | exit $RETVAL |