#! /bin/sh
#
# /etc/init.d/nstxd: start and stop the nstx IP over DNS daemon

DAEMON=/usr/sbin/nstxd
NAME=nstxd
DESC=nstxd
#NSTX_OPTIONS="-C /var/run/nstxd # -u nstxd"
NSTX_OPTIONS="-D"

test -x $DAEMON || exit 0

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

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

set -e

case "$1" in
  start)
	gprintf "Starting $DESC: "
	if [ -n "$NSTX_IFACE" ]; then
		OPTIONS="-i $NSTX_IFACE $NSTX_OPTIONS $NSTX_DOMAIN"
	else
		OPTIONS="$NSTX_OPTIONS $NSTX_DOMAIN"
	fi
	daemon $DAEMON $OPTIONS 
	touch /var/lock/subsys/nstxd
	sleep 1;
	if [ -n "$ifup_tun" ]; then
	    ifconfig $ifup_tun up $tun_ip_address netmask $tun_ip_netmask
	fi
	echo 
	;;
  stop)
	gprintf  "Stopping $DESC: "
	if [ -n "$ifup_tun" ]; then
		ifconfig $ifup_tun down >/dev/null 2>&1
	fi
	killproc $DAEMON
	rm -f /var/lock/subsys/nstxd
	echo 
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	$0 stop
	$0 start
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
