diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rwxr-xr-x | scripts/vyatta-protocol | 74 | ||||
-rwxr-xr-x | scripts/vyatta-protocol-restart.pl | 127 | ||||
-rw-r--r-- | templates/protocols/bgp/node.def | 15 | ||||
-rw-r--r-- | templates/protocols/ospf/node.def | 8 | ||||
-rw-r--r-- | templates/protocols/rip/node.def | 7 | ||||
-rw-r--r-- | templates/protocols/ripng/node.def | 10 |
7 files changed, 98 insertions, 144 deletions
diff --git a/Makefile.am b/Makefile.am index d0dd7885..1ecac150 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,6 +8,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_PROGRAMS = src/check_prefix_boundary diff --git a/scripts/vyatta-protocol b/scripts/vyatta-protocol new file mode 100755 index 00000000..2d4ba430 --- /dev/null +++ b/scripts/vyatta-protocol @@ -0,0 +1,74 @@ +#! /bin/bash +# +# This is special script for start,stop,restart of quagga daemons +# +progname=$0 +usage() { + echo "Usage: $progname {start|stop|reload} {bgp|ospf|rip|ripng}" + exit 1; +} + +if [ $# -lt 2 ]; then + usage +fi + +protocol=$2 +daemon=${protocol}d +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 protocol: $protocol"; + exit 1; +fi + +case "$1" in + start) + echo -n "Starting $protocol..." + sudo start-stop-daemon --start --quiet \ + --chdir $log_dir \ + --exec $exe_file \ + -- -d -P 0 -i $pid_dir/${daemon}.pid + sudo start-stop-daemon --start --quiet \ + --chdir $log_dir \ + --pidfile $pid_dir/watch-${daemon}.pid \ + --exec /usr/sbin/vyatta-watchquagga \ + -- -dz -R "/opt/vyatta/sbin/vyatta-quagga reload $protocol" $daemon + echo "done." + ;; + + stop) + echo -n "Stopping $protocol..." + sudo start-stop-daemon --stop --quiet --oknodo --retry 2 \ + --pidfile $pid_dir/watch-${daemon}.pid + sudo start-stop-daemon --stop --quiet --oknodo --retry 2 \ + --exec $exe_file + echo "done." + ;; + + reload) + echo -n "Reloading $1..." + # Start new transaction + /opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin + + # In case of error undo + trap "/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end" EXIT HUP INT QUIT TERM + + # Save current configuration + tmp=/tmp/${protocol}-restart.$$ + /opt/vyatta/sbin/vyatta-save-config.pl $tmp + + # Erase active configuration for that protocol + rm -fr /opt/vyatta/config/active/protocols/$protocol + + # Reload causing configuration to activate - implies commit + /opt/vyatta/sbin/vyatta-load-config.pl $TMP + echo "done." + ;; + *) + usage;; +esac + diff --git a/scripts/vyatta-protocol-restart.pl b/scripts/vyatta-protocol-restart.pl deleted file mode 100755 index 5b77b76e..00000000 --- a/scripts/vyatta-protocol-restart.pl +++ /dev/null @@ -1,127 +0,0 @@ -#! /usr/bin/perl -# -# **** 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. -# -# A copy of the GNU General Public License is available as -# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution -# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. -# You can also obtain it by writing to the Free Software Foundation, -# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, -# MA 02110-1301, USA. -# -# This code was originally developed by Vyatta, Inc. -# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc. -# All Rights Reserved. -# **** End License **** -# -# Author: Stephen Hemminger -# Date: January 2009 -# Description: Script used to restore protocol configuration on quagga daemon -# restart -# -# Not meant to be run directly, it is wrapped inside another script -# that sets up transaction - -use strict; -use warnings; -use lib "/opt/vyatta/share/perl5/"; -use Vyatta::ConfigOutput; -use Vyatta::ConfigLoad; - -my $sbindir = '/opt/vyatta/sbin'; -my $active_config_dir = "/opt/vyatta/config/active"; - -my %protomap = ( - 'bgp' => ['protocols/bpp'], - 'ospf' => [ 'protocols/ospf', 'interfaces/*/*/ip/ospf' ], - 'rip' => [ 'protocols/rip', 'interfaces/*/*/ip/rip' ], -); - -sub usage { - die "Usage: $0 {",join('|',keys %protomap),"}\n"; -} - -sub save_config { - my $file = shift; - my $version_str = `/opt/vyatta/sbin/vyatta_current_conf_ver.pl`; - die "no version string??" unless $version_str; - - open my $save, '+>', $file - or return; #undef - - select $save; - set_show_all(1); - outputActiveConfig(); - print $version_str; - select STDOUT; - print "created $file\n"; - - return $save; -} - -sub clean_nodes { - foreach my $path (@_) { - system("rm -rf $active_config_dir/$path"); - } -} - -sub load_config { - my $file = shift; - my %cfg_hier = Vyatta::ConfigLoad::loadConfigHierarchy($file); - die "Saved configuration was bad can't reload" - unless %cfg_hier; - - my %cfg_diff = Vyatta::ConfigLoad::getConfigDiff( \%cfg_hier ); - - # Only doing sets - foreach ( @{ $cfg_diff{'set'} } ) { - my ( $cmd_ref, $rank ) = @{$_}; - my @cmd = ( "my_set", @{$cmd_ref} ); - - system "$sbindir/my_set", @cmd == 0 - or warn join(' '), @cmd; - } -} - - -my $proto = shift @ARGV; -usage unless $proto; - -my @nodes = $protomap{$proto}; -usage unless @nodes; - -# set up the config environment -my $CWRAPPER = '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper'; -system ("$CWRAPPER begin") == 0 - or die "Cannot set up configuration environment\n"; - -# Step 1: save current configuration -my $save_file = "/tmp/$0-$proto.$$"; -my $save = save_config($save_file); -if (! defined $save) { - system "$CWRAPPER cleanup"; - die "Can not open file '$save_file': $!\n"; -} - -# Step 2: remove old state -clean_nodes(@nodes); - -# Step 3: reload -seek $save, 0, 0; -load_config($save); -close $save; - -# Step 4: finalize -system "$CWRAPPER commit" == 0 - or die "Reload failed: check $save_file\n"; - -unlink $save_file; - diff --git a/templates/protocols/bgp/node.def b/templates/protocols/bgp/node.def index 69c2daab..ef80d812 100644 --- a/templates/protocols/bgp/node.def +++ b/templates/protocols/bgp/node.def @@ -2,9 +2,14 @@ tag: type: u32 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" -update: vyatta-vtysh -c "configure terminal" -c "router bgp $VAR(@)" -# we need to set default parameters in BGP here since we can't do it in -# startup scripts as we don't know the AS number at that point -update: vyatta-vtysh -c "configure terminal" -c "router bgp $VAR(@)" -c "bgp network import-check" +syntax:expression: $VAR(@) >= 1 && $VAR(@) <= 4294967294 ; \ + "AS number must be between 1 and 4294967294" + +create: if [ $(pgrep -c -x vyatta-bgpd) -eq 0 ] + then /opt/vyatta/sbin/vyatta-protocol start bgp + fi + 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(@)" + diff --git a/templates/protocols/ospf/node.def b/templates/protocols/ospf/node.def index 7870a8cb..25ef78e3 100644 --- a/templates/protocols/ospf/node.def +++ b/templates/protocols/ospf/node.def @@ -1,5 +1,5 @@ help: Configure Open Shortest Path First protocol (OSPF) parameters -create:expression: "vyatta-vtysh -c \"configure terminal\" \ - -c \"router ospf\" " -delete:expression: "vyatta-vtysh -c \"configure terminal\" \ - -c \"no router ospf\" " +create: /opt/vyatta/sbin/vyatta-protocol start ospf + vyatta-vtysh -c "configure terminal" -c "router ospf" +delete: vyatta-vtysh -c "configure terminal" -c "no router ospf" + /opt/vyatta/sbin/vyatta-protocol stop ospf diff --git a/templates/protocols/rip/node.def b/templates/protocols/rip/node.def index 38d3da1a..f1a08cc5 100644 --- a/templates/protocols/rip/node.def +++ b/templates/protocols/rip/node.def @@ -1,4 +1,7 @@ help: Configure Routing Information Protocol (RIP) parameters -create:expression: "vyatta-vtysh -c \"configure terminal\" -c \"router rip\" " -delete:expression: "vyatta-vtysh -c \"configure terminal\" -c \"no router rip\" " +create: /opt/vyatta/sbin/vyatta-protocol start rip + vyatta-vtysh -c "configure terminal" -c "router rip" +delete: vyatta-vtysh -c "configure terminal" -c "no router rip" + /opt/vyatta/sbin/vyatta-protocol stop rip + diff --git a/templates/protocols/ripng/node.def b/templates/protocols/ripng/node.def index 77991f97..efe56ba3 100644 --- a/templates/protocols/ripng/node.def +++ b/templates/protocols/ripng/node.def @@ -1,7 +1,5 @@ help: Configure Routing Information Protocol (RIPng) parameters - -create: vyatta-vtysh -c "configure terminal" \ - -c "router ripng" - -delete: vyatta-vtysh -c "configure terminal" \ - -c "no router ripng" +create: /opt/vyatta/sbin/vyatta-protocol start ripng + vyatta-vtysh -c "configure terminal" -c "router ripng" +delete: vyatta-vtysh -c "configure terminal" -c "no router ripng" + /opt/vyatta/sbin/vyatta-protocol stop ripng |