]>
Commit | Line | Data |
---|---|---|
59f6c21a | 1 | #!/bin/sh |
2 | # | |
7dbb2b59 | 3 | # pound |
59f6c21a | 4 | # |
5 | # chkconfig: 345 85 15 | |
6 | # description: reverse-proxy and load-balancer | |
7 | # | |
8 | ||
9 | # Source function library | |
10 | . /etc/rc.d/init.d/functions | |
11 | ||
12 | # Get network config | |
13 | . /etc/sysconfig/network | |
14 | ||
f33820c6 ER |
15 | # List of instances to start. |
16 | POUND_INSTANCES="pound" | |
17 | ||
59f6c21a | 18 | # Get service config |
19 | [ -f /etc/sysconfig/pound ] && . /etc/sysconfig/pound | |
20 | ||
21 | # Check that networking is up. | |
22 | if is_yes "${NETWORKING}"; then | |
1a0ae1a4 | 23 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then |
74738d13 | 24 | msg_network_down pound |
25 | exit 1 | |
26 | fi | |
59f6c21a | 27 | else |
74738d13 | 28 | exit 0 |
59f6c21a | 29 | fi |
30 | ||
e23f2808 ER |
31 | configtest() { |
32 | local instance="$1" | |
33 | pound -c -f /etc/pound/$instance.cfg > /dev/null | |
34 | } | |
35 | ||
36 | ||
19b8f25f ER |
37 | # check if the $1 instance is up |
38 | is_up() { | |
39 | local instance="$1" | |
40 | local pidfile=/var/run/pound/$instance.pid | |
41 | [ -f $pidfile ] || return 1 | |
42 | local pid=$(cat $pidfile) | |
43 | kill -0 $pid 2>/dev/null | |
44 | return $? | |
45 | } | |
46 | ||
e23f2808 ER |
47 | # check if any of the instances are up |
48 | any_up() { | |
49 | local ret=1 instance pidfile | |
50 | ||
51 | for pidfile in /var/run/pound/*.pid; do | |
52 | [ -f "$pidfile" ] || continue | |
53 | instance=${pidfile#/var/run/pound/} | |
54 | instance=${instance%.pid} | |
55 | is_up $instance || continue | |
56 | ret=0 | |
57 | done | |
58 | ||
59 | return $ret | |
60 | } | |
61 | ||
62 | # check if all of the instances are up | |
63 | all_up() { | |
41dc05d3 | 64 | local ret=1 instance pidfile |
e23f2808 ER |
65 | |
66 | for pidfile in /var/run/pound/*.pid; do | |
67 | [ -f "$pidfile" ] || continue | |
68 | instance=${pidfile#/var/run/pound/} | |
69 | instance=${instance%.pid} | |
70 | is_up $instance && continue | |
41dc05d3 | 71 | ret=0 |
e23f2808 ER |
72 | done |
73 | ||
74 | return $ret | |
75 | } | |
76 | ||
50de9853 | 77 | start() { |
e23f2808 ER |
78 | local ret started=0 found=0 instance |
79 | ||
19b8f25f | 80 | # Check if the service is already running? |
e23f2808 ER |
81 | if ! all_up; then |
82 | msg_starting "Pound"; started | |
19b8f25f | 83 | for instance in $POUND_INSTANCES; do |
e23f2808 ER |
84 | show "Starting Pound instance %s" "$instance" |
85 | if is_up $instance; then | |
86 | started | |
87 | continue | |
88 | fi | |
89 | ||
4ee2ad17 ER |
90 | PIDFILE=/var/run/pound/$instance.pid |
91 | start-stop-daemon --start \ | |
e23f2808 ER |
92 | --exec /usr/sbin/pound \ |
93 | --pidfile $PIDFILE -- -v -f /etc/pound/$instance.cfg -p $PIDFILE | |
19b8f25f | 94 | ret=$? |
e23f2808 | 95 | |
4ee2ad17 ER |
96 | if [ $ret -eq 0 ]; then |
97 | ok | |
5208430f ER |
98 | RETVAL=$ret |
99 | started=1 | |
e23f2808 | 100 | found=1 |
4ee2ad17 | 101 | else |
f4b0626e | 102 | fail |
5208430f | 103 | fi |
19b8f25f | 104 | done |
19b8f25f | 105 | |
e23f2808 | 106 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pound |
19b8f25f ER |
107 | else |
108 | msg_already_running "Pound" | |
109 | fi | |
50de9853 ER |
110 | } |
111 | ||
112 | stop() { | |
e23f2808 | 113 | local ret instance |
74738d13 | 114 | # Stop daemons. |
e23f2808 | 115 | if any_up; then |
44ac793d | 116 | msg_stopping "Pound"; started |
19b8f25f ER |
117 | for instance in $POUND_INSTANCES; do |
118 | is_up $instance || continue | |
e23f2808 | 119 | show "Stopping Pound instance %s" "$instance"; busy |
19b8f25f ER |
120 | killproc --pidfile pound/$instance.pid pound |
121 | ret=$? | |
122 | done | |
e23f2808 | 123 | rm -f /var/lock/subsys/pound > /dev/null 2>&1 |
41dc05d3 | 124 | rm -f /var/run/pound/$instance.pid > /dev/null 2>&1 |
19b8f25f ER |
125 | else |
126 | msg_not_running "Pound" | |
127 | fi | |
50de9853 ER |
128 | } |
129 | ||
194b939d | 130 | restart() { |
e23f2808 ER |
131 | local instance |
132 | ||
86406927 ER |
133 | if any_up; then |
134 | # make up list of configured and up instances | |
135 | local list | |
136 | show "Checking configuration"; busy | |
137 | for instance in $POUND_INSTANCES; do | |
138 | # skip ones whose config fails | |
139 | configtest $instance || continue | |
140 | list="$list $instance" | |
141 | done | |
e23f2808 | 142 | |
23b12d23 | 143 | # nothing left or never was |
f27d5c80 ER |
144 | if [ -z "$list" ]; then |
145 | fail | |
146 | return | |
147 | else | |
148 | POUND_INSTANCES=$list | |
149 | ok | |
150 | fi | |
151 | ||
86406927 | 152 | fi |
194b939d ER |
153 | |
154 | stop | |
155 | start | |
156 | } | |
157 | ||
901f3d9e ER |
158 | condrestart() { |
159 | if [ -f /var/lock/subsys/pound ]; then | |
160 | stop | |
161 | start | |
162 | else | |
163 | msg_not_running "Pound" | |
164 | RETVAL=$1 | |
165 | fi | |
166 | } | |
19b8f25f | 167 | |
e23f2808 | 168 | pound_status() { |
901f3d9e | 169 | local stat=1 pidfile instance |
e23f2808 | 170 | |
19b8f25f ER |
171 | nls "Configured Pound instances:" |
172 | echo " $POUND_INSTANCES" | |
173 | nls "Currently active Pound instances:" | |
19b8f25f ER |
174 | for pidfile in /var/run/pound/*.pid; do |
175 | [ -f "$pidfile" ] || continue | |
176 | instance=${pidfile#/var/run/pound/} | |
177 | instance=${instance%.pid} | |
178 | is_up $instance && echo -n " $instance($(cat $pidfile))" | |
179 | stat=0 | |
180 | done | |
181 | echo "" | |
182 | exit $stat | |
e23f2808 ER |
183 | } |
184 | ||
901f3d9e ER |
185 | if [ "$1" != status -a "$2" ]; then |
186 | POUND_INSTANCES="$2" | |
187 | fi | |
188 | ||
e23f2808 ER |
189 | RETVAL=0 |
190 | # See how we were called. | |
191 | case "$1" in | |
192 | start) | |
193 | start | |
194 | ;; | |
195 | stop) | |
196 | stop | |
197 | ;; | |
901f3d9e | 198 | restart) |
194b939d | 199 | restart |
59f6c21a | 200 | ;; |
901f3d9e ER |
201 | try-restart) |
202 | condrestart 0 | |
203 | ;; | |
204 | force-reload) | |
205 | condrestart 7 | |
206 | ;; | |
0b650d78 ER |
207 | flush-logs) |
208 | if [ -f /var/lock/subsys/pound ]; then | |
209 | for instance in $POUND_INSTANCES; do | |
210 | show "Rotating Pound logs for %s instance" $instance | |
211 | killproc --pidfile /var/run/pound/$instance.pid pound -USR1 | |
212 | ret=$? | |
213 | if [ $ret != 0 ]; then | |
214 | RETVAL=$ret | |
215 | fi | |
216 | done | |
217 | else | |
218 | msg_not_running "Pound" | |
219 | RETVAL=7 | |
220 | fi | |
221 | ;; | |
e890afb0 ER |
222 | status) |
223 | pound_status | |
224 | ;; | |
59f6c21a | 225 | *) |
901f3d9e | 226 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|flush-logs|status} [INSTANCE NAMES]" |
5917fcaf | 227 | exit 3 |
59f6c21a | 228 | esac |
229 | ||
230 | exit $RETVAL |