2008-11-18 21:01:46 +00:00
|
|
|
#!/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
|
|
|
|
#
|
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
|
|
|
|
|
2008-11-18 21:01:46 +00:00
|
|
|
. /etc/rc.conf
|
|
|
|
. /etc/rc.d/functions
|
2009-02-21 13:13:35 +00:00
|
|
|
DAEMON=__ASTERISK_SBIN_DIR__/asterisk
|
|
|
|
ASTVARRUNDIR=__ASTERISK_VARRUN_DIR__
|
2008-11-18 21:01:46 +00:00
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
stat_busy "Starting Asterisk..."
|
2009-02-21 13:13:35 +00:00
|
|
|
if [ ! -d $ASTVARRUNDIR ]; then
|
|
|
|
mkdir -p $ASTVARRUNDIR
|
|
|
|
fi
|
|
|
|
if [ -x $DAEMON ]; then
|
2008-11-18 21:01:46 +00:00
|
|
|
# Check if Asterisk is already running. If it is, then bug out, because
|
|
|
|
# starting safe_asterisk when Asterisk is running is very bad.
|
2009-02-21 13:13:35 +00:00
|
|
|
VERSION=`${DAEMON} -rx 'core show version'`
|
2008-11-18 21:01:46 +00:00
|
|
|
if [ "`echo $VERSION | cut -c 1-8`" = "Asterisk" ]; then
|
|
|
|
echo "Asterisk is already running. $0 will exit now."
|
|
|
|
exit 1
|
|
|
|
fi
|
2009-02-21 13:13:35 +00:00
|
|
|
${DAEMON}
|
2008-11-18 21:01:46 +00:00
|
|
|
stat_done
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
stop)
|
2009-02-21 13:13:35 +00:00
|
|
|
if [ -r ${ASTVARRUNDIR}/asterisk.pid ]; then
|
2008-11-18 21:01:46 +00:00
|
|
|
stat_busy "Stoping Asterisk..."
|
2009-02-21 13:13:35 +00:00
|
|
|
${DAEMON} -rx "core stop now" > /dev/null 2&>1
|
2008-11-18 21:01:46 +00:00
|
|
|
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
|