#!/bin/sh
# rc.zebra:  start/stop/restart quagga daemons
#

zebra_start() {
    if [ -r /etc/quagga/zebra.conf ]; then
      echo "Starting Zebra daemon: /usr/sbin/zebra -d"
      /usr/sbin/zebra -d
    fi

    if [ -r /etc/quagga/ripd.conf ]; then
      echo "Starting RIP daemon: /usr/sbin/ripd -d"
      /usr/sbin/ripd -d
    fi

    if [ -r /etc/quagga/ospfd.conf ]; then
      echo "Starting OSPF daemon with OSPF-API enabled: /usr/sbin/ospfd -a -d"
      /usr/sbin/ospfd -a -d
    fi

    if [ -r /etc/quagga/bgpd.conf ]; then
      echo "Starting BGP daemon: /usr/sbin/bgpd -d"
      /usr/sbin/bgpd -d
    fi
}

zebra_stop() {
  echo "Stopping quagga daemons"
  killall -9 bgpd 2> /dev/null
  killall -9 ospfd 2> /dev/null
  killall -9 ripd 2> /dev/null
  killall -9 zebra 2> /dev/null 
}

zebra_restart() {
  zebra_stop
  sleep 1
  zebra_start
}

case "$1" in
'start')
  zebra_start
  ;;
'stop')
  zebra_stop
  ;;
'restart')
  zebra_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac
