2004-01-11 10:17:38 +00:00
|
|
|
#!/bin/sh
|
2017-12-22 14:23:22 +00:00
|
|
|
#
|
2004-01-11 10:17:38 +00:00
|
|
|
# asterisk: Starts the asterisk service
|
2017-12-22 14:23:22 +00:00
|
|
|
#
|
2004-01-11 10:22:29 +00:00
|
|
|
# Version: @(#) /etc/rc.d/init.d/asterisk 1.0
|
2017-12-22 14:23:22 +00:00
|
|
|
#
|
2004-01-11 10:17:38 +00:00
|
|
|
# chkconfig: 2345 95 10
|
|
|
|
# description: Starts the asterisk service
|
2017-12-22 14:23:22 +00:00
|
|
|
#
|
2004-01-11 10:17:38 +00:00
|
|
|
# processname: asterisk
|
2017-12-22 14:23:22 +00:00
|
|
|
#
|
2004-01-11 10:17:38 +00:00
|
|
|
|
2010-01-11 23:53:32 +00:00
|
|
|
### 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
|
|
|
|
|
2007-06-04 17:12:35 +00:00
|
|
|
# $Id$
|
|
|
|
|
2004-01-11 10:17:38 +00:00
|
|
|
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`
|
2008-08-04 17:08:42 +00:00
|
|
|
ASTSBINDIR=/usr/sbin
|
|
|
|
|
Merged revisions 7285,7299,7310,7329 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7285 | tilghman | 2005-12-02 15:12:05 -0600 (Fri, 02 Dec 2005) | 2 lines
Turn on executable bits for startup scripts, and fix bash var interpolation for Mandrake
........
r7299 | oej | 2005-12-02 19:24:40 -0600 (Fri, 02 Dec 2005) | 2 lines
Documenting the default registerattempts setting as 0, continue hammering the server for ever and ever ;-)
........
r7310 | tilghman | 2005-12-03 13:55:05 -0600 (Sat, 03 Dec 2005) | 3 lines
Bug 5925: check for "Unknown", as that's what app_voicemail puts into the field for Unknown callerid
Also, remove useless res checks (initialized to 0; never set)
........
r7329 | kpfleming | 2005-12-04 12:03:07 -0600 (Sun, 04 Dec 2005) | 2 lines
use a more efficient way to get the revision number, that will also report if the working copy contains uncommitted modifications
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7330 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2005-12-04 18:12:52 +00:00
|
|
|
if [ 0`readlink $0` = "0" ]; then
|
|
|
|
CONFIGFILE=/etc/sysconfig/`basename $0`
|
|
|
|
else
|
|
|
|
CONFIG0=`readlink $0`
|
|
|
|
CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
|
|
|
|
fi
|
2004-01-11 10:17:38 +00:00
|
|
|
|
|
|
|
# Setup environment
|
|
|
|
cd /usr/src
|
2005-03-12 06:50:22 +00:00
|
|
|
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
|
2010-01-11 23:00:55 +00:00
|
|
|
[ -r $CONFIGFILE ] && . $CONFIGFILE
|
2005-03-12 06:50:22 +00:00
|
|
|
|
2004-01-11 10:17:38 +00:00
|
|
|
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
|
2017-12-22 14:23:22 +00:00
|
|
|
if [ ! -w ${DUMPDROP} ]; then
|
2004-01-11 10:17:38 +00:00
|
|
|
echo "Cannot write to ${DUMPDROP}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Let Asterisk dump core
|
|
|
|
#
|
|
|
|
ulimit -c unlimited
|
|
|
|
|
|
|
|
#launch_asterisk()
|
|
|
|
#{
|
|
|
|
#}
|
|
|
|
|
Merged revisions 7285,7299,7310,7329 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7285 | tilghman | 2005-12-02 15:12:05 -0600 (Fri, 02 Dec 2005) | 2 lines
Turn on executable bits for startup scripts, and fix bash var interpolation for Mandrake
........
r7299 | oej | 2005-12-02 19:24:40 -0600 (Fri, 02 Dec 2005) | 2 lines
Documenting the default registerattempts setting as 0, continue hammering the server for ever and ever ;-)
........
r7310 | tilghman | 2005-12-03 13:55:05 -0600 (Sat, 03 Dec 2005) | 3 lines
Bug 5925: check for "Unknown", as that's what app_voicemail puts into the field for Unknown callerid
Also, remove useless res checks (initialized to 0; never set)
........
r7329 | kpfleming | 2005-12-04 12:03:07 -0600 (Sun, 04 Dec 2005) | 2 lines
use a more efficient way to get the revision number, that will also report if the working copy contains uncommitted modifications
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7330 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2005-12-04 18:12:52 +00:00
|
|
|
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")
|
2005-03-12 06:50:22 +00:00
|
|
|
|
2004-01-11 10:17:38 +00:00
|
|
|
run_asterisk()
|
|
|
|
{
|
2017-12-22 14:23:22 +00:00
|
|
|
while :; do
|
2004-01-11 10:17:38 +00:00
|
|
|
|
|
|
|
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
|
2005-03-12 06:50:22 +00:00
|
|
|
EXITSIGNAL=$(($EXITSTATUS - 128))
|
Merged revisions 7285,7299,7310,7329 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7285 | tilghman | 2005-12-02 15:12:05 -0600 (Fri, 02 Dec 2005) | 2 lines
Turn on executable bits for startup scripts, and fix bash var interpolation for Mandrake
........
r7299 | oej | 2005-12-02 19:24:40 -0600 (Fri, 02 Dec 2005) | 2 lines
Documenting the default registerattempts setting as 0, continue hammering the server for ever and ever ;-)
........
r7310 | tilghman | 2005-12-03 13:55:05 -0600 (Sat, 03 Dec 2005) | 3 lines
Bug 5925: check for "Unknown", as that's what app_voicemail puts into the field for Unknown callerid
Also, remove useless res checks (initialized to 0; never set)
........
r7329 | kpfleming | 2005-12-04 12:03:07 -0600 (Sun, 04 Dec 2005) | 2 lines
use a more efficient way to get the revision number, that will also report if the working copy contains uncommitted modifications
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7330 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2005-12-04 18:12:52 +00:00
|
|
|
EXITMSG=${SIGMSG[$EXITSIGNAL]}
|
2004-01-11 10:17:38 +00:00
|
|
|
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)
|
2008-05-05 03:25:35 +00:00
|
|
|
# Check if Asterisk is already running. If it is, then bug out, because
|
|
|
|
# starting Asterisk when Asterisk is already running is very bad.
|
Update init.d scripts to handle stderr; readd splash screen for remote consoles
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
2013-01-21 20:41:12 +00:00
|
|
|
VERSION=`${ASTSBINDIR}/asterisk -rx 'core show version' 2>/dev/null`
|
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
|
|
|
|
|
2004-01-11 10:17:38 +00:00
|
|
|
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: "
|
2008-10-18 09:02:36 +00:00
|
|
|
asterisk -r -x "core stop gracefully" >/dev/null 2>&1
|
2004-01-11 10:17:38 +00:00
|
|
|
killall -9 mpg123 2>/dev/null
|
|
|
|
success
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
$0 stop
|
|
|
|
usleep 100000
|
|
|
|
$0 start
|
|
|
|
;;
|
|
|
|
reload)
|
|
|
|
gprintf "Reloading asterisk: "
|
2008-10-18 09:02:36 +00:00
|
|
|
asterisk -r -x "module reload" >/dev/null 2>&1
|
2004-01-11 10:17:38 +00:00
|
|
|
success
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
stopnow)
|
|
|
|
gprintf "Stopping asterisk: "
|
2008-10-18 09:02:36 +00:00
|
|
|
asterisk -r -x "core stop now" >/dev/null 2>&1
|
2004-01-11 10:17:38 +00:00
|
|
|
success
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
restartnow)
|
|
|
|
$0 stopnow
|
|
|
|
$0 start
|
|
|
|
;;
|
2005-03-12 06:50:22 +00:00
|
|
|
fullrestart)
|
|
|
|
$0 stop
|
2008-06-12 17:27:55 +00:00
|
|
|
service dahdi restart
|
2005-03-12 06:50:22 +00:00
|
|
|
$0 start
|
|
|
|
;;
|
|
|
|
fullrestartnow)
|
|
|
|
$0 stopnow
|
2008-06-12 17:27:55 +00:00
|
|
|
service dahdi restart
|
2005-03-12 06:50:22 +00:00
|
|
|
$0 start
|
|
|
|
;;
|
2004-01-11 10:17:38 +00:00
|
|
|
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
|
|
|
|
;;
|
|
|
|
*)
|
2005-03-12 06:50:22 +00:00
|
|
|
gprintf "*** Usage: $0 {start|stop[now]|reload|[full]restart[now]|status}\n"
|
2004-01-11 10:17:38 +00:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|