#!/bin/sh
#
# yate:	Starts the Yet Another Telephony Engine
#
# chkconfig: 345 95 10
# description: Starts and stops yate used as Telephony Server
#
# processname: yate
# pidfile: /var/run/yate.pid
#

# Extra Yate command line options
OPTS="-rs -vvv -l /var/log/yate"

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

RETVAL=0

start() {
    gprintf "Starting yate: "
    unset DISPLAY
    daemon yate -d -p /var/run/yate.pid $OPTS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/yate
}

stop() {
    gprintf "Stopping yate: "
    killproc yate
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm -f /var/lock/subsys/yate
    fi
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
        status yate
	RETVAL=$?
        ;;
    restart)
	stop
	start
	;;
    condrestart)
	if [ -f /var/lock/subsys/yate ]; then
	    stop
	    start
	fi
	;;
    reload)
  	killproc yate -HUP
	RETVAL=$?
        ;;
    *)
	gprintf "Usage: %s {start|stop|status|restart|condrestart|reload}\n" "$0"
	;;
esac
exit $RETVAL
