#!/bin/sh
#
# ircd		This shell script takes care of starting and stopping ircd.
#
# chkconfig:	234 75 30
# description:	Internet Relay Chat Server.
#

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

# Source networking configuration.
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/ircd ] && . /etc/sysconfig/ircd

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down IRCd
		exit 1
	fi
else
	exit 0
fi

if is_yes "$IPV6_NETWORKING" && [ -x /usr/sbin/ircd6 ]; then
    IRCD="/usr/sbin/ircd6"
else
    IRCD="/usr/sbin/ircd"
fi

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/ircd ]; then
		# Start daemons.
		msg_starting "IRCd Server"
		daemon ${IRCD} -c
		touch /var/lock/subsys/ircd
	else
		msg_already_running IRCd
	fi
	;;
  stop)
	# Check if the service is already running?
	if [ -f /var/lock/subsys/ircd ]; then
		# Stop daemons.
		msg_stopping "IRCd Server"
		killproc ${IRCD#\-}
		rm -f /var/run/ircd.pid
		rm -f /var/lock/subsys/ircd
	else
		msg_not_running IRCd
	fi
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/ircd ]; then
		msg_reloading "IRCd Server"
		killproc ${IRCD#\-} -HUP
		RETVAL=$?
	else
		msg_not_running IRCd >&2
		exit 7
	fi
	;;
  restart)
	$0 stop
	$0 start
	exit $?
	;;
  status)
	status ${IRCD#\-}
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
