SOURCES: pound.init - rewritten, using ideas from openvpn.init
glen
glen at pld-linux.org
Thu Jan 8 16:40:38 CET 2009
Author: glen Date: Thu Jan 8 15:40:38 2009 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- rewritten, using ideas from openvpn.init
---- Files affected:
SOURCES:
pound.init (1.15 -> 1.16)
---- Diffs:
================================================================
Index: SOURCES/pound.init
diff -u SOURCES/pound.init:1.15 SOURCES/pound.init:1.16
--- SOURCES/pound.init:1.15 Thu Oct 2 15:49:04 2008
+++ SOURCES/pound.init Thu Jan 8 16:40:32 2009
@@ -28,6 +28,12 @@
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 @@
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 @@
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 @@
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
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/pound.init?r1=1.15&r2=1.16&f=u
More information about the pld-cvs-commit
mailing list