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 # Print the name of the pidfile.
28 echo "/var/run/quagga/$1.pid"
31 # Check if daemon is started by using the pidfile.
34 [ -e `pidfile $1` ] && kill -0 `cat \`pidfile
$1\
`` 2> /dev
/null
&& return 0
38 # Loads the config via vtysh -b if configured to do so.
41 # Rember, that all variables have been incremented by 1 in convert_daemon_prios()
42 if [ "$vtysh_enable" = 2 -a -f $C_PATH/Quagga.conf
]; then
47 # Check if the daemon is activated and if its executable and config files
50 # returns: 0=ok, 1=error
53 # If the integrated config file is used the others are not checked.
54 if [ -r "$C_PATH/Quagga.conf" ]; then
58 # vtysh_enable has no config file nor binary so skip check.
59 # (Not sure why vtysh_enable is in this list but does not hurt)
60 if [ $1 != "watchquagga" -a $1 != "vtysh_enable" ]; then
61 # check for daemon binary
62 if [ ! -x "$D_PATH/$1" ]; then return 1; fi
64 # check for config file
65 if [ ! -r "$C_PATH/$1.conf" ]; then
66 echo -n " (not started without config file)"
73 # Starts the server if it's not alrady running according to the pid file.
74 # The Quagga daemons creates the pidfile when starting.
78 if ! check_daemon
$1; then return; fi
80 if [ "$1" = "watchquagga" ]; then
83 --pidfile=`pidfile $1` \
86 "${watchquagga_options[@]}"
90 --pidfile=`pidfile $1` \
93 `eval echo "$""$1""_options"`
97 # Stop the daemon given in the parameter, printing its name to the terminal.
100 if ! started
"$1" ; then
105 PID
=`cat $PIDFILE 2>/dev/null`
106 start-stop-daemon
--stop --quiet --oknodo --exec "$D_PATH/$1"
108 # Now we have to wait until $DAEMON has _really_ stopped.
110 if test -n "$PID" && kill -0 $PID 2>/dev
/null
; then
111 echo -n " (waiting) ."
113 while kill -0 $PID 2>/dev
/null
; do
115 if [ $cnt -gt 60 ]; then
116 # Waited 120 secs now, fail.
129 # Converts values from /etc/quagga/daemons to all-numeric values.
130 convert_daemon_prios
()
132 for name
in $DAEMONS zebra vtysh_enable watchquagga_enable
; do
133 # First, assign the value set by the user to $value
136 # Daemon not activated or entry missing?
137 if [ "$value" = "no" -o "$value" = "" ]; then value
=0; fi
139 # These strings parsed for backwards compatibility.
140 if [ "$value" = "yes" -o "$value" = "true" ]; then value
=1; fi
142 # Zebra is threatened special. It must be between 0=off and the first
143 # user assigned value "1" so we increase all other enabled daemons' values.
144 if [ "$name" != "zebra" -a "$value" -gt 0 ]; then value
=`expr "$value" + 1`; fi
146 # If e.g. name is zebra then we set "zebra=yes".
151 # Starts watchquagga for all wanted daemons.
158 # Start the monitor daemon only if desired.
159 if [ 0 -eq "$watchquagga_enable" ]; then
163 # Check variable type
164 if ! declare -p watchquagga_options |
grep -q '^declare \-a'; then
166 echo "ERROR: The variable watchquagga_options from /etc/quagga/debian.cnf must be a BASH array!"
167 echo "ERROR: Please convert config file and restart!"
171 # Which daemons have been started?
173 for daemon_name
in $DAEMONS; do
174 eval daemon_prio
=\$
$daemon_name
175 if [ "$daemon_prio" -gt 0 ]; then
176 watchquagga_options
+=($daemon_name)
181 # Start if at least one daemon is activated.
182 if [ $found_one -eq 1 ]; then
183 echo -n "Starting Quagga monitor daemon:"
189 # Stopps watchquagga.
192 echo -n "Stopping Quagga monitor daemon:"
197 # Stops all daemons that have a lower level of priority than the given.
198 # (technically if daemon_prio >= wanted_prio)
206 daemon_list
=${2:-$DAEMONS}
208 echo -n "Stopping Quagga daemons (prio:$wanted_prio):"
210 for prio_i
in `seq 10 -1 $wanted_prio`; do
211 for daemon_name
in $daemon_list; do
212 eval daemon_prio
=\$
$daemon_name
213 if [ $daemon_prio -eq $prio_i ]; then
221 # Starts all daemons that have a higher level of priority than the given.
222 # (technically if daemon_prio <= wanted_prio)
230 daemon_list
=${2:-$DAEMONS}
232 echo -n "Starting Quagga daemons (prio:$wanted_prio):"
234 for prio_i
in `seq 1 $wanted_prio`; do
235 for daemon_name
in $daemon_list; do
236 eval daemon_prio
=\$
$daemon_name
237 if [ $daemon_prio -eq $prio_i ]; then
245 #########################################################
247 #########################################################
249 # Config broken but script must exit silently.
250 [ ! -r "$C_PATH/daemons" ] && exit 0
254 .
"$C_PATH/debian.conf"
256 # Set priority of un-startable daemons to 'no' and substitute 'yes' to '0'
259 if [ ! -d /var
/run
/quagga
]; then
260 mkdir
-p /var
/run
/quagga
261 chown quagga
:quagga
/var
/run
/quagga
262 chmod 755 /var
/run
/quagga
267 # Try to load this necessary (at least for 2.6) module.
268 if [ -d /lib
/modules
/`uname -r` ] ; then
269 echo "Loading capability module if not yet done."
270 set +e
; LC_ALL
=C modprobe
-a capability
2>&1 |
egrep -v "(not found|Can't locate)"; set -e
275 if [ "$2" != "watchquagga" ]; then
282 1|
2|
3|
4|
5|
6|
7|
8|
9|
10)
283 # Stop/start daemons for the appropriate priority level
290 # Stop all daemons at level '0' or 'stop'
292 if [ "$2" != "watchquagga" ]; then
296 if [ -z "$2" -o "$2" = "zebra" ]; then
297 echo "Removing all routes made by zebra."
298 ip route flush proto zebra
302 restart|force-reload
)
309 echo "Usage: /etc/init.d/quagga {start|stop|restart|force-reload|<priority>} [daemon]"
310 echo " E.g. '/etc/init.d/quagga 5' would start all daemons with a prio 1-5."
311 echo " Read /usr/share/doc/quagga/README.Debian for details."