[Pkg-voip-commits] [asterisk] 02/02: Make init script more adaptable for multiple instances

Daniel Pocock pocock at moszumanska.debian.org
Thu Mar 27 13:01:55 UTC 2014


This is an automated email from the git hooks/post-receive script.

pocock pushed a commit to branch master
in repository asterisk.

commit 157ff24279baf1e9775ea58d1409fcb8f00bda2a
Author: Daniel Pocock <daniel at pocock.pro>
Date:   Thu Mar 27 14:01:48 2014 +0100

    Make init script more adaptable for multiple instances
---
 debian/asterisk.init | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/debian/asterisk.init b/debian/asterisk.init
index 715b4e9..f34bb00 100644
--- a/debian/asterisk.init
+++ b/debian/asterisk.init
@@ -24,13 +24,18 @@
 
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 NAME=asterisk
+INSTANCE=$NAME
 USER=$NAME
 GROUP=$USER
 DAEMON=/usr/sbin/$NAME
 CANARY=/usr/sbin/astcanary
 DESC="Asterisk PBX"
-PIDFILE="/var/run/asterisk/asterisk.pid"
-ASTSAFE_PIDFILE="/var/run/asterisk/asterisk_safe.pid"
+ETCDIR=/etc/$INSTANCE
+LOGDIR=/var/log/$INSTANCE
+RUNDIR="/var/run/$INSTANCE
+PIDFILE="${RUNDIR}/asterisk.pid"
+ASTSAFE_PIDFILE="${RUNDIR}/asterisk_safe.pid"
+ASTCTL="${RUNDIR}/${NAME}.ctl"
 UMASK=007 # by default
 #MAXFILES=1024 # (the system default)
 
@@ -45,13 +50,21 @@ AST_DUMPCORE="no"
 AST_DUMPCORE_DIR="/var/spool/asterisk" # only used if AST_DUMPCORE != no
 # core_pattern. See: http://lxr.linux.no/source/Documentation/sysctl/kernel.txt
 #CORE_PATTERN=
-if [ -r /etc/default/$NAME ]; then . /etc/default/$NAME; fi
+if [ -r /etc/default/$INSTANCE ]; then . /etc/default/$INSTANCE ; fi
 
 if [ "$RUNASTERISK" != "yes" ];then
-	echo "Asterisk not yet configured. Edit /etc/default/asterisk first."
+	echo "Asterisk not yet configured. Edit /etc/default/$INSTANCE first."
 	exit 0
 fi
 
+if [ ! -z "$ETCDIR" ]
+then
+   PARAMS="$PARAMS -C $ETCDIR"
+fi
+if [ ! -z "$ASTCTL" ]
+then
+   PARAMS="$PARAMS -s $ASTCTL"
+fi
 if [ "$AST_REALTIME" != "no" ]
 then
   PARAMS="$PARAMS -p"
@@ -96,7 +109,7 @@ fi
 
 test -x $DAEMON || exit 0
 
-for dir in /var/run/asterisk /var/log/asterisk /var/log/asterisk/cdr-csv /var/log/asterisk/cdr-custom; do
+for dir in ${RUNDIR} ${LOGDIR} ${LOGDIR}/cdr-csv ${LOGDIR}/cdr-custom; do
 	[ -d $dir ] || install -d -o $USER -g $GROUP $dir
 	[ -x /sbin/restorecon ] && /sbin/restorecon $dir
 done
@@ -115,6 +128,9 @@ then
 fi
 
 status() {
+	# it is not clear whether it is better to use $NAME or $INSTANCE here,
+	# status_of_proc will always try to use the PID file if it really exists
+	# fortunately
 	status_of_proc -p "$PIDFILE" "$NAME" "$DESC" && return 0 || return $?
 }
 
@@ -124,7 +140,7 @@ asterisk_rx() {
 	# if $HOME is set, asterisk -rx writes a .asterisk_history there
 	(
 		unset HOME
-		$DAEMON -rx "$1"
+		$DAEMON -r -s "${ASTCTL}" -x "$1"
 	)
 }
 
@@ -164,10 +180,10 @@ case "$1" in
 	fi
 		
 	
-	echo "$NAME."
+	echo "$INSTANCE."
 	;;
   stop)
-	echo -n "Stopping $DESC: $NAME"
+	echo -n "Stopping $DESC: $INSTANCE"
 	# Try gracefully.
 	# this may hang in some cases. Specifically, when the asterisk
 	# processes is stopped. No bother to worry about cleanup: 
@@ -207,7 +223,7 @@ case "$1" in
 	exit $?
 	;;
   *)
-	N=/etc/init.d/$NAME
+	N=/etc/init.d/$INSTANCE
 	echo "Usage: $N {start|stop|restart|reload|status|debug|logger-reload|extensions-reload|restart-convenient|force-reload}" >&2
 	exit 1
 	;;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/asterisk.git



More information about the Pkg-voip-commits mailing list