#! /bin/sh
#
# innd		InterNet News System

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

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
	exit 0
fi

[ -d /etc/news ] || exit 0
[ -d /usr/lib/news ] || exit 0
[ -d /var/spool/news ] || exit 0

# See how we were called.
case "$1" in
  start)
	echo -n "Starting INND system: "
	su news -c /etc/rc.d/rc.news
	touch /var/lock/subsys/news
	;;
  stop)
	echo -n "Stopping INND service: "
	su news -c "/usr/lib/news/bin/ctlinnd shutdown 'stop required'" &
	# give it a try to die gracefuly
	sleep 5
	# just in case innd didn't die gracefully
	if [ -f /var/run/news/innd.pid ]
	then
		kill -9 `cat /var/run/news/innd.pid`
		rm -f /var/run/news/innd.pid
	fi
	# always echo that INND is shut down
	echo -n "innd "
	if [ -f /var/run/news/innwatch.pid ]
	then
		kill -9 `cat /var/run/news/innwatch.pid`
		rm -f /var/run/news/innwatch.pid
		echo -n "innwatch "
	fi
	echo 
	rm -f /var/lock/subsys/news /var/lock/news/*
	;;
  *)
	echo "Usage: $0 {start|stop}"
	exit 1
esac

exit 0
