#! /bin/sh
#
# diablo	Start/stop the Diablo news server daemon.
#
# Version:	@(#)diablo.sh  1.2  28-Feb-1998  miquels@cistron.nl
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/diablo
NAME=diablo
DESC="news server"
SPACES="-s                                                                   "
NEWSDIR="/etc/news"

test -f $DAEMON  || exit 0
test -d $NEWSDIR || exit 0
cd $NEWSDIR

#ulimit -n 1024		# Max no of file descriptors.
#ulimit -u 256		# Max no of processes

set -e
DNAME=`cat $NEWSDIR/diablo.pathname`
if [ -s $NEWSDIR/diablo.hostname ]
then
	HNAME=`cat $NEWSDIR/diablo.hostname`
else
	HNAME=$DNAME
fi

case "$1" in
  start)
    if [ "$DNAME" = unconfigured ]
    then
	echo "Diablo not configured - not started."
	exit 0
    fi
    echo -n "Starting $DESC: "
    start-stop-daemon --start --quiet \
		--exec $DAEMON -- server "$SPACES" -p $DNAME -h $HNAME
    echo "$NAME."
    ;;
  stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
    echo "$NAME."
    ;;
  reload)
    #
    # Diablo re-reads config files on the fly.
    #
    ;;
  restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
    sleep 1
    start-stop-daemon --start --quiet \
		--exec $DAEMON -- server "$SPACES" -p $DNAME -h $HNAME
    echo "$NAME."
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload}"
    exit 1
    ;;
esac

exit 0
