When r376428 was commited to re-order start up sequences to be more tolerant of forking with thread primitives, a few items were changed that caused changes in behavior on some distros. This includes: * Not displaying the splash screen on a remote console. * Displaying an error message on stderr when a remote console cannot connect to a running instance of Asterisk. In the first case, the splash screen was re-added (thanks to Michael L. Young). In the second case, the various init.d scripts were modified to pipe stderr to /dev/null, as the error message is useful - if you execute a remote console or a remote console command execution and it fail, it should tell you. Note that the error message was always present, it just failed to be printed prior to r376428. Much thanks to the folks who quickly reported this problem, provided solutions, and promptly tested the various init.d scripts on a variety of distros. (closes issue ASTERISK-20945) Reported by: Warren Selby Tested by: Michael L. Young, Jamuel Starkey, kaldemar, Danny Nicholas, mjordan patches: asterisk-20945-remote-intro-msg.diff uploaded by elguero (license 5026) ASTERISK-20945-1.8-mjordan.diff uploaded by mjordan (license 6283) ........ Merged revisions 379760 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 379777 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 379790 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@379791 65c4cc65-6c06-0410-ace0-fbb531ad65f3
208 lines
4.7 KiB
Bash
Executable file
208 lines
4.7 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# asterisk: Starts the asterisk service
|
|
#
|
|
# Version: @(#) /etc/rc.d/init.d/asterisk 1.0
|
|
#
|
|
# chkconfig: 2345 95 10
|
|
# description: Starts the asterisk service
|
|
#
|
|
# processname: asterisk
|
|
#
|
|
|
|
### 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
|
|
|
|
# $Id$
|
|
|
|
TTY=9 # TTY (if you want one) for Asterisk to run on
|
|
CONSOLE=yes # Whether or not you want a console
|
|
NOTIFY=root # Who to notify about crashes
|
|
DUMPDROP=/tmp
|
|
HOSTNAME=`hostname`
|
|
ASTSBINDIR=/usr/sbin
|
|
|
|
if [ 0`readlink $0` = "0" ]; then
|
|
CONFIGFILE=/etc/sysconfig/`basename $0`
|
|
else
|
|
CONFIG0=`readlink $0`
|
|
CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
|
|
fi
|
|
|
|
# Setup environment
|
|
cd /usr/src
|
|
if [ -f /usr/lib/asterisk/modules/chan_h323.so -a `grep -c ^noload=chan_h323.so /etc/asterisk/modules.conf` -eq 0 ]; then
|
|
OPENH323DIR=/usr/src/h323/openh323
|
|
PWLIBDIR=/usr/src/h323/pwlib
|
|
else
|
|
OPENH323DIR=/usr/src/oh323/openh323
|
|
PWLIBDIR=/usr/src/oh323/pwlib
|
|
fi
|
|
|
|
# Put overrides in /etc/sysconfig/asterisk
|
|
[ -r $CONFIGFILE ] && . $CONFIGFILE
|
|
|
|
LD_LIBRARY_PATH=$OPENH323DIR/lib:$PWLIBDIR/lib
|
|
export OPENH323DIR PWLIBDIR LD_LIBRARY_PATH
|
|
|
|
# Source function library.
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
#
|
|
# Don't fork when running "safely"
|
|
#
|
|
ASTARGS="-p"
|
|
if [ "$TTY" != "" ]; then
|
|
if [ -c /dev/tty${TTY} ]; then
|
|
TTY=tty${TTY}
|
|
elif [ -c /dev/vc/${TTY} ]; then
|
|
TTY=vc/${TTY}
|
|
else
|
|
echo "Cannot find your TTY (${TTY})" >&2
|
|
exit 1
|
|
fi
|
|
ASTARGS="${ASTARGS} -vvv"
|
|
if [ "$CONSOLE" != "no" ]; then
|
|
ASTARGS="${ASTARGS} -c"
|
|
fi
|
|
fi
|
|
if [ ! -w ${DUMPDROP} ]; then
|
|
echo "Cannot write to ${DUMPDROP}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
#
|
|
# Let Asterisk dump core
|
|
#
|
|
ulimit -c unlimited
|
|
|
|
#launch_asterisk()
|
|
#{
|
|
#}
|
|
|
|
SIGMSG=("None", "Hangup" "Interrupt" "Quit" "Illegal instruction" "Trace trap" "IOT Trap" "Bus Error" "Floating-point exception" "Killed" "User-defined signal 1" "Segmentation violation" "User-defined signal 2" "Broken pipe" "Alarm clock" "Termination" "Stack fault")
|
|
|
|
run_asterisk()
|
|
{
|
|
while :; do
|
|
|
|
if [ "$TTY" != "" ]; then
|
|
cd /tmp
|
|
stty sane < /dev/${TTY}
|
|
asterisk ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
|
|
else
|
|
cd /tmp
|
|
asterisk ${ASTARGS}
|
|
fi
|
|
EXITSTATUS=$?
|
|
echo "Asterisk ended with exit status $EXITSTATUS"
|
|
if [ "$EXITSTATUS" = "0" ]; then
|
|
# Properly shutdown....
|
|
echo "Asterisk shutdown normally."
|
|
exit 0
|
|
elif [ $EXITSTATUS -gt 128 ]; then
|
|
EXITSIGNAL=$(($EXITSTATUS - 128))
|
|
EXITMSG=${SIGMSG[$EXITSIGNAL]}
|
|
echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG."
|
|
if [ "$NOTIFY" != "" ]; then
|
|
echo "Asterisk exited on signal $EXITSIGNAL - $EXITMSG. Might want to take a peek." | \
|
|
mail -s "Asterisk Died ($HOSTNAME)" $NOTIFY
|
|
fi
|
|
if [ -f /tmp/core ]; then
|
|
mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
|
fi
|
|
else
|
|
echo "Asterisk died with code $EXITSTATUS. Aborting."
|
|
if [ -f /tmp/core ]; then
|
|
mv /tmp/core ${DUMPDROP}/core.`hostname`-`date -Iseconds` &
|
|
fi
|
|
exit 0
|
|
fi
|
|
echo "Automatically restarting Asterisk."
|
|
done
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
# Check if Asterisk is already running. If it is, then bug out, because
|
|
# starting Asterisk when Asterisk is already running is very bad.
|
|
VERSION=`${ASTSBINDIR}/asterisk -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
|
|
|
|
gprintf "Starting asterisk: "
|
|
run_asterisk >/dev/null 2>&1 &
|
|
sleep 2 # Give it time to die
|
|
succeeded=`pidof asterisk|awk '{print NF}'`
|
|
if [ $succeeded = "0" ]; then
|
|
failure
|
|
else
|
|
success
|
|
fi
|
|
echo
|
|
;;
|
|
stop)
|
|
gprintf "Stopping asterisk: "
|
|
asterisk -r -x "core stop gracefully" >/dev/null 2>&1
|
|
killall -9 mpg123 2>/dev/null
|
|
success
|
|
echo
|
|
;;
|
|
restart)
|
|
$0 stop
|
|
usleep 100000
|
|
$0 start
|
|
;;
|
|
reload)
|
|
gprintf "Reloading asterisk: "
|
|
asterisk -r -x "module reload" >/dev/null 2>&1
|
|
success
|
|
echo
|
|
;;
|
|
stopnow)
|
|
gprintf "Stopping asterisk: "
|
|
asterisk -r -x "core stop now" >/dev/null 2>&1
|
|
success
|
|
echo
|
|
;;
|
|
restartnow)
|
|
$0 stopnow
|
|
$0 start
|
|
;;
|
|
fullrestart)
|
|
$0 stop
|
|
service dahdi restart
|
|
$0 start
|
|
;;
|
|
fullrestartnow)
|
|
$0 stopnow
|
|
service dahdi restart
|
|
$0 start
|
|
;;
|
|
status)
|
|
succeeded=`pidof asterisk|awk '{print NF}'`
|
|
if [ $succeeded = "0" ]; then
|
|
echo "Asterisk is not running"
|
|
else
|
|
echo "Asterisk is currently running with $succeeded threads"
|
|
fi
|
|
;;
|
|
*)
|
|
gprintf "*** Usage: $0 {start|stop[now]|reload|[full]restart[now]|status}\n"
|
|
exit 1
|
|
esac
|
|
|
|
exit 0
|
|
|