[Pkg-voip-commits] r1125 - asterisk/trunk/debian
Tzafrir Cohen
tzafrir-guest at costa.debian.org
Tue Jan 3 20:52:11 UTC 2006
Author: tzafrir-guest
Date: 2006-01-03 20:52:11 +0000 (Tue, 03 Jan 2006)
New Revision: 1125
Modified:
asterisk/trunk/debian/asterisk.init
asterisk/trunk/debian/changelog
Log:
updates to the init.d script:
* runs asterisk with correct group (except when safe_asterisk is used)
* better handling of some cases
Modified: asterisk/trunk/debian/asterisk.init
===================================================================
--- asterisk/trunk/debian/asterisk.init 2006-01-03 00:55:06 UTC (rev 1124)
+++ asterisk/trunk/debian/asterisk.init 2006-01-03 20:52:11 UTC (rev 1125)
@@ -19,6 +19,8 @@
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=asterisk
USER=$NAME
+GROUP=$USER
+DAEMON=/usr/sbin/$NAME
DESC="Asterisk PBX"
PIDFILE="/var/run/asterisk/asterisk.pid"
@@ -26,8 +28,7 @@
PARAMS=""
AST_REALTIME="yes"
RUNASTERISK="no"
-MODULEINIT=""
-if [ -r /etc/default/asterisk ]; then . /etc/default/asterisk; fi
+if [ -r /etc/default/$NAME ]; then . /etc/default/$NAME; fi
if [ "$RUNASTERISK" != "yes" ];then
echo "Asterisk not yet configured. Edit /etc/default/asterisk first."
@@ -50,21 +51,62 @@
exit 1
fi
PARAMS="$PARAMS -U $USER"
-if [ "x$RUNASTSAFE" = "xyes" ];then
- DAEMON=/usr/sbin/safe_asterisk
- REALDAEMON=/usr/sbin/asterisk
+
+if [ "x$AST_DEBUG_PARAMS" = x ]
+then
+ AST_DEBUG_PARAMS=-cvvvvvddddd
+fi
+if [ "$RUNASTSAFE" = "yes" ];then
+ # The value of WRAPPER_DAEMON in can be set in /etc/default/asterisk
+ WRAPPER_DAEMON=${WRAPPER_DAEMON:-/usr/sbin/safe_asterisk}
+ REALDAEMON="$WRAPPER_DAEMON"
else
- DAEMON=/usr/sbin/asterisk
+ REALDAEMON="$DAEMON"
fi
test -x $DAEMON || exit 0
set -e
+status() {
+ plist=`ps auxw | grep "$DAEMON" | grep -v grep | awk '{print $2}' | tr '\012' ' '`
+ if [ "$plist" = "" ]; then
+ echo "$DESC is stopped"
+ return 1
+ else
+ echo "$DESC is running: $plist"
+ return 0
+ fi
+}
+
case "$1" in
+ debug)
+ # we add too many special parameters that I don't want to skip
+ # accidentally. I'm afraid that skipping -U once may cause
+ # confusing results. I also want to maintain the user's choice
+ # of -p
+ echo "Debugging $DESC: "
+ $DAEMON $PARAMS $AST_DEBUG_PARAMS
+ exit 0
+ ;;
start)
+ if status > /dev/null; then
+ echo "$DESC is already running. Use restart."
+ exit 1
+ fi
echo -n "Starting $DESC: "
- start-stop-daemon --start --pidfile "$PIDFILE" --exec $DAEMON -- $PARAMS
+ if [ "$RUNASTSAFE" != "yes" ];then
+ # TODO: what if we cought the wrapper just as its asterisk
+ # was killed? status should check for the wrapper if we're in
+ # "safe mode"
+ if status > /dev/null; then
+ echo "$DESC is already running. Use restart."
+ exit 1
+ fi
+ fi
+ echo -n "Starting $DESC: "
+ start-stop-daemon --start --group $GROUP --pidfile "$PIDFILE" \
+ --exec $REALDAEMON -- $PARAMS
echo "$NAME."
;;
stop)
@@ -73,18 +115,21 @@
# hopefully this will work. Untested
$REALDAEMON -rx 'stop now' > /dev/null || true
else
- # Try gracefully
- $DAEMON -rx 'stop now' > /dev/null 2>&1 || true
+ # Try gracefully.
+ # this may hang in some cases. Specifically, when the asterisk
+ # processes is stopped. No bother to worry about cleanup:
+ # it will either fail or die when asterisk dies.
+ ( $DAEMON -rx 'stop now' > /dev/null 2>&1 & ) &
fi
echo -n "$NAME"
- # giving a small grace time to shut down cleanly.
- sleep 2
+ ## giving a small grace time to shut down cleanly.
+ #sleep 2 # you can add timeouts in the comma
if [ "$RUNASTSAFE" = "yes" ];then
- start-stop-daemon --quiet --oknodo --stop --exec $DAEMON
+ start-stop-daemon --quiet --oknodo --stop --exec $WRAPPER_DAEMON
fi
# just making sure it's really, really dead.
# KILL is necessary just in case there's an asterisk -r in the background
- start-stop-daemon --stop --quiet --oknodo --retry=0/2/TERM/2/KILL/5 --exec $DAEMON
+ start-stop-daemon --stop --quiet --oknodo --retry=0/2/TERM/2/KILL/5 --exec $REALDAEMON
echo "."
;;
reload)
@@ -102,10 +147,14 @@
$0 stop
$0 start
;;
+ status)
+ status
+ exit $?
+ ;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart|reload|logger-reload|extensions-reload|force-reload}" >&2
- echo "Usage: $N {start|stop|restart|force-reload}" >&2
+ echo "Usage: $N {start|stop|status|debug|restart|force-reload}" >&2
exit 1
;;
esac
Modified: asterisk/trunk/debian/changelog
===================================================================
--- asterisk/trunk/debian/changelog 2006-01-03 00:55:06 UTC (rev 1124)
+++ asterisk/trunk/debian/changelog 2006-01-03 20:52:11 UTC (rev 1125)
@@ -1,6 +1,7 @@
asterisk (1:1.2.1.dfsg-4) UNRELEASED; urgency=low
* Fix PID display (Closes: #338646)
+ * changes to the init.d script (Tzafrir)
-- Kilian Krause <kilian at debian.org> Mon, 2 Jan 2006 11:04:54 +0000
More information about the Pkg-voip-commits
mailing list