]> git.pld-linux.org Git - packages/pound.git/blobdiff - pound.init
- release 3 (by relup.sh)
[packages/pound.git] / pound.init
old mode 100644 (file)
new mode 100755 (executable)
index d57f10e..09ed5f2
@@ -28,6 +28,11 @@ else
        exit 0
 fi
 
+configtest() {
+       local instance="$1"
+       pound -c -f /etc/pound/$instance.cfg > /dev/null
+}
+
 # check if the $1 instance is up
 is_up() {
        local instance="$1"
@@ -38,89 +43,136 @@ is_up() {
        return $?
 }
 
+# check if any of the instances are up
+any_up() {
+       local ret=1 instance pidfile
+
+       for pidfile in /var/run/pound/*.pid; do
+               [ -f "$pidfile" ] || continue
+               instance=${pidfile#/var/run/pound/}
+               instance=${instance%.pid}
+               is_up $instance || continue
+               ret=0
+       done
+
+       return $ret
+}
+
+# check if all of the instances are up
+all_up() {
+       local ret=1 instance pidfile
+
+       for pidfile in /var/run/pound/*.pid; do
+               [ -f "$pidfile" ] || continue
+               instance=${pidfile#/var/run/pound/}
+               instance=${instance%.pid}
+               is_up $instance && continue
+               ret=0
+       done
+
+       return $ret
+}
+
 start() {
-       local ret started=0
+       local ret started=0 found=0 instance
+
        # Check if the service is already running?
-       if [ ! -f /var/lock/subsys/pound -o "$single" = 1 ]; then
-               for instance in $POUND_INSTANCES; do
-                       is_up $instance && continue
-                       msg_starting "Pound ($instance)"
-                       PIDFILE=/var/run/pound/$instance.pid
-                       start-stop-daemon --start \
+       if all_up; then
+               msg_already_running "Pound"
+               return
+       fi
+
+       msg_starting "Pound"; started
+       for instance in $POUND_INSTANCES; do
+               show "Starting Pound instance %s" "$instance"
+               if is_up $instance; then
+                       started
+                       continue
+               fi
+
+               PIDFILE=/var/run/pound/$instance.pid
+               start-stop-daemon --start \
                        --exec /usr/sbin/pound \
                        --pidfile $PIDFILE -- -v -f /etc/pound/$instance.cfg -p $PIDFILE
-                       ret=$?
-                       if [ $ret -eq 0 ]; then
-                               ok
-                               RETVAL=$ret
-                               started=1
-                       else
-                               failed
-                       fi
-               done
-               [ $started = 1 ] && touch /var/lock/subsys/pound
+               ret=$?
 
-               if [ -z "$ret" -a "$single" = 1 ]; then
-                       msg_already_running "Pound ($instance)"
+               if [ $ret -eq 0 ]; then
+                       ok
+                       RETVAL=$ret
+                       started=1
+                       found=1
+               else
+                       fail
                fi
-       else
-               msg_already_running "Pound"
-       fi
+       done
+
+       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pound
 }
 
 stop() {
-       local ret
        # Stop daemons.
-       if [ -f /var/lock/subsys/pound ]; then
-               for instance in $POUND_INSTANCES; do
-                       is_up $instance || continue
-                       msg_stopping "Pound ($instance)"
-                       killproc --pidfile pound/$instance.pid pound
-                       ret=$?
-               done
-               [ "$single" != 1 ] && rm -f /var/lock/subsys/pound > /dev/null 2>&1
-               if [ -z "$ret" -a "$single" = 1 ]; then
-                       msg_not_running "Pound ($instance)"
-               fi
-       else
+       if ! any_up; then
                msg_not_running "Pound"
+               return
        fi
+
+       local ret instance
+       msg_stopping "Pound"; started
+       for instance in $POUND_INSTANCES; do
+               is_up $instance || continue
+               show "Stopping Pound instance %s" "$instance"; busy
+               killproc --pidfile pound/$instance.pid pound
+               ret=$?
+       done
+       rm -f /var/lock/subsys/pound > /dev/null 2>&1
+       rm -f /var/run/pound/$instance.pid > /dev/null 2>&1
 }
 
 restart() {
-       if [ "$single" != 1 ]; then
+       local instance
+
+       if any_up; then
                # make up list of configured and up instances
                local list
+               show "Checking configuration"; busy
                for instance in $POUND_INSTANCES; do
-                       is_up $instance || continue
+                       # skip ones whose config fails
+                       configtest $instance || continue
                        list="$list $instance"
                done
-               POUND_INSTANCES=$list
+
+               # nothing left or never was
+               if [ -z "$list" ]; then
+                       fail
+                       return
+               else
+                       POUND_INSTANCES=$list
+                       ok
+               fi
+
        fi
 
        stop
        start
 }
 
-if [ "$1" != status -a "$2" ]; then
-       POUND_INSTANCES="$2"
-       single=1
-fi
+condrestart() {
+       if [ ! -f /var/lock/subsys/pound ]; then
+               msg_not_running "Pound"
+               RETVAL=$1
+               return
+       fi
+
+       stop
+       start
+}
+
+pound_status() {
+       local stat=1 pidfile instance
 
-RETVAL=0
-# See how we were called.
-case "$1" in
-  start)
-       start
-       ;;
-  stop)
-       stop
-       ;;
-  status)
        nls "Configured Pound instances:"
        echo " $POUND_INSTANCES"
        nls "Currently active Pound instances:"
-       stat=1
        for pidfile in /var/run/pound/*.pid; do
                [ -f "$pidfile" ] || continue
                instance=${pidfile#/var/run/pound/}
@@ -130,12 +182,50 @@ case "$1" in
        done
        echo ""
        exit $stat
+}
+
+if [ "$1" != status -a "$2" ]; then
+       POUND_INSTANCES="$2"
+fi
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       stop
        ;;
-  restart|force-reload)
+  restart)
        restart
        ;;
+  try-restart)
+       condrestart 0
+       ;;
+  force-reload)
+       condrestart 7
+       ;;
+  flush-logs)
+       if [ -f /var/lock/subsys/pound ]; then
+               for instance in $POUND_INSTANCES; do
+                       show "Rotating Pound logs for %s instance" $instance
+                       killproc --pidfile /var/run/pound/$instance.pid pound -USR1
+                       ret=$?
+                       if [ $ret != 0 ]; then
+                               RETVAL=$ret
+                       fi
+               done
+       else
+               msg_not_running "Pound"
+               RETVAL=7
+       fi
+       ;;
+  status)
+       pound_status
+       ;;
   *)
-       msg_usage "$0 {start|stop|restart|force-reload|status} [INSTANCE NAMES]"
+       msg_usage "$0 {start|stop|restart|try-restart|force-reload|flush-logs|status} [INSTANCE NAMES]"
        exit 3
 esac
 
This page took 0.054648 seconds and 4 git commands to generate.