mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-11-03 20:38:59 +00:00 
			
		
		
		
	`rc.archlinux.asterisk`, which explicitly requests bash in its
shebang, uses the following command syntax:
  ${DAEMON} -rx "core stop now" > /dev/null 2&>1
The intent of which is to execute:
  ${DAEMON} -rx "core stop now"
While sending both stdout and stderr to `/dev/null`. Unfortunately,
because the `&` is in the wrong place, bash is interpreting the `2` as
just an additional argument to the `$DAEMON` command and not as a file
descriptor and proceeds to use the bashism `&>` to send stderr and
stdout to a file named `1`.
So we clean it up and just use bash's shortcut syntax.
Issue raised and a fix suggested (but not used) by peutch on GitHub¹.
ASTERISK-30449 #close
1. https://github.com/asterisk/asterisk/pull/31
Change-Id: Ie279bf4efb4d95cbf507313483d316e977303d19
		
	
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/bash
 | 
						|
#
 | 
						|
# Start/stop/restart Asterisk PBX
 | 
						|
#
 | 
						|
# Version: 0.1 by Sherif Nagy AKA DarKnesS_WolF <sherif.nagy@gmail.com> BASED ON THE SLACKWARE INIT SCRIPT
 | 
						|
#
 | 
						|
# 10.10.2008 - Initial Version
 | 
						|
#
 | 
						|
 | 
						|
### BEGIN INIT INFO
 | 
						|
# Provides:		asterisk
 | 
						|
# 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
 | 
						|
# Default-Start:	2 3 4 5
 | 
						|
# Default-Stop:		0 1 6
 | 
						|
# Short-Description:	Asterisk PBX
 | 
						|
# Description:		the Asterisk Open Source PBX
 | 
						|
### END INIT INFO
 | 
						|
 | 
						|
. /etc/rc.conf
 | 
						|
. /etc/rc.d/functions
 | 
						|
DAEMON=__ASTERISK_SBIN_DIR__/asterisk
 | 
						|
ASTVARRUNDIR=__ASTERISK_VARRUN_DIR__
 | 
						|
 | 
						|
case "$1" in
 | 
						|
  start)
 | 
						|
    stat_busy "Starting Asterisk..."
 | 
						|
	if [ ! -d $ASTVARRUNDIR ]; then
 | 
						|
		mkdir -p $ASTVARRUNDIR
 | 
						|
	fi
 | 
						|
    if [ -x $DAEMON ]; then
 | 
						|
      # Check if Asterisk is already running.  If it is, then bug out, because
 | 
						|
      # starting safe_asterisk when Asterisk is running is very bad.
 | 
						|
      VERSION=`${DAEMON} -rx 'core show version' 2>/dev/null`
 | 
						|
      if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
 | 
						|
         echo "Asterisk is already running.  $0 will exit now."
 | 
						|
         exit 1
 | 
						|
      fi
 | 
						|
	  ${DAEMON}
 | 
						|
      stat_done
 | 
						|
    fi
 | 
						|
    ;;
 | 
						|
  stop)
 | 
						|
    if [ -r ${ASTVARRUNDIR}/asterisk.pid ]; then
 | 
						|
      stat_busy "Stopping Asterisk..."
 | 
						|
      ${DAEMON} -rx "core stop now" &>/dev/null
 | 
						|
      if [ $? -gt 0 ]; then
 | 
						|
        stat_fail
 | 
						|
      else
 | 
						|
        stat_done
 | 
						|
      fi
 | 
						|
    fi
 | 
						|
    ;;
 | 
						|
  restart)
 | 
						|
    $0 stop
 | 
						|
    sleep 2
 | 
						|
    $0 start
 | 
						|
    ;;
 | 
						|
  *)
 | 
						|
    echo "usage $0 start|stop|restart" ;;
 | 
						|
esac
 | 
						|
exit 0
 |