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