5
# Required-Start: $local_fs $network $remote_fs $syslog
6
# Required-Stop: $local_fs $network $remote_fs $syslog
7
# Default-Start: 2 3 4 5
9
# Short-Description: start and stop the Quagga routing suite
10
# Description: Quagga is a routing suite for IP routing protocols like
11
# BGP, OSPF, RIP and others. This script contols the main
12
# daemon "quagga" as well as the individual protocol daemons.
16
PATH=/bin:/usr/bin:/sbin:/usr/sbin
17
D_PATH=/usr/lib/quagga
20
# Local Daemon selection may be done by using /etc/quagga/daemons.
21
# See /usr/share/doc/quagga/README.Debian.gz for further information.
22
# Keep zebra first and do not list watchquagga!
23
DAEMONS="zebra bgpd ripd ripngd ospfd ospf6d isisd babeld"
25
. /lib/lsb/init-functions
27
# Print the name of the pidfile.
30
echo "/var/run/quagga/$1.pid"
33
# Check if daemon is started by using the pidfile.
36
[ -e `pidfile $1` ] && kill -0 `cat \`pidfile $1\`` 2> /dev/null && return 0
40
# Loads the config via vtysh -b if configured to do so.
43
# Rember, that all variables have been incremented by 1 in convert_daemon_prios()
44
if [ "$vtysh_enable" = 2 -a -f $C_PATH/Quagga.conf ]; then
49
# Check if the daemon is activated and if its executable and config files
52
# returns: 0=ok, 1=error
55
# If the integrated config file is used the others are not checked.
56
if [ -r "$C_PATH/Quagga.conf" ]; then
60
# vtysh_enable has no config file nor binary so skip check.
61
# (Not sure why vtysh_enable is in this list but does not hurt)
62
if [ $1 != "watchquagga" -a $1 != "vtysh_enable" ]; then
63
# check for daemon binary
64
if [ ! -x "$D_PATH/$1" ]; then return 1; fi
66
# check for config file
67
if [ ! -r "$C_PATH/$1.conf" ]; then
68
echo -n " (not started without config file)"
75
# Starts the server if it's not alrady running according to the pid file.
76
# The Quagga daemons creates the pidfile when starting.
80
if ! check_daemon $1; then return; fi
82
if [ "$1" = "watchquagga" ]; then
86
--pidfile=`pidfile $1` \
89
"${watchquagga_options[@]}"
93
--pidfile=`pidfile $1` \
96
`eval echo "$""$1""_options"`
100
# Stop the daemon given in the parameter, printing its name to the terminal.
103
if ! started "$1" ; then
108
PID=`cat $PIDFILE 2>/dev/null`
109
start-stop-daemon --stop --quiet --oknodo --exec "$D_PATH/$1"
111
# Now we have to wait until $DAEMON has _really_ stopped.
113
if test -n "$PID" && kill -0 $PID 2>/dev/null; then
114
echo -n " (waiting) ."
116
while kill -0 $PID 2>/dev/null; do
118
if [ $cnt -gt 60 ]; then
119
# Waited 120 secs now, fail.
132
# Converts values from /etc/quagga/daemons to all-numeric values.
133
convert_daemon_prios()
135
for name in $DAEMONS zebra vtysh_enable watchquagga_enable; do
136
# First, assign the value set by the user to $value
139
# Daemon not activated or entry missing?
140
if [ "$value" = "no" -o "$value" = "" ]; then value=0; fi
142
# These strings parsed for backwards compatibility.
143
if [ "$value" = "yes" -o "$value" = "true" ]; then value=1; fi
145
# Zebra is threatened special. It must be between 0=off and the first
146
# user assigned value "1" so we increase all other enabled daemons' values.
147
if [ "$name" != "zebra" -a "$value" -gt 0 ]; then value=`expr "$value" + 1`; fi
149
# If e.g. name is zebra then we set "zebra=yes".
154
# Starts watchquagga for all wanted daemons.
161
# Start the monitor daemon only if desired.
162
if [ 0 -eq "$watchquagga_enable" ]; then
166
# Check variable type
167
if ! declare -p watchquagga_options | grep -q '^declare \-a'; then
169
echo "ERROR: The variable watchquagga_options from /etc/quagga/debian.cnf must be a BASH array!"
170
echo "ERROR: Please convert config file and restart!"
174
# Which daemons have been started?
176
for daemon_name in $DAEMONS; do
177
eval daemon_prio=\$$daemon_name
178
if [ "$daemon_prio" -gt 0 ]; then
179
watchquagga_options+=($daemon_name)
184
# Start if at least one daemon is activated.
185
if [ $found_one -eq 1 ]; then
186
echo -n "Starting Quagga monitor daemon:"
192
# Stopps watchquagga.
195
echo -n "Stopping Quagga monitor daemon:"
200
# Stops all daemons that have a lower level of priority than the given.
201
# (technically if daemon_prio >= wanted_prio)
209
daemon_list=${2:-$DAEMONS}
211
echo -n "Stopping Quagga daemons (prio:$wanted_prio):"
213
for prio_i in `seq 10 -1 $wanted_prio`; do
214
for daemon_name in $daemon_list; do
215
eval daemon_prio=\$$daemon_name
216
if [ $daemon_prio -eq $prio_i ]; then
224
# Starts all daemons that have a higher level of priority than the given.
225
# (technically if daemon_prio <= wanted_prio)
233
daemon_list=${2:-$DAEMONS}
235
echo -n "Starting Quagga daemons (prio:$wanted_prio):"
237
for prio_i in `seq 1 $wanted_prio`; do
238
for daemon_name in $daemon_list; do
239
eval daemon_prio=\$$daemon_name
240
if [ $daemon_prio -eq $prio_i ]; then
248
#########################################################
250
#########################################################
252
# Config broken but script must exit silently.
253
[ ! -r "$C_PATH/daemons" ] && exit 0
257
. "$C_PATH/debian.conf"
259
# Set priority of un-startable daemons to 'no' and substitute 'yes' to '0'
262
if [ ! -d /var/run/quagga ]; then
263
mkdir -p /var/run/quagga
264
chown quagga:quagga /var/run/quagga
265
chmod 755 /var/run/quagga
270
# Try to load this necessary (at least for 2.6) module.
271
if [ -d /lib/modules/`uname -r` ] ; then
272
echo "Loading capability module if not yet done."
273
set +e; LC_ALL=C modprobe -a capability 2>&1 | egrep -v "(not found|Can't locate)"; set -e
278
if [ "$2" != "watchquagga" ]; then
285
1|2|3|4|5|6|7|8|9|10)
286
# Stop/start daemons for the appropriate priority level
293
# Stop all daemons at level '0' or 'stop'
295
if [ "$2" != "watchquagga" ]; then
299
if [ -z "$2" -o "$2" = "zebra" ]; then
300
echo "Removing all routes made by zebra."
301
ip route flush proto zebra
305
restart|force-reload)
313
for i in /var/run/quagga/*.pid; do
316
running="$running $d"
325
echo "Usage: /etc/init.d/quagga {start|stop|restart|force-reload|<priority>} [daemon]"
326
echo " E.g. '/etc/init.d/quagga 5' would start all daemons with a prio 1-5."
327
echo " Read /usr/share/doc/quagga/README.Debian for details."