]>
Commit | Line | Data |
---|---|---|
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. | |
16 | POUND_INSTANCES="pound" | |
17 | ||
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 | |
23 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
24 | msg_network_down pound | |
25 | exit 1 | |
26 | fi | |
27 | else | |
28 | exit 0 | |
29 | fi | |
30 | ||
31 | # check if the $1 instance is up | |
32 | is_up() { | |
33 | local instance="$1" | |
34 | local pidfile=/var/run/pound/$instance.pid | |
35 | [ -f $pidfile ] || return 1 | |
36 | local pid=$(cat $pidfile) | |
37 | kill -0 $pid 2>/dev/null | |
38 | return $? | |
39 | } | |
40 | ||
41 | start() { | |
42 | local ret started=0 | |
43 | # Check if the service is already running? | |
44 | if [ ! -f /var/lock/subsys/pound -o "$single" = 1 ]; then | |
45 | for instance in $POUND_INSTANCES; do | |
46 | is_up $instance && continue | |
47 | msg_starting "Pound ($instance)" | |
48 | PIDFILE=/var/run/pound/$instance.pid | |
49 | start-stop-daemon --start \ | |
50 | --exec /usr/sbin/pound \ | |
51 | --pidfile $PIDFILE -- -v -f /etc/pound/$instance.cfg -p $PIDFILE | |
52 | ret=$? | |
53 | if [ $ret -eq 0 ]; then | |
54 | ok | |
55 | RETVAL=$ret | |
56 | started=1 | |
57 | else | |
58 | failed | |
59 | fi | |
60 | done | |
61 | [ $started = 1 ] && touch /var/lock/subsys/pound | |
62 | ||
63 | if [ -z "$ret" -a "$single" = 1 ]; then | |
64 | msg_already_running "Pound ($instance)" | |
65 | fi | |
66 | else | |
67 | msg_already_running "Pound" | |
68 | fi | |
69 | } | |
70 | ||
71 | stop() { | |
72 | local ret | |
73 | # Stop daemons. | |
74 | if [ -f /var/lock/subsys/pound ]; then | |
75 | for instance in $POUND_INSTANCES; do | |
76 | is_up $instance || continue | |
77 | msg_stopping "Pound ($instance)" | |
78 | killproc --pidfile pound/$instance.pid pound | |
79 | ret=$? | |
80 | done | |
81 | [ "$single" != 1 ] && rm -f /var/lock/subsys/pound > /dev/null 2>&1 | |
82 | if [ -z "$ret" -a "$single" = 1 ]; then | |
83 | msg_not_running "Pound ($instance)" | |
84 | fi | |
85 | else | |
86 | msg_not_running "Pound" | |
87 | fi | |
88 | } | |
89 | ||
90 | restart() { | |
91 | if [ "$single" != 1 ]; then | |
92 | # make up list of configured and up instances | |
93 | local list | |
94 | for instance in $POUND_INSTANCES; do | |
95 | is_up $instance || continue | |
96 | list="$list $instance" | |
97 | done | |
98 | POUND_INSTANCES=$list | |
99 | fi | |
100 | ||
101 | stop | |
102 | start | |
103 | } | |
104 | ||
105 | if [ "$1" != status -a "$2" ]; then | |
106 | POUND_INSTANCES="$2" | |
107 | single=1 | |
108 | fi | |
109 | ||
110 | RETVAL=0 | |
111 | # See how we were called. | |
112 | case "$1" in | |
113 | start) | |
114 | start | |
115 | ;; | |
116 | stop) | |
117 | stop | |
118 | ;; | |
119 | status) | |
120 | nls "Configured Pound instances:" | |
121 | echo " $POUND_INSTANCES" | |
122 | nls "Currently active Pound instances:" | |
123 | stat=1 | |
124 | for pidfile in /var/run/pound/*.pid; do | |
125 | [ -f "$pidfile" ] || continue | |
126 | instance=${pidfile#/var/run/pound/} | |
127 | instance=${instance%.pid} | |
128 | is_up $instance && echo -n " $instance($(cat $pidfile))" | |
129 | stat=0 | |
130 | done | |
131 | echo "" | |
132 | exit $stat | |
133 | ;; | |
134 | restart|force-reload) | |
135 | restart | |
136 | ;; | |
137 | *) | |
138 | msg_usage "$0 {start|stop|restart|force-reload|status} [INSTANCE NAMES]" | |
139 | exit 3 | |
140 | esac | |
141 | ||
142 | exit $RETVAL |