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