aboutsummaryrefslogtreecommitdiffstats
path: root/net/frr7/files/frr.in
blob: 2f46184e6da23bd7c6c427214519f939ffa3c3b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: frr
# REQUIRE: netif routing
# KEYWORD: nojailvnet shutdown

# Add the following line to /etc/rc.conf to enable frr:
#  frr_enable="YES"
#
# You may also wish to use the following variables to fine-tune startup:
#  frr_flags=""
#  frr_daemons="zebra babeld bfdd bgpd eigrpd fabricd isisd ospfd ospf6d ripd ripngd staticd"
#  frr_vtysh_boot="YES"
# Per daemon tuning may be done with daemon_name_flags
#  zebra_flags="-P 0"
#  bgpd_flags="-nrP 0" and so on
# If you want to give the routing deamons a chance to catchup before
# continueing, set frr_wait_for to a "default" or certain prefix.
#  frr_wait_for="default"
# Set the time limit for the wait.
#  frr_wait_seconds="90"
#
# If the frr daemons require additional shared libraries to start,
# use the following variable to run ldconfig(8) in advance:
#  frr_extralibs_path="/usr/local/lib ..."
#
# This RC script was adapted from the net/quagga port

. /etc/rc.subr

name=frr
rcvar=$name_enable

start_postcmd=start_postcmd
stop_postcmd="rm -f $pidfile"
configtest_cmd=check_config
extra_commands=configtest
command_args="-d"

load_rc_config $name
: ${frr_enable:="NO"}
: ${frr_flags:=""}
: ${frr_daemons:="zebra babeld bfdd bgpd eigrpd fabricd isisd ospfd ospf6d ripd ripngd staticd"}
: ${frr_vtysh_boot:="NO"}
: ${frr_wait_for:=""}
: ${frr_wait_seconds:="90"}

check_config()
{
    echo "Checking $daemon.conf"
    # pimd doesn't support -C
    if [ "$daemon" = "pimd" ]; then
        echo "Ignored"
    else
        $command $daemon_flags -C
        result=$?
        if [ "$result" -eq "0" ]; then
            echo "OK"
        else
            echo "FAILED"
            exit
        fi
    fi
}

start_postcmd()
{
    local waited_for
    waited_for=0
    # Wait only when last daemon has started.
    if [ "${frr_daemons}" = "${frr_daemons% ${name}}" ]; then
        return;
    fi
        if [ -n "${frr_wait_for}" ]; then
        echo Waiting for ${frr_wait_for} route...
        while [ ${waited_for} -lt ${frr_wait_seconds} ]; do
            /sbin/route -n get ${frr_wait_for} >/dev/null 2>&1 && break;
            waited_for=$((waited_for+1))
            sleep 1;
        done
        [ ${waited_for} -lt ${frr_wait_seconds} ] || echo Giving up...
    fi
}

do_cmd()
{
    local ret
    ret=0
    frr_cmd=$1
    if checkyesno frr_vtysh_boot && ( [ ${frr_cmd} = "restart" ] || [ ${frr_cmd} = "start" ] ); then
        echo "Checking intergrated config..."
        daemon="vtysh"
        daemon_flags=""
        command=%%PREFIX%%/bin/${daemon}
        check_config
    fi
    for daemon in ${frr_daemons}; do
        command=%%PREFIX%%/sbin/${daemon}
        pidfile=/var/run/frr/${daemon}.pid
        if ! checkyesno frr_vtysh_boot; then
            required_files=%%ETCDIR%%/${daemon}.conf
            if [ ${frr_cmd} = "restart" ] || [ ${frr_cmd} = "start" ]; then
                check_config
            fi
            if [ ${frr_cmd} = "start" ] && ! [ -f ${required_files} ]; then
                continue
            fi
        fi
        if [ ${frr_cmd} = "stop" ] && [ -z $(check_process ${command}) ]; then
            continue
        fi
        eval flags=\$\{${daemon}_flags:-\"${frr_flags}\"\}
        name=${daemon}
        _rc_restart_done=false
        run_rc_command "$1" || ret=1
    done
    if checkyesno frr_vtysh_boot && ( [ ${frr_cmd} = "restart" ] || [ ${frr_cmd} = "start" ] ); then
        echo "Booting for integrated-vtysh-config..."
        %%PREFIX%%/bin/vtysh -b
    fi
    return ${ret}
}

frr_cmd=$1

case "$1" in
    force*)
        frr_cmd=${frr_cmd#force}
        ;;
    fast*)
        frr_cmd=${frr_cmd#fast}
        ;;
esac
shift

if [ $# -ge 1 ]; then
    frr_daemons="$*"
fi

case "${frr_cmd}" in
    start|quietstart)
        if [ -n "${frr_extralibs_path}" ]; then
            /sbin/ldconfig -m ${frr_extralibs_path}
        fi
        # Why should I need to add this check ?
        checkyesno frr_enable && do_cmd "start"
        ;;
    stop)
        frr_daemons=$(reverse_list ${frr_daemons})
        do_cmd "stop"
        ;;
    restart)
        frr_daemons=$(reverse_list ${frr_daemons})
        do_cmd "stop"
        frr_daemons=$(reverse_list ${frr_daemons})
        checkyesno frr_enable && do_cmd "start"
        ;;
    *)
        do_cmd "${frr_cmd}"
        ;;
esac