blob: 8f037d3df56766104deb1975483249184e1557a8 (
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
|
#!/bin/sh
#
# $FreeBSD$
#
# A sample XORP startup script.
#
# PROVIDE: xorp
# REQUIRE: netif routing mountcritlocal
# BEFORE: NETWORKING
# Add the following lines to /etc/rc.conf to enable xorp:
#
# xorp_enable="YES"
# xorp_flags="<set as needed>"
# xorp_config_boot="%%PREFIX%%/etc/xorp.conf.sample"
. /etc/rc.subr
name="xorp"
rcvar=xorp_enable
load_rc_config $name
: ${xorp_enable="NO"}
: ${xorp_config_boot="%%PREFIX%%/etc/xorp.conf"}
: ${xorp_rtrmgr_pidfile="/var/run/xorp_rtrmgr.pid"}
: ${xorp_rtrmgr_logfile="/var/log/xorp_rtrmgr.log"}
: ${xorp_rtrmgr_poll_enable=true}
: ${xorp_rtrmgr_poll_timeout=90}
: ${xorp_hardkill_enable=false}
required_files=${xorp_config_boot}
command=%%PREFIX%%/bin/xorp_rtrmgr
command_args="-b ${xorp_config_boot}"
pidfile=${xorp_rtrmgr_pidfile}
sig_stop=INT
start_precmd="xorp_prestart"
start_cmd="xorp_start"
stop_postcmd="xorp_poststop"
xorp_prestart()
{
touch ${xorp_rtrmgr_logfile}
return 0
}
xorp_start()
{
pidfile=${xorp_rtrmgr_pidfile}
echo -n 'Starting XORP router processes:'
echo -n ' xorp_rtrmgr'
if ! daemon </dev/null >>${xorp_rtrmgr_logfile} 2>&1 -c -p ${pidfile} \
${command} ${command_args} ; then
warn 'could not bring up xorp_rtrmgr.'
return 1
fi
${xorp_rtrmgr_poll_enable} || return 0
# If startup polling is enabled, then poll xorp_rtrmgr every
# second to see if it died, or if it logged successful bringup.
# XXX This may be racy on very fast machines, but without
# daemonizing support from xorp_rtrmgr it's difficult not to race.
pid=$(cat ${xorp_rtrmgr_pidfile})
timeout=${xorp_rtrmgr_poll_timeout}
tick=0
fail=true
until [ $tick = $timeout ];
do
sleep 1 ; kill -0 ${pid} || break
if ( tail -5 ${xorp_rtrmgr_logfile} | \
grep 'No more tasks to run' > /dev/null 2>&1 ) ; then
fail=false
break
fi
tick=$((tick + 1))
done
if $fail ; then
warn 'xorp_rtrmgr failed to start'
return 1
fi
echo '.'
return 0
}
xorp_poststop()
{
rm -f ${xorp_rtrmgr_pidfile} >/dev/null 2>&1 || true
${xorp_hardkill_enable} || return 0
killall -9 -m xorp_\* || true
return 0
}
run_rc_command "$1"
|