#! /bin/sh
#
# Copyright (c) 1998 Florian La Roche
#
### BEGIN INIT INFO
# Provides:          inn
# Required-Start:    $network $named
# Required-Stop:     $network $named
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Inter Net News Server (INN)
# Description:       Inter Net News Server (INN)
### END INIT INFO
     
. /etc/rc.status

function run_as_news ()
{
    if test "x$UID" = x0 ; then
	    su news -c "$*"
    else
	    $*
    fi
}

NEWSCONF=/etc/news/inn.conf

test -f $NEWSCONF || exit 5
PATHRUN=`sed -ne 's/^pathrun: *//p' < $NEWSCONF`
PATHBIN=`sed -ne 's/^pathbin: *//p' < $NEWSCONF`

WATCH=${PATHRUN}/innwatch.pid
ACTIVED=${PATHRUN}/actived.pid
PID=${PATHRUN}/innd.pid


# The echo return value for success (defined in /etc/rc.config).
rc_reset
case "$1" in
    start)	echo -n "Starting News-Server INN"
		run_as_news  "$PATHBIN/rc.news"
		rc_status -v
		;;
    stop)	echo -n "Shutting down News-Server INN"
		run_as_news  "$PATHBIN/rc.news stop"
		rc_status -v
		;;
    restart)
    		$0 stop
		$0 start
		rc_status
		;;
    reload)
    		echo -n "News-Server INN reload configuration files"
    		run_as_news "$PATHBIN/ctlinnd" reload all "by rcinn reload" >/dev/null
		rc_status -v
    		;;
    status)
		test -f "$PID" && run_as_news "$PATHBIN/ctlinnd" mode
		echo -n "News-Server INN: "
		checkproc -p "$PID" "$PATHBIN/innd"
		rc_status -v
		;;		
    *)
		echo "Usage: $0 {start|stop|restart|reload|status}"
		exit 1
esac
rc_exit
