#! /bin/sh
#
# init.d/inn	Start/stop the news server.

test -f /usr/sbin/innd || exit 0

start () {
  start-stop-daemon --quiet --start --exec /etc/news/boot
  sleep 1
}

stop () {
  if [ -f /var/run/innd/innwatch.pid ]; then
    start-stop-daemon --quiet --stop --pidfile /var/run/innd/innwatch.pid
  fi
  if [ -f /var/run/innd/innd.pid ]; then
    ctlinnd -s -t 20 throttle 'system is going down'
    ctlinnd -s -t 20 shutdown 'system is going down'
    start-stop-daemon --quiet --stop --pidfile /var/run/innd/innd.pid \
      --exec /usr/sbin/innd
  fi
}

case "$1" in
	start)
		start
		;;
	stop)
		echo "Stopping news server: innd"
		stop
		;;
	reload|force-reload)
		echo -n "Reloading INN configuration files: "
		ctlinnd -t 20 reload '' $0
		;;
	restart)
		stop
		sleep 2
		start
		;;
	*)
		echo "Usage: /etc/init.d/inn start|stop|restart|reload" >&2
		exit 1
		;;
esac

exit 0
