]> git.pld-linux.org Git - packages/pound.git/blame_incremental - pound.init
- updated URL (apsis.ch no longer works), note on pound-4 branch
[packages/pound.git] / pound.init
... / ...
CommitLineData
1#!/bin/sh
2#
3# pound
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
15# List of instances to start.
16POUND_INSTANCES="pound"
17
18# Get service config
19[ -f /etc/sysconfig/pound ] && . /etc/sysconfig/pound
20
21# Check that networking is up.
22if is_yes "${NETWORKING}"; then
23 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
24 msg_network_down pound
25 exit 1
26 fi
27else
28 exit 0
29fi
30
31configtest() {
32 local instance="$1"
33 pound -c -f /etc/pound/$instance.yaml > /dev/null
34}
35
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
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() {
63 local ret=1 instance pidfile
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
70 ret=0
71 done
72
73 return $ret
74}
75
76start() {
77 local ret started=0 found=0 instance
78
79 # Check if the service is already running?
80 if all_up; then
81 msg_already_running "Pound"
82 return
83 fi
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.yaml -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
110}
111
112stop() {
113 # Stop daemons.
114 if ! any_up; then
115 msg_not_running "Pound"
116 return
117 fi
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
129}
130
131restart() {
132 local instance
133
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
143
144 # nothing left or never was
145 if [ -z "$list" ]; then
146 fail
147 return
148 else
149 POUND_INSTANCES=$list
150 ok
151 fi
152
153 fi
154
155 stop
156 start
157}
158
159condrestart() {
160 if [ ! -f /var/lock/subsys/pound ]; then
161 msg_not_running "Pound"
162 RETVAL=$1
163 return
164 fi
165
166 stop
167 start
168}
169
170pound_status() {
171 local stat=1 pidfile instance
172
173 nls "Configured Pound instances:"
174 echo " $POUND_INSTANCES"
175 nls "Currently active Pound instances:"
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
185}
186
187if [ "$1" != status -a "$2" ]; then
188 POUND_INSTANCES="$2"
189fi
190
191RETVAL=0
192# See how we were called.
193case "$1" in
194 start)
195 start
196 ;;
197 stop)
198 stop
199 ;;
200 restart)
201 restart
202 ;;
203 try-restart)
204 condrestart 0
205 ;;
206 force-reload)
207 condrestart 7
208 ;;
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 ;;
224 status)
225 pound_status
226 ;;
227 *)
228 msg_usage "$0 {start|stop|restart|try-restart|force-reload|flush-logs|status} [INSTANCE NAMES]"
229 exit 3
230esac
231
232exit $RETVAL
This page took 0.02976 seconds and 4 git commands to generate.