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 /scripts | |
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
Diffstat (limited to 'scripts')
-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 |
4 files changed, 181 insertions, 132 deletions
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"; + |