#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
# Author:	Miquel van Smoorenburg <miquels@cistron.nl>.
#		Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
#		You may remove the "Author" lines above and replace them
#		with your own name if you copy and modify this script.
#
# Version:	@(#)skeleton  1.9.3  02-Nov-2003  miquels@cistron.nl
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/siproxd
NAME=siproxd
DESC="SIP SERVER"
ENABLED=0

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

# Read config file if it is present.
[ -e /etc/default/$NAME ] && . /etc/default/$NAME

if [ "$ENABLED" != "1" ];
	then
		echo "Not Enabled. See README.Debian for Details"
		exit 0
fi

kill_by_name() {
	NAME="$1"
	echo -n "$NAME "
#	start-stop-daemon --stop --quiet --name $NAME
	i=1
	while [ "$i" -le 10 ]; do
		pidof $NAME 2>&1 >/dev/null || break
		echo -n "."
		sleep 1
		i=$(($i+1))
	done	
	pidof $NAME 2>&1 >/dev/null && killall $NAME 2>&1 >/dev/null
	echo
	
}


start()
{
	echo -n "Starting $DESC: $NAME "
	rm -fr /var/run/$NAME.pid
	start-stop-daemon --start --quiet \
		--exec $DAEMON
	echo "."
}

stop()
{
	echo -n "Stopping $DESC: "
	kill_by_name $DAEMON
	echo ""
}

set -e
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|force-reload)
	stop
	start
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
