summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-28 16:11:42 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-28 16:11:42 -0800
commit7333d21e1a93fa73cbb030839a7a97a82a76471a (patch)
treed76d4e9796431da094df862cfdad296ef5c8fd06 /scripts
parent7a77df35c757e214c1c8033f9a025e2c8098bcae (diff)
downloadvyatta-cfg-quagga-7333d21e1a93fa73cbb030839a7a97a82a76471a.tar.gz
vyatta-cfg-quagga-7333d21e1a93fa73cbb030839a7a97a82a76471a.zip
More work on protocol restart
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vyatta-protocol-restart.pl94
1 files changed, 57 insertions, 37 deletions
diff --git a/scripts/vyatta-protocol-restart.pl b/scripts/vyatta-protocol-restart.pl
index 806fafef..5b77b76e 100755
--- a/scripts/vyatta-protocol-restart.pl
+++ b/scripts/vyatta-protocol-restart.pl
@@ -1,18 +1,52 @@
#! /usr/bin/perl
#
-# Script used to restore protocol 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.
+#
+# 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 lib "/opt/vyatta/share/perl5";
+use warnings;
+use lib "/opt/vyatta/share/perl5/";
use Vyatta::ConfigOutput;
use Vyatta::ConfigLoad;
-my $sbindir = $ENV{vyatta_sbindir};
-my $cfg = 'vyatta-cfg-cmd-wrapper';
+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 protocol\n", "protocol := bgp|ospf|rip|ripng\n";
+ die "Usage: $0 {",join('|',keys %protomap),"}\n";
}
sub save_config {
@@ -21,7 +55,7 @@ sub save_config {
die "no version string??" unless $version_str;
open my $save, '+>', $file
- or die "Can not open file '$file': $!\n";
+ or return; #undef
select $save;
set_show_all(1);
@@ -39,17 +73,6 @@ sub clean_nodes {
}
}
-sub config {
- my @args = @_;
- push @args, $cfg;
- print join( ' ', @args ), "\n";
- return system "$sbindir/$cfg", @args == 0;
-}
-
-sub cleanup {
- config('cleanup');
-}
-
sub load_config {
my $file = shift;
my %cfg_hier = Vyatta::ConfigLoad::loadConfigHierarchy($file);
@@ -61,21 +84,13 @@ sub load_config {
# Only doing sets
foreach ( @{ $cfg_diff{'set'} } ) {
my ( $cmd_ref, $rank ) = @{$_};
- my @cmd = @{$cmd_ref};
-
- warn "Set failed: ", join(' '), @cmd
- unless config( 'set', @{$cmd_ref} );
+ my @cmd = ( "my_set", @{$cmd_ref} );
+
+ system "$sbindir/my_set", @cmd == 0
+ or warn join(' '), @cmd;
}
-
- die "Commit failed"
- unless config('commit');
}
-my %protomap = (
- 'bgp' => ['protocols/bpp'],
- 'ospf' => [ 'protocols/ospf', 'interfaces/*/*/ip/ospf' ],
- 'rip' => [ 'protocols/rip', 'interfaces/*/*/ip/rip' ],
-);
my $proto = shift @ARGV;
usage unless $proto;
@@ -83,15 +98,18 @@ usage unless $proto;
my @nodes = $protomap{$proto};
usage unless @nodes;
-$SIG{__DIE__} = \&cleanup;
-$SIG{TERM} = \&cleanup;
-
-# Step 0: lock out any new transactions
-config('begin');
+# 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);
@@ -99,9 +117,11 @@ clean_nodes(@nodes);
# Step 3: reload
seek $save, 0, 0;
load_config($save);
+close $save;
-config('end');
+# Step 4: finalize
+system "$CWRAPPER commit" == 0
+ or die "Reload failed: check $save_file\n";
-close $save;
-## unlink $save_file;
+unlink $save_file;