summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-02-04 13:58:41 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-02-04 15:13:44 -0800
commit7158009fa019bb9eb5b871750e3658590b3a122f (patch)
treeb14de3ba75a42a218bf9e768bf229cc3992604c3 /scripts
parentde5866ef8e4c4249448a9e0d962f3f957c954ccd (diff)
downloadvyatta-cfg-quagga-7158009fa019bb9eb5b871750e3658590b3a122f.tar.gz
vyatta-cfg-quagga-7158009fa019bb9eb5b871750e3658590b3a122f.zip
Protocol daemon management
Bug 3828 Start protocols from configuration system, and use watchquagga to restart protocol daemons after failure
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vyatta-protocol74
-rwxr-xr-xscripts/vyatta-protocol-restart.pl127
2 files changed, 74 insertions, 127 deletions
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;
-