#!/bin/sh
#
# $NetBSD: ndtpd.sh,v 1.3 2011/04/24 13:47:45 shattered Exp $
#
# PROVIDE: ndtpd
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# To start ndtpd at startup, copy this script to /etc/rc.d and set
# ndtpd=YES in /etc/rc.conf.

if [ -f /etc/rc.subr ]; then
	. /etc/rc.subr
fi

name="ndtpd"
rcvar="$name"
prog=/usr/pkg/sbin/ndtpd
pidfile=/var/run/ndtpd/ndtpd.pid

case $1 in
start)
	echo "Starting ${name}."
	/bin/mkdir -p /var/run/ndtpd
	${prog} >/dev/null 2>&1 || {
		echo "Configuration error?" >&2
		echo "Try /usr/pkg/sbin/ndtpcheck" >&2
		exit 1
	}
	;;
stop)
	echo "Stopping ${name}."
	if [ -f ${pidfile} ]; then
		pid=`/usr/bin/head -1 ${pidfile}`
		kill -s TERM ${pid}
		/bin/rm -fr /var/run/ndtpd
	else
		echo "${name} not running?"
		exit 1
	fi
	;;
*)
	echo "Usage: $0 [start|stop]" 1>&2
	exit 1
	;;
esac

exit 0
