From e23f2808ca31bd5cc61d60f7e18cccfe7042f681 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 8 Jan 2009 15:40:32 +0000 Subject: [PATCH] - rewritten, using ideas from openvpn.init Changed files: pound.init -> 1.16 --- pound.init | 122 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 37 deletions(-) diff --git a/pound.init b/pound.init index 5ce60b0..d68745e 100644 --- a/pound.init +++ b/pound.init @@ -28,6 +28,12 @@ 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,65 +44,102 @@ 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=0 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=1 + 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 + if ! all_up; then + msg_starting "Pound"; started for instance in $POUND_INSTANCES; do - is_up $instance && continue - msg_starting "Pound ($instance)" + 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 + --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 + found=1 else fail fi done - [ $started = 1 ] && touch /var/lock/subsys/pound - if [ -z "$ret" -a "$single" = 1 ]; then - msg_already_running "Pound ($instance)" - fi + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pound else msg_already_running "Pound" fi } stop() { - local ret + local ret instance # Stop daemons. - if [ -f /var/lock/subsys/pound ]; then + if any_up; then + msg_stopping "Pound" for instance in $POUND_INSTANCES; do is_up $instance || continue - msg_stopping "Pound ($instance)" + show "Stopping Pound instance %s" "$instance"; busy 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 + rm -f /var/lock/subsys/pound > /dev/null 2>&1 else msg_not_running "Pound" fi } restart() { - if [ "$single" != 1 ]; then - # make up list of configured and up instances - local list - for instance in $POUND_INSTANCES; do - is_up $instance || continue - list="$list $instance" - done - POUND_INSTANCES=$list - fi + local instance + + # make up list of configured and up instances + local list + show "Checking configuration"; busy + for instance in $POUND_INSTANCES; do + # skip ones whose config fails + configtest $instance || continue + list="$list $instance" + done + ok + + POUND_INSTANCES=$list stop start @@ -104,19 +147,11 @@ restart() { if [ "$1" != status -a "$2" ]; then POUND_INSTANCES="$2" - single=1 fi -RETVAL=0 -# See how we were called. -case "$1" in - start) - start - ;; - stop) - stop - ;; - status) +pound_status() { + local stat pidfile instance + nls "Configured Pound instances:" echo " $POUND_INSTANCES" nls "Currently active Pound instances:" @@ -130,6 +165,19 @@ case "$1" in done echo "" exit $stat +} + +RETVAL=0 +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + pound_status ;; restart|force-reload) restart -- 2.44.0