#!/sbin/runscript
# $Id$

depend() {
	need net logger
}

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

	ebegin "Starting Asterisk"
	/usr/sbin/asterisk
	eend $? "Failed to start Asterisk"
}

stop() {
	ebegin "Stopping Asterisk"
	kill $(cat /var/run/asterisk.pid)
	eend $? "Failed to stop Asterisk"
}
