#!/bin/sh
#
# chkconfig: 345 50 50
# description: xinetd is a powerful replacement for inetd. \
#              xinetd has access control machanisms, extensive logging \
#              capabilities, the ability to make services available based \
#              on time, and can place limits on the number of servers \
#              that can be started, among other things. 
# probe: true
# processname: xinetd
# pidfile: /var/run/xinetd.pid
# config: /etc/sysconfig/network
# config: /etc/xinetd.conf

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

# Source networking configuration.
# Check that networking is up.
SourceIfNotEmpty /etc/sysconfig/network &&
	[ "$NETWORKING" != no ] &&
	[ -s /etc/xinetd.conf ] ||
	exit

# Get config.
SourceIfNotEmpty /etc/sysconfig/xinetd

EXE=/usr/sbin/xinetd
LOCKFILE=/var/lock/subsys/xinetd
RETVAL=0

start()
{
	echo -n "Starting xinetd: "
	daemon "$EXE" "$EXTRAOPTIONS"
	RETVAL=$?
	echo	
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
	return $RETVAL
}

stop()
{
	echo -n "Stopping xinetd: "
	killproc "$EXE"
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
	return $RETVAL
}

reload()
{
	echo -n "Reloading xinetd: "
	killproc "$EXE" -HUP
	RETVAL=$?
	echo
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status "$EXE"
		RETVAL=$?
		;;
	reload|sreload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|status|reload|restart|condstop|condrestart|condreload}"
		RETVAL=1
esac

exit $RETVAL
