diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-02-18 12:54:35 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-02-18 15:40:25 -0800 |
commit | 358846aef34e08817dbc7d7eefcffb2f075f786b (patch) | |
tree | 6ef2c5a65fcaec19ea6035efadccd1390b732e7d | |
parent | 5205f4cd0d68a78c86fce6588f9c276861bb9cdd (diff) | |
download | vyatta-cfg-quagga-358846aef34e08817dbc7d7eefcffb2f075f786b.tar.gz vyatta-cfg-quagga-358846aef34e08817dbc7d7eefcffb2f075f786b.zip |
Rework of protocol startup
Use scripts to do start/stop (instead of disable template).
Integrate reload into new quagga-manager script
-rw-r--r-- | Makefile.am | 5 | ||||
-rwxr-xr-x | scripts/quagga-manager | 130 | ||||
-rwxr-xr-x | scripts/vyatta-protocol | 66 | ||||
-rwxr-xr-x | scripts/vyatta-reload-proto-config | 66 | ||||
-rwxr-xr-x | scripts/vyatta-show-protocols | 51 | ||||
-rw-r--r-- | templates/protocols/bgp/node.def | 7 | ||||
-rw-r--r-- | templates/protocols/ospf/disable/node.def | 12 | ||||
-rw-r--r-- | templates/protocols/ospf/node.def | 2 | ||||
-rw-r--r-- | templates/protocols/rip/disable/node.def | 12 | ||||
-rw-r--r-- | templates/protocols/rip/node.def | 2 | ||||
-rw-r--r-- | templates/protocols/ripng/disable/node.def | 12 | ||||
-rw-r--r-- | templates/protocols/ripng/node.def | 2 |
12 files changed, 194 insertions, 173 deletions
diff --git a/Makefile.am b/Makefile.am index efcd5fe8..acff766f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,8 @@ cfgdir = $(datadir)/vyatta-cfg/templates curverdir = $(sysconfdir)/config-migrate/current +bin_SCRIPTS = scripts/vyatta-show-protocols + sbin_SCRIPTS = scripts/bgp/vyatta-bgp.pl sbin_SCRIPTS += scripts/policy/vyatta-policy.pl sbin_SCRIPTS += scripts/vyatta_quagga_utils.pl @@ -8,8 +10,7 @@ sbin_SCRIPTS += scripts/policy/vyatta-check-as-prepend.pl sbin_SCRIPTS += scripts/vyatta-policy-action-verify.pl sbin_SCRIPTS += scripts/vyatta-gateway-static_route-check.pl sbin_SCRIPTS += scripts/vyatta-link-detect -sbin_SCRIPTS += scripts/vyatta-protocol -sbin_SCRIPTS += scripts/vyatta-reload-proto-config +sbin_SCRIPTS += scripts/quagga-manager sbin_PROGRAMS = src/check_prefix_boundary diff --git a/scripts/quagga-manager b/scripts/quagga-manager new file mode 100755 index 00000000..1e6e5f06 --- /dev/null +++ b/scripts/quagga-manager @@ -0,0 +1,130 @@ +#! /bin/bash +# +# This is special script for start,stop,restart of quagga daemons +# + +progname=$0 +usage() { + echo "Usage: $progname {start|stop|restart} {bgpd|ospfd|ripd|ripngd}" + exit 1 +} + +if [ $# -lt 1 ]; then + usage +fi + +if [ $EUID -ne 0 ]; then + echo "must be root!" + exit 1 +fi + +pid_dir=/var/run/vyatta/quagga +log_dir=/var/log/vyatta/quagga + +start() { + local daemon=$1 + local exe_file=/usr/sbin/vyatta-$daemon + + if [ ! -x $exe_file ]; then + echo "Unknown daemon $daemon" + exit 1 + fi + + local -a args=( -d -P 0 -i ${pid_dir}/${daemon}.pid ) + case $daemon in + zebra) args+=( -l -S -s 1048576 ) ;; + watchquagga) + args=( -dz -p ${pid_dir}/${daemon}.pid ); + local -a daemons=(`/opt/vyatta/bin/vyatta-show-protocols configured`) + if [ ${#daemons} -eq 0 ] + then + # Only zebra: mode 1 simple restart + args+=( -R "$0 zebra restart" ) + else + # Many daemons: phased restart + args+=(-A -r "$0 restart \%s" -s "$0 start \%s" -k "$0 stop \%s" ); + fi + args+=( zebra $daemons ) + ;; + esac + + start-stop-daemon --start --quiet \ + --chdir $log_dir --exec $exe_file \ + -- "${args[@]}" +} + +stop() { + local daemon=$1 + local exe_file=/usr/sbin/vyatta-$daemon + + start-stop-daemon --stop --quiet --oknodo --retry 2 \ + --exec $exe_file + rm -f $pid_dir/${daemon}.pid +} + +vyatta_cfg=/opt/vyatta/config/active +reload_config() { + local daemon=$1 + local proto=${daemon/%d/} + local path=$vyatta_cfg/protocols/$proto + + # No point in reloading if that portion of config doesn't exist + [ -d $path ] || return; + + # Begin reloading transaction + /opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin || exit 1 + + # In case of error undo + trap "/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end" EXIT HUP INT QUIT TERM + + # Save current configuration + tmp=/tmp/${daemon}-restart.$$ + /opt/vyatta/sbin/vyatta-save-config.pl $tmp || exit 1 + + # Erase portion of active configuration for that protocol + rm -fr $path + + # special case for interface configuration + case $proto in + rip|ospf) + find $vyatta_cfg/interfaces -type d -name $daemon -exec rm -fr '{}' \; ;; + esac + + # Reload causing configuration to activate - implies commit + /opt/vyatta/sbin/vyatta-load-config.pl $tmp || exit 1 + + # remove tmp file if successful + rm $tmp + trap "" EXIT HUP INT QUIT TERM +} + + +case "$1" in + start) start $2;; + stop) stop $2;; + + update) + deleted=`/opt/vyatta/bin/vyatta-show-protocols deleted` + added=`/opt/vyatta/bin/vyatta-show-protocols added` + + # nothing lost, nothing gained + [ -z "$deleted" -a -z "$added" ] && exit 0 + + stop watchquagga + for daemon in $deleted + do stop ${daemon} + done + + start watchquagga + ;; + + restart) + # Restart single daemon + stop $2 + start $2 + reload_config $2 + ;; + *) + usage;; +esac + diff --git a/scripts/vyatta-protocol b/scripts/vyatta-protocol deleted file mode 100755 index 65ee3d76..00000000 --- a/scripts/vyatta-protocol +++ /dev/null @@ -1,66 +0,0 @@ -#! /bin/bash -# -# This is special script for start,stop,restart of quagga daemons -# -progname=$0 -usage() { - echo "Usage: $progname {start|stop|restart} {bgpd|ospfd|ripd|ripngd}" - exit 1 -} - -if [ $# -lt 2 ]; then - usage -fi - - -daemon=$2 -exe_file=/usr/sbin/vyatta-$daemon - -pid_dir=/var/run/vyatta/quagga -pid_file=$pid_dir/${daemon}.pid -log_dir=/var/log/vyatta/quagga - -if [ ! -x $exe_file ]; then - echo "Unknown daemon $daemon" - exit 1 -fi - -if [ $EUID -ne 0 ]; then - echo "must be root!" - exit 1 -fi - -case "$1" in - start) - start-stop-daemon --start --quiet \ - --chdir $log_dir --exec $exe_file \ - -- -d -P 0 -i $pid_dir/${daemon}.pid - start-stop-daemon --start --quiet \ - --chdir $log_dir \ - --exec /usr/sbin/vyatta-watchquagga \ - -- -p $pid_dir/watch-${daemon}.pid \ - -dz -r "$0 restart %s" $daemon - ;; - - stop) - start-stop-daemon --stop --quiet --oknodo --retry 2 \ - --pidfile $pid_dir/watch-${daemon}.pid - rm -f $pid_dir/watch-${daemon}.pid - start-stop-daemon --stop --quiet --oknodo --retry 2 \ - --exec $exe_file - rm -f $pid_dir/${daemon}.pid - ;; - - restart) - # Restart daemon - start-stop-daemon --stop --quiet --oknodo --exec $exe_file - start-stop-daemon --start --quiet \ - --chdir $log_dir --exec $exe_file \ - -- -d -P 0 -i $pid_dir/${daemon}.pid - - sudo /opt/vyatta/sbin/vyatta-reload-proto-config ${daemon/%d/} - ;; - *) - usage;; -esac - diff --git a/scripts/vyatta-reload-proto-config b/scripts/vyatta-reload-proto-config deleted file mode 100755 index 7fa75cc4..00000000 --- a/scripts/vyatta-reload-proto-config +++ /dev/null @@ -1,66 +0,0 @@ -#! /bin/bash -# Author: Stephen Hemminger -# Date: 2009 -# Description: reload portion of configuration - -# **** License **** -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc. -# All Rights Reserved. -# **** End License **** - -if [ $# -eq 0 ]; then - echo "Usage: $0 {bgp|ospf|rip|ripng}" - exit 1 -fi - -if [ $EUID -ne 0 ]; then - echo "Must be root" - exit 1 -fi - -vyatta_cfg=/opt/vyatta/config/active -daemon=$1 -path=$vyatta_cfg/protocols/$daemon - -# No point in reloading if that portion of config doesn't exist -if [ ! -d $path ]; then - echo "$path does not exist" - exit 1 -fi - -# Begin reloading transaction -/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin || exit 1 - -# In case of error undo -trap "/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end" EXIT HUP INT QUIT TERM - -# Save current configuration -tmp=/tmp/${daemon}-restart.$$ -/opt/vyatta/sbin/vyatta-save-config.pl $tmp || exit 1 - -# Erase portion of active configuration for that protocol -rm -fr $path - -# special case for interface configuration -case $daemon in - rip|ospf) find $vyatta_cfg/interfaces -type d -name $daemon \ - -exec rm -fr '{}' \; - ;; -esac - -# Reload causing configuration to activate - implies commit -/opt/vyatta/sbin/vyatta-load-config.pl $tmp || exit 1 - -# remove tmp file if successful -rm $tmp - diff --git a/scripts/vyatta-show-protocols b/scripts/vyatta-show-protocols new file mode 100755 index 00000000..c81dcb82 --- /dev/null +++ b/scripts/vyatta-show-protocols @@ -0,0 +1,51 @@ +#! /usr/bin/perl +# Author: Stephen Hemminger +# Date: 2009 +# Description: Helper script to display configured protocols + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc. +# All Rights Reserved. +# **** End License **** + +use lib "/opt/vyatta/share/perl5"; +use Vyatta::Config; +use strict; +use warnings; + +# Map from command line to config->XXX() function +my %actions = ( + 'configured' => 'exists', + 'added' => 'isAdded', + 'changed' => 'isChanged', + 'deleted' => 'isDeleted', +); + +my @protocols = qw(bgp isis ospf ospf6 rip ripng); + +sub usage { + die "Usage: $0 {",join('|',keys %actions),"}\n" +} + +usage if ($#ARGV == -1); +my $match = $actions{$ARGV[0]}; +usage unless $match; + +my $config = new Vyatta::Config; +$config->setLevel('protocols'); + +# Avoid the urge to do Perl Golf here... +my @found = grep { $config->$match($_) } @protocols; +my @daemons = map { $_ . 'd' } @found; +print join(' ', @daemons), "\n"; + diff --git a/templates/protocols/bgp/node.def b/templates/protocols/bgp/node.def index 520da78f..1c56426e 100644 --- a/templates/protocols/bgp/node.def +++ b/templates/protocols/bgp/node.def @@ -4,8 +4,9 @@ help: Configure Border Gateway Protocol (BGP) parameters comp_help: \1 <1-4294967294>\tAS number syntax:expression: $VAR(@) >= 1 && $VAR(@) <= 4294967294 ; \ "AS number must be between 1 and 4294967294" - +begin: sudo /opt/vyatta/sbin/quagga-manager start bgpd +create: vyatta-vtysh -c "configure terminal" -c "router bgp $VAR(@)" update: vyatta-vtysh -c "configure terminal" -c "router bgp $VAR(@)" \ -c "bgp network import-check" - - +delete: vyatta-vtysh -c "configure terminal" -c "no router bgp $VAR(@)" +end: sudo /opt/vyatta/sbin/quagga-manager update diff --git a/templates/protocols/ospf/disable/node.def b/templates/protocols/ospf/disable/node.def deleted file mode 100644 index eeccb9a1..00000000 --- a/templates/protocols/ospf/disable/node.def +++ /dev/null @@ -1,12 +0,0 @@ -type: bool -help: Disable OSPF daemon -default: false -update: if [ $VAR(@) == "true" ]; - then sudo ${vyatta_sbindir}/vyatta-protocol stop ospfd - else sudo ${vyatta_sbindir}/vyatta-protocol start ospfd - fi -possible completions: - true Stop OSPF daemon - false Start OSPF daemon - -allowed: echo "true false" diff --git a/templates/protocols/ospf/node.def b/templates/protocols/ospf/node.def index b28f5553..731d39f1 100644 --- a/templates/protocols/ospf/node.def +++ b/templates/protocols/ospf/node.def @@ -1,3 +1,5 @@ help: Configure Open Shortest Path First protocol (OSPF) parameters +begin: sudo /opt/vyatta/sbin/quagga-manager start ospfd create: vyatta-vtysh -c "configure terminal" -c "router ospf" delete: vyatta-vtysh -c "configure terminal" -c "no router ospf" +end: sudo /opt/vyatta/sbin/quagga-manager update diff --git a/templates/protocols/rip/disable/node.def b/templates/protocols/rip/disable/node.def deleted file mode 100644 index 4cd56588..00000000 --- a/templates/protocols/rip/disable/node.def +++ /dev/null @@ -1,12 +0,0 @@ -type: bool -help: Disable RIP daemon -default: false -update: if [ $VAR(@) == "true" ]; - then sudo ${vyatta_sbindir}/vyatta-protocol stop ripd - else sudo ${vyatta_sbindir}/vyatta-protocol start ripd - fi -possible completions: - true Stop RIP daemon - false Start RIP daemon - -allowed: echo "true false" diff --git a/templates/protocols/rip/node.def b/templates/protocols/rip/node.def index 541baa8d..b7f085a5 100644 --- a/templates/protocols/rip/node.def +++ b/templates/protocols/rip/node.def @@ -1,3 +1,5 @@ help: Configure Routing Information Protocol (RIP) parameters +begin: sudo /opt/vyatta/sbin/quagga-manager start ripd create: vyatta-vtysh -c "configure terminal" -c "router rip" delete: vyatta-vtysh -c "configure terminal" -c "no router rip" +end: sudo /opt/vyatta/sbin/quagga-manager update diff --git a/templates/protocols/ripng/disable/node.def b/templates/protocols/ripng/disable/node.def deleted file mode 100644 index d23c9c5f..00000000 --- a/templates/protocols/ripng/disable/node.def +++ /dev/null @@ -1,12 +0,0 @@ -type: bool -help: Disable RIPng daemon -default: false -update: if [ $VAR(@) == "true" ]; - then sudo ${vyatta_sbindir}/vyatta-protocol stop ripngd - else sudo ${vyatta_sbindir}/vyatta-protocol start ripngd - fi -possible completions: - true Stop RIPng daemon - false Start RIPng daemon - -allowed: echo "true false" diff --git a/templates/protocols/ripng/node.def b/templates/protocols/ripng/node.def index 61c30b01..a4c4c9d4 100644 --- a/templates/protocols/ripng/node.def +++ b/templates/protocols/ripng/node.def @@ -1,3 +1,5 @@ help: Configure Routing Information Protocol (RIPng) parameters +begin: sudo /opt/vyatta/sbin/quagga-manager start ripngd create: vyatta-vtysh -c "configure terminal" -c "router ripng" delete: vyatta-vtysh -c "configure terminal" -c "no router ripng" +end: sudo /opt/vyatta/sbin/quagga-manager update |