summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-28 14:15:05 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-01-28 14:15:05 -0800
commit2a7c3c212b83384636429c17f356f02e2aeb52c8 (patch)
tree5a6732f7e1c932c081e3ddd16ebd8a81f682d349
parent72fc4bcfd16e7760841b251c85b3779bd26d4943 (diff)
downloadvyatta-cfg-quagga-2a7c3c212b83384636429c17f356f02e2aeb52c8.tar.gz
vyatta-cfg-quagga-2a7c3c212b83384636429c17f356f02e2aeb52c8.zip
add new script for protocol restart
This is pre-release version of script to reload config.
-rwxr-xr-xscripts/vyatta-protocol-restart.pl107
1 files changed, 107 insertions, 0 deletions
diff --git a/scripts/vyatta-protocol-restart.pl b/scripts/vyatta-protocol-restart.pl
new file mode 100755
index 00000000..806fafef
--- /dev/null
+++ b/scripts/vyatta-protocol-restart.pl
@@ -0,0 +1,107 @@
+#! /usr/bin/perl
+#
+# Script used to restore protocol configuration
+
+use strict;
+use lib "/opt/vyatta/share/perl5";
+use Vyatta::ConfigOutput;
+use Vyatta::ConfigLoad;
+
+my $sbindir = $ENV{vyatta_sbindir};
+my $cfg = 'vyatta-cfg-cmd-wrapper';
+my $active_config_dir = "/opt/vyatta/config/active";
+
+sub usage {
+ die "Usage: $0 protocol\n", "protocol := bgp|ospf|rip|ripng\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 die "Can not open file '$file': $!\n";
+
+ 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 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);
+ 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 = @{$cmd_ref};
+
+ warn "Set failed: ", join(' '), @cmd
+ unless config( 'set', @{$cmd_ref} );
+ }
+
+ 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;
+
+my @nodes = $protomap{$proto};
+usage unless @nodes;
+
+$SIG{__DIE__} = \&cleanup;
+$SIG{TERM} = \&cleanup;
+
+# Step 0: lock out any new transactions
+config('begin');
+
+# Step 1: save current configuration
+my $save_file = "/tmp/$0-$proto.$$";
+my $save = save_config($save_file);
+
+# Step 2: remove old state
+clean_nodes(@nodes);
+
+# Step 3: reload
+seek $save, 0, 0;
+load_config($save);
+
+config('end');
+
+close $save;
+## unlink $save_file;
+