| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | #! /bin/sh | 
					
						
							| 
									
										
										
										
											2007-06-04 17:12:35 +00:00
										 |  |  | # $Id$ | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  | # Mon Jun 04 2007 Iñaki Baz Castillo <ibc@in.ilimit.es> | 
					
						
							|  |  |  | # - 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". | 
					
						
							| 
									
										
										
										
											2009-07-30 16:07:05 +00:00
										 |  |  | # - Added "--oknodo" to "start-stop-daemon" for compatibility with LSB: | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  | #   http://www.linux-foundation.org/spec/refspecs/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2005-11-30 21:22:38 +00:00
										 |  |  | # Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net> | 
					
						
							|  |  |  | # - Reversed behavior of LD_ASSUME_KERNEL=2.4.1 | 
					
						
							|  |  |  | # - Added detailed failure messages | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | # Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net> | 
					
						
							|  |  |  | # - Added test for safe_asterisk | 
					
						
							|  |  |  | # - Changed "stop gracefully" to "stop now" | 
					
						
							|  |  |  | # - Added support for -U and -G command line options | 
					
						
							|  |  |  | # - Modified "reload" to call asterisk -rx 'reload'  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | 
					
						
							|  |  |  | NAME=asterisk | 
					
						
							|  |  |  | DESC="Asterisk PBX" | 
					
						
							|  |  |  | # Full path to asterisk binary | 
					
						
							| 
									
										
										
										
											2009-02-21 13:13:35 +00:00
										 |  |  | DAEMON=__ASTERISK_SBIN_DIR__/asterisk | 
					
						
							|  |  |  | ASTVARRUNDIR=__ASTERISK_VARRUN_DIR__ | 
					
						
							|  |  |  | ASTETCDIR=__ASTERISK_ETC_DIR__ | 
					
						
							| 
									
										
										
										
											2008-05-08 15:32:48 +00:00
										 |  |  | TRUE=/bin/true | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-07 17:02:38 +00:00
										 |  |  | ### BEGIN INIT INFO | 
					
						
							|  |  |  | # Provides:		asterisk | 
					
						
							| 
									
										
										
										
											2010-01-11 23:53:32 +00:00
										 |  |  | # Required-Start:    $network $syslog $named $local_fs $remote_fs | 
					
						
							|  |  |  | # Required-Stop:     $network $syslog $named $local_fs $remote_fs | 
					
						
							|  |  |  | # Should-Start:      dahdi misdn lcr wanrouter mysql postgresql | 
					
						
							|  |  |  | # Should-Stop:       dahdi misdn lcr wanrouter mysql postgresql | 
					
						
							| 
									
										
										
										
											2009-11-07 17:02:38 +00:00
										 |  |  | # Default-Start:	2 3 4 5 | 
					
						
							|  |  |  | # Default-Stop:		0 1 6 | 
					
						
							|  |  |  | # Short-Description:	Asterisk PBX | 
					
						
							|  |  |  | # Description:		the Asterisk Open Source PBX | 
					
						
							|  |  |  | ### END INIT INFO | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  | set -e | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-30 21:22:38 +00:00
										 |  |  | if ! [ -x $DAEMON ] ; then | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  |         echo "ERROR: $DAEMON not found" | 
					
						
							| 
									
										
										
										
											2005-11-30 21:22:38 +00:00
										 |  |  |         exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-21 13:13:35 +00:00
										 |  |  | if ! [ -d $ASTETCDIR ] ; then | 
					
						
							|  |  |  |         echo "ERROR: $ASTETCDIR directory not found" | 
					
						
							| 
									
										
										
										
											2005-11-30 21:22:38 +00:00
										 |  |  |         exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-09 17:32:52 +00:00
										 |  |  | # Use the LSB standard functions for services management | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  | . /lib/lsb/init-functions | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 23:00:55 +00:00
										 |  |  | # Allow configuration overrides in /etc/default/asterisk | 
					
						
							| 
									
										
										
										
											2010-09-16 22:04:38 +00:00
										 |  |  | CONFIG0=`readlink $0 || :` # readlink returns 1 when something isn't a symlink | 
					
						
							| 
									
										
										
										
											2010-01-11 23:00:55 +00:00
										 |  |  | if [ "$CONFIG0" = "" ]; then | 
					
						
							|  |  |  | 	CONFIGFILE=/etc/default/`basename $0` | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  | 	CONFIGFILE=/etc/default/`basename $CONFIG0` | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | [ -r $CONFIGFILE ] && . $CONFIGFILE | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | case "$1" in | 
					
						
							|  |  |  |   start) | 
					
						
							| 
									
										
										
										
											2008-05-05 03:25:35 +00:00
										 |  |  | 	# Check if Asterisk is already running.  If it is, then bug out, because | 
					
						
							|  |  |  | 	# starting up Asterisk when Asterisk is already running is very bad. | 
					
						
							| 
									
										
										
										
											2011-02-10 22:39:30 +00:00
										 |  |  | 	VERSION=`${DAEMON} -rx 'core show version' || ${TRUE}` | 
					
						
							| 
									
										
										
										
											2008-05-30 16:47:24 +00:00
										 |  |  | 	if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then | 
					
						
							| 
									
										
										
										
											2008-05-05 03:25:35 +00:00
										 |  |  | 		echo "Asterisk is already running.  $0 will exit now." | 
					
						
							|  |  |  | 		exit 1 | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  | 	log_begin_msg "Starting $DESC: $NAME" | 
					
						
							| 
									
										
										
										
											2009-02-21 13:13:35 +00:00
										 |  |  | 	if [ ! -d $ASTVARRUNDIR ]; then | 
					
						
							|  |  |  | 		mkdir -p $ASTVARRUNDIR | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	if [ $AST_USER ] ; then | 
					
						
							|  |  |  | 		ASTARGS="-U $AST_USER" | 
					
						
							|  |  |  | 		chown $AST_USER $ASTVARRUNDIR | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	if [ $AST_GROUP ] ; then | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -G $AST_GROUP" | 
					
						
							| 
									
										
										
										
											2009-06-12 02:20:19 +00:00
										 |  |  | 		chgrp $AST_GROUP $ASTVARRUNDIR | 
					
						
							| 
									
										
										
										
											2009-02-21 13:13:35 +00:00
										 |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2010-01-11 23:00:55 +00:00
										 |  |  | 	if [ $ALTCONF ]; then | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -C \"$ALTCONF\"" | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	if [ "x$COREDUMP" = "xyes" ]; then | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -g" | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	if [ "0$MAXLOAD" -gt "0" ]; then | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -L $MAXLOAD" | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	if [ "0$MAXCALLS" -gt "0" ]; then | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -M $MAXCALLS" | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	if [ "0$VERBOSITY" -gt "0" ]; then | 
					
						
							|  |  |  | 		for i in `seq 1 $VERBOSITY`; do | 
					
						
							|  |  |  | 			ASTARGS="$ASTARGS -v" | 
					
						
							|  |  |  | 		done | 
					
						
							| 
									
										
										
										
											2010-12-17 21:18:18 +00:00
										 |  |  | 		# -v implies -f, so we override that implicit specification here | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -F" | 
					
						
							| 
									
										
										
										
											2010-01-11 23:00:55 +00:00
										 |  |  | 	fi | 
					
						
							|  |  |  | 	if [ "x$INTERNALTIMING" = "xyes" ]; then | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -I" | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -t" | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2010-06-09 17:32:52 +00:00
										 |  |  | 	if test "x$COLOR" = "xno" ; then | 
					
						
							|  |  |  | 		ASTARGS="$ASTARGS -n" | 
					
						
							| 
									
										
										
										
											2009-12-27 18:20:53 +00:00
										 |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2010-06-09 17:32:52 +00:00
										 |  |  | 	# "start-stop-daemon --oknodo" returns 0 even if Asterisk was already running (as LSB expects): | 
					
						
							|  |  |  | 	start-stop-daemon --start --oknodo --exec $DAEMON -- $ASTARGS | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  | 	log_end_msg $? | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | 	;; | 
					
						
							|  |  |  |   stop) | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  | 	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 $? | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | 	;; | 
					
						
							|  |  |  |   reload) | 
					
						
							|  |  |  | 	echo "Reloading $DESC configuration files." | 
					
						
							| 
									
										
										
										
											2008-10-18 09:02:36 +00:00
										 |  |  | 	$DAEMON -rx 'module reload' > /dev/null 2> /dev/null | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | 	;; | 
					
						
							|  |  |  |   restart|force-reload) | 
					
						
							| 
									
										
										
										
											2008-02-29 01:15:20 +00:00
										 |  |  | 	$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). | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | 	;; | 
					
						
							| 
									
										
										
										
											2011-05-17 12:39:37 +00:00
										 |  |  |   status) | 
					
						
							|  |  |  |        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? | 
					
						
							|  |  |  |        ;; | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  |   *) | 
					
						
							|  |  |  | 	N=/etc/init.d/$NAME | 
					
						
							| 
									
										
										
										
											2011-05-17 12:39:37 +00:00
										 |  |  | 	echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 | 
					
						
							| 
									
										
										
										
											2004-07-24 03:17:52 +00:00
										 |  |  | 	exit 1 | 
					
						
							|  |  |  | 	;; | 
					
						
							|  |  |  | esac |