#! /bin/sh
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#		Modified for yate by Radu Spineanu <radu@timisoara.roedu.net>.
#			and Kilian Krause <kk@verfaction.de>

### BEGIN INIT INFO
# Provides:          yate
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Yet another telephony engine
# Description:       Start YATE in daemon mode
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/yate
NAME=yate
DESC=yate
PIDFILE=/var/run/$NAME.pid

test -x $DAEMON || exit 0

# Include yate defaults if available
if [ -f /etc/default/yate ] ; then
	. /etc/default/yate
fi

if [ "$NO_START" = "1" ];then
	echo Yate Daemon not setup for automagic start. Edit /etc/default/yate to change this.
	exit 0
fi
set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "

	#so yate won't load the client modules
	unset DISPLAY

	start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE \
		--user $YATE_USER --group $YATE_GROUP \
		--exec $DAEMON -- $DAEMON_OPTS
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
	echo "$NAME."
	;;
  reload)
	echo "Reloading $DESC module files."
	start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE --exec $DAEMON
  ;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
	sleep 1

	#so yate won't load the client modules
	unset DISPLAY

        start-stop-daemon --start --quiet --pidfile $PIDFILE \
                --user $YATE_USER --group $YATE_GROUP \
                --exec $DAEMON -- $DAEMON_OPTS
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0
