Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 4921fe814549dff61a41fab617533c8b > files > 58

asterisk-1.8.12.2-1.fc15.i686.rpm

#!/bin/sh
# $Id: rc.redhat.asterisk 337115 2011-09-20 22:18:25Z lmadsen $
#
# asterisk    Starts, Stops and Reloads Asterisk.
#
# chkconfig: - 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

# Do not modify this script to change any of the settings, instead
# edit /etc/sysconfig/asterisk

# Use this option to specify a different configuration directory
AST_CONFIG=__ASTERISK_ETC_DIR__/asterisk.conf

# Installation directory
AST_SBIN=__ASTERISK_SBIN_DIR__

# Source function library.
. /etc/rc.d/init.d/functions

# The user that Asterisk will run as.
AST_USER="asterisk"

# If a user is specified above, Asterisk will change the group it runs
# as to the primary group of the user, as well as initialize the
# supplementary groups.  If you want to run Asterisk as a different
# group, set AST_GROUP to the group that Asterisk should run as.  Note
# that this may break DAHDI devices as supplementary groups will not
# be initialized.
#AST_GROUP="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
[ -f $CONFIGFILE ] && . $CONFIGFILE

if ! [ -x $AST_SBIN/asterisk ] ; then
	echo "ERROR: $AST_SBIN/asterisk not found"
	exit 0
fi

if ! [ -f $AST_CONFIG ] ; then
	echo "ERROR: $AST_CONFIG not found"
	exit 0
fi

# Full path to asterisk binary
DAEMON=$AST_SBIN/asterisk

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.
	VERSION=`${AST_SBIN}/asterisk -rx 'core show version'`
	if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
		echo "Asterisk is already running."
		exit 0
	fi

	# Start daemons.
	echo -n $"Starting asterisk: "

	export HOME=~asterisk
	cd $HOME

	if [ $AST_USER ] ; then
		AST_ARGS="$AST_ARGS -U $AST_USER"
	fi
	if [ $AST_GROUP ] ; then
		AST_ARGS="$AST_ARGS -G $AST_GROUP"
	fi
	if [ $AST_CONFIG ]; then
		ASTARGS="$ASTARGS -C $AST_CONFIG"
	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 $AST_EXTRA_ARGS -c" >/dev/null </dev/null 2>&1 &
	else
		daemon $DAEMON $ASTARGS $AST_EXTRA_ARGS
	fi
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/asterisk
	echo
	return $RETVAL
}

stop() {
	# Stop daemon.
	echo -n $"Stopping 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 $?