#!/bin/sh
# chkconfig: - 12 88
# description: IS-IS routing daemon for use with Quagga
# processname: isisd
# config: /etc/quagga/isisd.conf
# pidfile: /var/lib/quagga/isisd.pid

### BEGIN INIT INFO
# Provides:          isisd
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:
# Default-Stop:
# Short-Description: Start isisd at boot time
# Description:       Enable IS-IS routing
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

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

# quagga command line options
SourceIfNotEmpty /etc/sysconfig/quagga

ZNAME=isisd

# Config is a must to run
[ -f /etc/quagga/$ZNAME.conf ] || exit 0

RETVAL=0
PIDFILE=/var/lib/quagga/$ZNAME.pid
LOCKFILE=/var/lock/subsys/$ZNAME

start()
{
	is_yes "$NETWORKING" || return 0
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user quagga -- $ZNAME --daemon $ISISD_OPTS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user quagga -- $ZNAME
	RETVAL=$?
	return $RETVAL
}

restart()
{
	$ZNAME --dryrun &>/dev/null
	RETVAL=$?
	if [ $[ $RETVAL > 0 ] == 1 ]; then
	    echo "Service $ZNAME is not restarted: config's test failed. Try '$ZNAME --dryrun'"
	    exit $RETVAL
	fi

	stop
	start
}

reload()
{
	$ZNAME --dryrun &>/dev/null
	RETVAL=$?
	if [ $[ $RETVAL > 0 ] == 1 ]; then
	    echo "Service $ZNAME is not reloaded: config's test failed. Try '$ZNAME --dryrun'"
	    exit $RETVAL
	fi

	msg_reloading $ZNAME
	stop_daemon -HUP $ZNAME
	RETVAL=$?
	return $RETVAL
}


# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  reload)
	reload
	;;
  restart)
	restart
	;;
  condstop)
	# Stop the servce if it is already running
	if [ -e "$LOCKFILE" ]; then
	 stop
	fi
	;;
  condrestart|condreload)
	# Restart the servce if it is already running
	if [ -e "$LOCKFILE" ]; then
 	 restart
	fi
	;;
  status)
	# report the status of the daemons in free-form format
	status --pidfile "$PIDFILE" --expect-user quagga -- $ZNAME
	RETVAL=$?
	;;
  *)
	msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
	RETVAL=1
esac

exit $RETVAL
