asterisk/contrib/init.d/rc.redhat.asterisk

179 lines
4.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# $Id$
#
# asterisk Starts, Stops and Reloads Asterisk.
#
# chkconfig: 2345 90 60
# description: Asterisk PBX and telephony daemon.
# processname: asterisk
# pidfile: __ASTERISK_VARRUN_DIR__/asterisk.pid
#
# Thu Nov 17 2005 Gregory Boehnlein <damin@nacs.net>
# - Updated Version to 1.3
# - Reversed behavior of LD_ASSUME_KERNEL=2.4.1
# - Added detailed failure messages
#
# Sun Jul 18 2004 Gregory Boehnlein <damin@nacs.net>
# - Updated Version to 1.2
# - Added test for safe_asterisk
# - Verified SIGTERM issued by "killproc" ensures "stop gracefully"
# - Added support for -U and -G command line options
# - Modified "reload" to call asterisk -rx 'reload'
### 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
# Use this option to specify a different configuration directory
#AST_CONFIG=__ASTERISK_ETC_DIR__
# Installation directory
AST_SBIN=__ASTERISK_SBIN_DIR__
# Source function library.
. /etc/rc.d/init.d/functions
if ! [ -x $AST_SBIN/asterisk ] ; then
echo "ERROR: $AST_SBIN/asterisk not found"
exit 0
fi
if ! [ -d $AST_CONFIG ] ; then
echo "ERROR: $AST_CONFIG directory not found"
exit 0
fi
# Full path to asterisk binary
DAEMON=$AST_SBIN/asterisk
# Full path to safe_asterisk script
SAFE_ASTERISK=$AST_SBIN/safe_asterisk
# Allow configuration overrides in /etc/sysconfig/asterisk
CONFIG0=`readlink $0`
if [ "$CONFIG0" = "" ]; then
CONFIGFILE=/etc/sysconfig/`basename $0`
else
CONFIGFILE=/etc/sysconfig/`basename $CONFIG0`
fi
[ -r $CONFIGFILE ] && . $CONFIGFILE
RETVAL=0
start() {
# Check if Asterisk is already running. If it is, then bug out, because
# starting safe_asterisk when Asterisk is 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=`${AST_SBIN}/asterisk -rx 'core show version' 2>/dev/null`
if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
echo "Asterisk is already running."
exit 0
fi
# Start daemons.
echo -n $"Starting asterisk: "
if [ -f $SAFE_ASTERISK ] ; then
DAEMON=$SAFE_ASTERISK
fi
if [ $AST_USER ] ; then
ASTARGS="-U $AST_USER"
fi
if [ $AST_GROUP ] ; then
ASTARGS="$ASTARGS -G $AST_GROUP"
fi
if [ $AST_CONFIG ]; then
ASTARGS="$ASTARGS -C $AST_CONFIG/asterisk.conf"
elif [ $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
fi
if [ "x$INTERNALTIMING" = "xyes" ]; then
ASTARGS="$ASTARGS -I"
fi
if [ "x$TEMPRECORDINGLOCATION" = "xyes" -o "x$TMPRECORDINGLOCATION" = "xyes" ]; then
ASTARGS="$ASTARGS -t"
fi
if [ "x$COLOR" = "xyes" ]; then
export TERM=linux
daemon sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 &
else
daemon $DAEMON $ASTARGS
fi
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
echo
return $RETVAL
}
stop() {
# Stop daemons.
if [ -f $SAFE_ASTERISK ]; then
# Kill safe_asterisk first, to prevent us from starting up 2 instances of safe_asterisk
echo -n $"Stopping safe_asterisk: "
killproc `basename $SAFE_ASTERISK`
echo
fi
echo -n $"Shutting down asterisk: "
killproc `basename $DAEMON`
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/asterisk
echo
return $RETVAL
}
restart() {
stop
start
}
reload() {
$DAEMON -rx 'module reload' > /dev/null 2> /dev/null
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
[ -f /var/lock/subsys/asterisk ] && restart || :
;;
status)
status asterisk
;;
*)
echo "Usage: asterisk {start|stop|restart|reload|condrestart|status}"
exit 1
esac
exit $?