summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xetc/bash_completion.d/vyatta-cfg2
-rwxr-xr-xetc/init.d/vyatta-router34
-rwxr-xr-xscripts/vyatta-cfg-cmd-wrapper82
-rwxr-xr-xscripts/vyatta-config-loader.pl89
4 files changed, 101 insertions, 106 deletions
diff --git a/etc/bash_completion.d/vyatta-cfg b/etc/bash_completion.d/vyatta-cfg
index 110b563..32a5283 100755
--- a/etc/bash_completion.d/vyatta-cfg
+++ b/etc/bash_completion.d/vyatta-cfg
@@ -1,4 +1,4 @@
-#!/bin/bash
+# vyatta bash configuration mode completion
# **** License ****
# This program is free software; you can redistribute it and/or modify
diff --git a/etc/init.d/vyatta-router b/etc/init.d/vyatta-router
index 763471a..d77aa96 100755
--- a/etc/init.d/vyatta-router
+++ b/etc/init.d/vyatta-router
@@ -115,7 +115,6 @@ migrate_bootfile ()
# load the initial config
load_bootfile ()
{
- if [ -x $vyatta_sbindir/vyatta-config-loader.pl ]; then
log_progress_msg configure
(
if [ -f /etc/default/vyatta-load-boot ]; then
@@ -124,7 +123,7 @@ load_bootfile ()
fi
sg ${GROUP} -c "$vyatta_sbindir/vyatta-config-loader.pl $BOOTFILE"
)
- fi
+ log_end_msg $?
}
@@ -135,22 +134,7 @@ load_bootfile ()
cleanup_raid()
{
MD_MODULES='linear multipath raid0 raid1 raid456 raid5 raid6 raid10'
- rmmod $MD_MODULES > /tmp/vyatta_raid_cleanup_log 2>&1
-}
-
-#
-# Load the acpi_cpufreq kernel module, but only for certain processors.
-# Some Intel CPUs need to have it loaded in order to initialize
-# properly.
-#
-load_acpi_cpufreq()
-{
- manuf=`dmidecode -s system-manufacturer`
- prod=`dmidecode -s system-product-name`
- if [ "$manuf" = "Vyatta" -a "$prod" = "Series 2500" ]; then
- logger -t "$progname" -p user.notice "loading acpi_cpufreq module"
- modprobe acpi_cpufreq
- fi
+ rmmod $MD_MODULES > /tmp/vyatta_raid_cleanup.log 2>&1
}
#
@@ -216,19 +200,23 @@ start ()
for s in ${subinit[@]} ; do
if ! disabled $s; then
log_progress_msg $s
- ${vyatta_sbindir}/${s}.init start || (log_end_msg $? && return)
+ if ! ${vyatta_sbindir}/${s}.init start
+ then log_end_msg $?
+ exit 1
+ fi
fi
done
- disabled configure || load_bootfile
+ if ! disabled configure; then
+ load_bootfile
+ else
+ log_success_msg
+ fi
- load_acpi_cpufreq
cleanup_raid
telinit q
bind_mount_boot
chmod g-w,o-w /
-
- log_end_msg $?
}
stop()
diff --git a/scripts/vyatta-cfg-cmd-wrapper b/scripts/vyatta-cfg-cmd-wrapper
index 569b68f..a5db7d5 100755
--- a/scripts/vyatta-cfg-cmd-wrapper
+++ b/scripts/vyatta-cfg-cmd-wrapper
@@ -8,12 +8,12 @@
# 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.
@@ -33,71 +33,54 @@ SID=$PPID
if [ -n "$CMD_WRAPPER_SESSION_ID" ]; then
SID=$CMD_WRAPPER_SESSION_ID
fi
+
# set up the session environment (get it from the unified lib)
session_env=$(${vyatta_sbindir}/my_cli_shell_api getSessionEnv $SID)
eval "$session_env"
-RET_STATUS=0
-
case "$1" in
- begin)
- # set up the session
- ${vyatta_sbindir}/my_cli_shell_api setupSession
- RET_STATUS=$?
+ begin) # set up the session
+ exec ${vyatta_sbindir}/my_cli_shell_api setupSession
;;
- end)
- # tear down the session
- ${vyatta_sbindir}/my_cli_shell_api teardownSession
- RET_STATUS=$?
+ end) # tear down the session
+ exec ${vyatta_sbindir}/my_cli_shell_api teardownSession
;;
cleanup|discard)
- /opt/vyatta/sbin/my_discard
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/my_discard
;;
set)
- /opt/vyatta/sbin/my_set "${@:2}"
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/my_set "${@:2}"
;;
delete)
- /opt/vyatta/sbin/my_delete "${@:2}"
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/my_delete "${@:2}"
;;
deactivate)
- /opt/vyatta/sbin/my_deactivate "${@:2}"
- RET_STATUS=$?
- ;;
+ exec ${vyatta_sbindir}/my_deactivate "${@:2}"
+ ;;
activate)
- /opt/vyatta/sbin/my_activate "${@:2}"
- RET_STATUS=$?
- ;;
+ exec ${vyatta_sbindir}/my_activate "${@:2}"
+ ;;
show)
- ${vyatta_sbindir}/my_cli_shell_api showCfg
- RET_STATUS=$?
- ;;
+ exec ${vyatta_sbindir}/my_cli_shell_api showCfg
+ ;;
comment)
- /opt/vyatta/sbin/my_comment "${@:2}"
- RET_STATUS=$?
- ;;
+ exec ${vyatta_sbindir}/my_comment "${@:2}"
+ ;;
commit)
export COMMIT_VIA=cfg-cmd-wrapper
- # debug file /tmp/bar should be deleted before release
- /opt/vyatta/sbin/my_commit -a >> /tmp/bar
- /opt/vyatta/sbin/my_commit -s >> /tmp/bar
- /opt/vyatta/sbin/my_commit -e -d >> /tmp/bar
- RET_STATUS=$?
- unset COMMIT_VIA
+ ${vyatta_sbindir}/my_commit -a >> /tmp/vyatta-commit.log
+ ${vyatta_sbindir}/my_commit -s >> /tmp/vyatta-commit.log
+ ${vyatta_sbindir}/my_commit -e -d >> /tmp/vyatta-commit.log
+ exit 0
;;
commit_with_error)
- /opt/vyatta/sbin/my_commit
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/my_commit
;;
save)
- /opt/vyatta/sbin/vyatta-save-config.pl "${@:2}"
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/vyatta-save-config.pl "${@:2}"
;;
load)
- /opt/vyatta/sbin/vyatta-load-config.pl "${@:2}"
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/vyatta-load-config.pl "${@:2}"
;;
rule-rename)
# this option is to be used for renaming firewall and nat rules only
@@ -107,11 +90,9 @@ case "$1" in
# 2 3 4 5 6 7
# rule-rename nat rule $rule_num to rule $rename_rulenum
if [ "$2" == "firewall" ]; then
- /opt/vyatta/sbin/my_move firewall name "$3" rule "$5" to "$8"
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/my_move firewall name "$3" rule "$5" to "$8"
elif [ "$2" == "nat" ]; then
- /opt/vyatta/sbin/my_move service nat rule "$4" to "$7"
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/my_move service nat rule "$4" to "$7"
fi
;;
move)
@@ -119,14 +100,15 @@ case "$1" in
# e.g., "move interfaces ethernet eth2 vif 100 to 200"
# is similar to "edit interfaces ethernet eth2" plus
# "rename vif 100 to vif 200".
- /opt/vyatta/sbin/my_move "${@:2}"
- RET_STATUS=$?
+ exec ${vyatta_sbindir}/my_move "${@:2}"
;;
*)
echo "Invalid command \"$1\" for vyatta-cfg-cmd-wrapper"
- RET_STATUS=1
+ exit 1
;;
esac
-exit $RET_STATUS
+# Only get here if exec failed.
+echo "!!! Missing Vyatta shell infrastructure for $1 !!!!"
+exit 1
diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl
index 3213fcb..168a8ea 100755
--- a/scripts/vyatta-config-loader.pl
+++ b/scripts/vyatta-config-loader.pl
@@ -26,33 +26,50 @@ use strict;
use lib "/opt/vyatta/share/perl5/";
use Vyatta::ConfigLoad;
use Sys::Syslog qw(:standard :macros);
+use POSIX qw(strftime);
my $CWRAPPER = '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper';
-my $CONFIG_LOG = '/tmp/vyatta-config.log';
-my $COMMIT_CMD = "$CWRAPPER commit";
+my $CONFIG_LOG = '/tmp/vyatta-config-loader.log';
+my $COMMIT_CMD = "$CWRAPPER commit";
my $CLEANUP_CMD = "$CWRAPPER cleanup";
+my $BEGIN_CMD = "$CWRAPPER begin";
+my $END_CMD = "$CWRAPPER end";
umask 0002;
# Set up logging
openlog("config-loader", "nofail", LOG_LOCAL0);
+
+open (STDIN, '<', "/dev/null")
+ or die "Can't open /dev/null : $!";
open (STDOUT, '>>', $CONFIG_LOG)
- or die "Can not open $CONFIG_LOG : $!";
+ or die "Can't open $CONFIG_LOG : $!";
+open (STDERR, '>&STDOUT')
+ or die "Can't redirect stderr: $!";
+
+sub trace {
+ my $str = shift;
+
+ printf "%s %s\n", strftime("%F %T ", localtime), $str;
+}
# get a list of all config statement in the startup config file
my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true');
my @all_nodes = @{ $cfg_hier{'set'} };
# empty configuration?
-exit 1 if (scalar(@all_nodes) == 0);
+die "Empty configuration!\n"
+ if (scalar(@all_nodes) == 0);
# set up the config environment
-unless (system("$CWRAPPER begin") == 0) {
+unless (system($BEGIN_CMD) == 0) {
syslog(LOG_WARNING, "Cannot set up configuration environment");
- die "Cannot set up configuration environment";
+ die "Cannot set up configuration environment\n";
}
-my $fail = 0;
+my $start = time;
+trace "-- begin";
+
#cmd below is added to debug last set of command ordering
foreach (@all_nodes) {
my ($path_ref, $rank) = @$_;
@@ -64,7 +81,7 @@ foreach (@all_nodes) {
foreach my $rp (@pr[1..$#pr]) {
$ct++;
my $tmp_path = $rel_path . "/" . $rp;
- my $node_path = "/opt/vyatta/share/vyatta-cfg/templates/"
+ my $node_path = "/opt/vyatta/share/vyatta-cfg/templates/"
. $tmp_path . "/node.def";
last if ($rp eq '"');
@@ -83,50 +100,58 @@ foreach (@all_nodes) {
next;
}
- # Show all commands in log
- my $cmd = join ' ', @pr;
- printf "[%s]\n", $cmd;
+ my $cmd = 'set ' . join(' ', @pr);
- $cmd = "$CWRAPPER set " . $cmd;
- unless (system($cmd) == 0) {
- $cmd =~ s/^.*?set /set /;
- printf "[[%s] failed: %d\n", $cmd, $?;
+ # Show all commands in log
+ trace $cmd;
+ unless (system("$CWRAPPER $cmd") == 0) {
+ warn "*** %s failed: %d\n", $cmd, $?;
syslog(LOG_NOTICE, "[[%s]] failed", $cmd);
- ++$fail;
}
}
-warn "$fail failures (see $CONFIG_LOG)\n" if ($fail > 0);
+my $commit_start = time;
+trace "commit";
+syslog(LOG_INFO, "Configuration took %d seconds.", $commit_start - $start);
unless (system($COMMIT_CMD) == 0) {
- printf "commit failed: %d\n", $?;
- syslog (LOG_NOTICE, "Commit failed at boot");
- warn "Commit failed at boot\n";
+ warn "*** Commit failed: %d\n", $?;
+ syslog (LOG_WARNING, "Commit failed at boot");
+
system($CLEANUP_CMD);
+ system($END_CMD);
exit 1;
}
+my $commit_end = time;
+syslog(LOG_INFO, "Commit succeeded took %d seconds.",
+ $commit_end - $commit_start);
+
# Now process any deactivate nodes
my @deactivate_nodes = @{ $cfg_hier{'deactivate'} };
if (@deactivate_nodes) {
- $fail = 0;
-
- my $cmd = "$CWRAPPER deactivate " . $_;
- unless (system($cmd) == 0) {
- printf "[[%s] failed: %d\n", $cmd, $?;
- syslog(LOG_NOTICE, "[[%s]] failed", $cmd);
+ foreach (@deactivate_nodes) {
+ my $cmd = "deactivate " . $_;
+ trace $cmd;
+
+ unless (system("$CWRAPPER $cmd") == 0) {
+ warn "*** %s failed: %d\n", $cmd, $?;
+ syslog(LOG_WARNING, "[[%s]] failed", $cmd);
+ last;
+ }
}
- warn "$fail deactivate failures (see $CONFIG_LOG)\n" if ($fail > 0);
unless (system($COMMIT_CMD) == 0) {
- printf "deactivate commit failed: %d\n", $?;
+ warn "deactivate commit failed: %d\n", $?;
syslog(LOG_NOTICE, "Commit deactivate failed at boot");
- warn "Commit deactivate failed at boot\n";
system($CLEANUP_CMD);
}
}
-# really clean up
-exec "$CWRAPPER end"
- or die "exec of $CWRAPPER failed";
+unless (system($END_CMD) == 0) {
+ syslog(LOG_WARNING, "Cannot teardown configuration environment");
+ die "Cannot teardown configuration environment\n";
+}
+trace "done.";
+exit 0;