]> git.pld-linux.org Git - packages/pound.git/blob - pound.init
- improved single instance startup shutdown
[packages/pound.git] / pound.init
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
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                         daemon pound -f /etc/pound/$instance.cfg -p /var/run/pound/$instance.pid
49                         ret=$?
50                         [ $RETVAL -eq 0 ] && RETVAL=$ret
51                 done
52                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pound
53
54                 if [ -z "$ret" -a "$single" = 1 ]; then
55                         msg_already_running "Pound ($instance)"
56                 fi
57         else
58                 msg_already_running "Pound"
59         fi
60 }
61
62 stop() {
63         local ret
64         # Stop daemons.
65         if [ -f /var/lock/subsys/pound ]; then
66                 for instance in $POUND_INSTANCES; do
67                         is_up $instance || continue
68                         msg_stopping "Pound ($instance)"
69                         killproc --pidfile pound/$instance.pid pound
70                         ret=$?
71                 done
72                 [ "$single" != 1 ] && rm -f /var/lock/subsys/pound > /dev/null 2>&1
73                 if [ -z "$ret" -a "$single" = 1 ]; then
74                         msg_not_running "Pound ($instance)"
75                 fi
76         else
77                 msg_not_running "Pound"
78         fi
79 }
80
81 if [ "$1" != status -a "$2" ]; then
82         POUND_INSTANCES="$2"
83         single=1
84 fi
85
86 RETVAL=0
87 # See how we were called.
88 case "$1" in
89   start)
90         start
91         ;;
92   stop)
93         stop
94         ;;
95   status)
96         nls "Configured Pound instances:"
97         echo " $POUND_INSTANCES"
98         nls "Currently active Pound instances:"
99         stat=1
100         for pidfile in /var/run/pound/*.pid; do
101                 [ -f "$pidfile" ] || continue
102                 instance=${pidfile#/var/run/pound/}
103                 instance=${instance%.pid}
104                 is_up $instance && echo -n " $instance($(cat $pidfile))"
105                 stat=0
106         done
107         echo ""
108         exit $stat
109         ;;
110   restart|force-reload)
111         stop
112         start
113         ;;
114   *)
115         msg_usage "$0 {start|stop|restart|force-reload|status} [INSTANCE NAMES]"
116         exit 3
117 esac
118
119 exit $RETVAL
This page took 0.060246 seconds and 4 git commands to generate.