--- rc.debian.asterisk 2007-10-05 11:57:20.000000000 +0200 +++ rc.debian.asterisk.new 2007-10-05 11:43:46.000000000 +0200 @@ -1,7 +1,11 @@ #! /bin/sh -# $Id: rc.debian.asterisk 67061 2007-06-04 17:11:43Z tilghman $ # -# asterisk start the asterisk PBX +# Mon Jun 04 2007 IƱaki Baz Castillo +# - Updated Version to 1.4 +# - Eliminated SAFE_ASTERISK since it doesn't work as LSB script (it could require a independent "safe_asterisk" init script). +# - Load and use the standar "/lib/lsb/init-functions". +# - Addded "--oknodo" to "start-stop-daemon" for compatibility with LSB: +# http://www.linux-foundation.org/spec/refspecs/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html # # Thu Nov 17 2005 Gregory Boehnlein # - Updated Version to 1.3 @@ -21,9 +25,6 @@ # Full path to asterisk binary DAEMON=/usr/sbin/asterisk -# Full path to safe_asterisk script -SAFE_ASTERISK=/usr/sbin/safe_asterisk - # Uncomment this ONLY if you know what you are doing. # export LD_ASSUME_KERNEL=2.4.1 @@ -35,8 +36,10 @@ #AST_USER="asterisk" #AST_GROUP="asterisk" +set -e + if ! [ -x $DAEMON ] ; then - echo "ERROR: /usr/sbin/asterisk not found" + echo "ERROR: $DAEMON not found" exit 0 fi @@ -45,35 +48,37 @@ exit 0 fi -set -e +# Use the LSB standar functions for services management +. /lib/lsb/init-functions case "$1" in start) - echo -n "Starting $DESC: " - if [ -f $SAFE_ASTERISK ] ; then - DAEMON=$SAFE_ASTERISK - fi + log_begin_msg "Starting $DESC: $NAME" if [ $AST_USER ] ; then ASTARGS="-U $AST_USER" fi if [ $AST_GROUP ] ; then - ASTARGS="`echo $ASTARGS` -G $AST_GROUP" + ASTARGS="$ASTARGS -G $AST_GROUP" fi - start-stop-daemon --start --exec $DAEMON -- $ASTARGS - echo "$NAME." + # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already running (as LSB expects): + start-stop-daemon --start --oknodo --exec $DAEMON -- $ASTARGS + log_end_msg $? ;; stop) - echo -n "Stopping $DESC: " - $DAEMON -rx 'stop now' > /dev/null 2> /dev/null && echo -n "$NAME" - echo "." - exit 0 + log_begin_msg "Stopping $DESC: $NAME" + # "start-stop-daemon --oknodo" returns 0 even if Asterisk was already stopped (as LSB expects): + start-stop-daemon --stop --oknodo --exec $DAEMON + log_end_msg $? ;; reload) echo "Reloading $DESC configuration files." $DAEMON -rx 'reload' > /dev/null 2> /dev/null ;; restart|force-reload) - $DAEMON -rx 'restart gracefully' > /dev/null 2> /dev/null && echo -n "$NAME" + $0 stop + sleep 2 # It needs some time to really be stopped. + $0 start + # "restart|force-reload" starts Asterisk and returns 0 even if Asterisk was stopped (as LSB expects). ;; *) N=/etc/init.d/$NAME @@ -81,5 +86,3 @@ exit 1 ;; esac - -exit 0