#!/bin/sh
############################################################
# Program: /etc/rc.d/rc.xinetd
# Purpose: Run control for xinetd 
# Author : Stuart Winter <mozes@armedslack.org>
# Date...: 26/Nov/02
############################################################

PIDFILE=/var/run/xinetd.pid

function start_xinetd () {
   echo -n "Starting xinetd.. "
   rm -f ${PIDFILE} 
   /usr/sbin/xinetd \
     -stayalive \
     -reuse \
     -pidfile ${PIDFILE}
   if [ $? -gt 0 ]; then
       echo "FAILED!"
    else
      echo "OK"
   fi
}

function stop_xinetd () {
   echo "Stopping xinetd"
   if [ -f "${PIDFILE}" ]; then
      kill -9 "$( cat ${PIDFILE} )"
   fi
   killall -9 xinetd >/dev/null 2>&1 # just to make sure ;p
}

case "$1" in
  start)
       start_xinetd ;;

  stop)
       stop_xinetd ;;

  rehash)
       echo "Rehashing xinetd (sending -HUP signal)"
       killall -HUP xinetd ;;

  restart)
       stop_xinetd
       start_xinetd ;;

  *)   echo "Usage: $0 {start|stop|rehash|restart}"
       exit 1 

esac

# EOF
