#!/bin/sh
#
# bird		Starts the Dynamic Route Daemon
#
# chkconfig:	345 11 90
#
# description:	Dynamic Route Daemon
#
# processname:	bird
# config:	/etc/bird.conf


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

# Get network config
. /etc/sysconfig/network

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

# 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 bird
		exit 1
	fi
else
	exit 0
fi

# Sanity checks.
[ -f /etc/bird.conf ] || exit 0

checkconfig() {
	/usr/sbin/bird -p || exit 1
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the services are already running?
	if [ ! -f /var/lock/subsys/bird ]; then
		checkconfig
		msg_starting bird
		daemon ${SERVICE_RUN_NICE_LEVEL} /usr/sbin/bird -u bird -g bird -P /var/run/bird/bird.pid $BIRD_OPTS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/bird
	else
		msg_already_running bird
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/bird ]; then
		msg_stopping bird
		killproc --pidfile /var/run/bird/bird.pid bird
		rm -f /var/lock/subsys/bird
	else
		msg_not_running bird
	fi
	;;
  restart)
	checkconfig
	$0 stop
	$0 start
	exit $?
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/bird ]; then
		checkconfig
		msg_reloading bird
		killproc --pidfile /var/run/bird/bird.pid bird -HUP
		RETVAL=$?
	else
		msg_not_running bird
		RETVAL=7
	fi
	;;
  configtest)
	checkconfig
	;;
  status)
	status --pidfile /var/run/bird/bird.pid bird
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|configtest|status}"
	exit 3
esac

exit $RETVAL
