#!/bin/bash
#
# bird6 - BIRD Internet Routing Daemon
#
# chkconfig: - 80 20
# description: BIRD is a dynamic IP routing daemon supporting both, IPv4 and IPv6, Border \
#              Gateway Protocol (BGPv4), Routing Information Protocol (RIPv2, RIPng), Open \
#              Shortest Path First protocol (OSPFv2, OSPFv3), Babel Routing Protocol (Babel), \
#              Bidirectional Forwarding Detection (BFD), IPv6 router advertisements, static \
#              routes, inter-table protocol, command-line interface allowing on-line control \
#              and inspection of the status of the daemon, soft reconfiguration as well as a \
#              powerful language for route filtering.
# config: /etc/bird6.conf

### BEGIN INIT INFO
# Provides: bird6
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 
# Default-Stop: 0 1 6
# Short-Description: BIRD Internet Routing Daemon
# Description: BIRD is a dynamic IP routing daemon supporting both, IPv4 and IPv6, Border
#              Gateway Protocol (BGPv4), Routing Information Protocol (RIPv2, RIPng), Open
#              Shortest Path First protocol (OSPFv2, OSPFv3), Babel Routing Protocol (Babel),
#              Bidirectional Forwarding Detection (BFD), IPv6 router advertisements, static
#              routes, inter-table protocol, command-line interface allowing on-line control
#              and inspection of the status of the daemon, soft reconfiguration as well as a
#              powerful language for route filtering.
### END INIT INFO

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

prog="bird6"
exec="/usr/sbin/$prog"
user="bird6"
lockfile="/var/lock/subsys/$prog"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
    [ -x $exec ] || exit 5
    [ -f $config ] || exit 6
    echo -n $"Starting $prog: "
    daemon $exec -u $user -g $user $OPTIONS
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $exec
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile    
    return $retval
}

reload() {
    echo -n $"Reloading $prog: "
    killproc $exec -HUP
    retval=$?
    echo
    return $retval
}

rh_status() {
    status $exec
}

rh_status_q() {
    rh_status > /dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        stop
        start
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        restart
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        stop
        start
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac

exit $?
