#! /bin/sh

# Modified for use with Siproxd by Dan Weber <dan@mirrorlynx.com>
# 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.4  21-Mar-2004  miquels@cistron.nl
#

### BEGIN INIT INFO
# Provides:          siproxd
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Should-Start:      
# Should-Stop:       
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: SIP Proxy Daemon
# Description:       Proxy for SIP channels of VoIP clients
### END INIT INFO

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=siproxd
DAEMON=/usr/sbin/$NAME
DESC="SIP proxy"
ENABLED=0
PIDFILE=/var/run/$NAME/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

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

# Make sure /var/run/$NAME exists
test -d /var/run/$NAME || install -d -o siproxd -g siproxd /var/run/$NAME

# Read config file if it is present.
if [ -r /etc/default/$NAME ]
then
	. /etc/default/$NAME
fi

if [ "$ENABLED" = "0" ]
then
    echo "To enable siproxd, the sip proxy, modify /etc/default/siproxd"
    exit 0
fi

start()
{
    echo -n "Starting $DESC: $NAME"
    start-stop-daemon --start --quiet --pidfile $PIDFILE \
	 --exec $DAEMON -- -p $PIDFILE
    echo "."
}

stop()
{
	echo -n "Stopping $DESC: $NAME"
	if test -e $PIDFILE; then
	    start-stop-daemon --stop --quiet --pidfile $PIDFILE
	fi
	echo "."
	rm -f $PIDFILE
}    

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|force-reload)
	stop
	start
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
