#! /bin/bash

# Source function library (and set vital variables).
. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
 start)
  [ ! -e $SVIlock ] || exit 1
  
  SVIemptyConfig /etc/news/inn.conf && {
    echo "$DESCRIPTIVE: not configured! Skipped..."
    exit 2
  }

  echo -n "Starting $IDENT services: "
  SVIrun S I "innd" "!innd" \
  /usr/libexec/inn/bin/rc.news

  echo  "."
  touch $SVIlock
  ;;

 stop)
  [ -e $SVIlock ] || exit 0

  echo -n "Stopping $IDENT services: "
  SVIrun S I "innd." "ctlinnd failed." \
  /usr/libexec/inn/bin/ctlinnd -s -t 30 shutdown System stopped
  test -f /var/run/news/innwatch.pid &&
	kill -1 `cat /var/run/news/innwatch.pid`

  echo "."
  rm -f $SVIlock
  ;;

 *)
  echo "Usage: $SVIscript {start|stop}"
  exit 1
  ;;
esac

exit 0
