diff options
author | Bob Gilligan <gilligan@vyatta.com> | 2008-02-26 16:52:11 -0800 |
---|---|---|
committer | Bob Gilligan <gilligan@vyatta.com> | 2008-02-26 16:52:11 -0800 |
commit | f9ee85510c958f07191cdbb7c3f57f2cf226a6d3 (patch) | |
tree | 47f55dc322dcaa83f3bdb2fd5caa2388e8ff4b8b /scripts/vyatta-config-loader.pl | |
parent | 79eb089b0d3463823f0a1fba1376842e3eb8aa47 (diff) | |
parent | af75cfaa93b1ac933bb8b5ecec64fcc0c269a013 (diff) | |
download | vyatta-cfg-f9ee85510c958f07191cdbb7c3f57f2cf226a6d3.tar.gz vyatta-cfg-f9ee85510c958f07191cdbb7c3f57f2cf226a6d3.zip |
Merge branch 'glendale' of git:/git/vyatta-cfg into glendale
Diffstat (limited to 'scripts/vyatta-config-loader.pl')
-rwxr-xr-x | scripts/vyatta-config-loader.pl | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl index 4c05b80..035d2af 100755 --- a/scripts/vyatta-config-loader.pl +++ b/scripts/vyatta-config-loader.pl @@ -8,16 +8,40 @@ use VyattaConfigLoad; umask 0002; +if (!open(OLDOUT, ">&STDOUT") || !open(OLDERR, ">&STDERR") + || !open(STDOUT, ">/var/log/config-boot.log") + || !open(STDERR, ">&STDOUT")) { + print STDERR "Cannot dup STDOUT/STDERR: $!\n"; + exit 1; +} + +sub restore_fds { + open(STDOUT, ">&OLDOUT"); + open(STDERR, ">&OLDERR"); +} + # get a list of all config statement in the startup config file # (sorted by rank). my @all_nodes = VyattaConfigLoad::getStartupConfigStatements($ARGV[0]); if (scalar(@all_nodes) == 0) { # no config statements + restore_fds(); exit 1; } my $cur_rank = ${$all_nodes[0]}[1]; -my $commit_cmd = '/opt/vyatta/sbin/xorp_tmpl_tool commit'; -my $cleanup_cmd = '/opt/vyatta/sbin/xorp_tmpl_tool cleanup'; + +# set up the config environment +my $CWRAPPER = '/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper'; +system("$CWRAPPER begin"); +if ($? >> 8) { + print OLDOUT "Cannot set up configuration environment\n"; + print STDOUT "Cannot set up configuration environment\n"; + restore_fds(); + exit 1; +} + +my $commit_cmd = "$CWRAPPER commit"; +my $cleanup_cmd = "$CWRAPPER cleanup"; my $ret = 0; # higher-ranked statements committed before lower-ranked. foreach (@all_nodes) { @@ -26,28 +50,33 @@ foreach (@all_nodes) { # commit all nodes with the same rank together. $ret = system("$commit_cmd"); if ($ret >> 8) { - print STDERR "Commit failed at rank $cur_rank\n"; + print OLDOUT "Commit failed at rank $cur_rank\n"; + print STDOUT "Commit failed at rank $cur_rank\n"; system("$cleanup_cmd"); # continue after cleanup (or should we abort?) } $cur_rank = $rank; } - my $cmd = '/opt/vyatta/sbin/xorp_tmpl_tool set ' . (join ' ', @$path_ref); + my $cmd = "$CWRAPPER set " . (join ' ', @$path_ref); $ret = system("$cmd"); if ($ret >> 8) { $cmd =~ s/^.*?set /set /; - print STDERR "[[$cmd]] failed\n"; + print OLDOUT "[[$cmd]] failed\n"; + print STDOUT "[[$cmd]] failed\n"; # continue after set failure (or should we abort?) } } $ret = system("$commit_cmd"); if ($ret >> 8) { - print STDERR "Commit failed at rank $cur_rank\n"; + print OLDOUT "Commit failed at rank $cur_rank\n"; + print STDOUT "Commit failed at rank $cur_rank\n"; system("$cleanup_cmd"); # exit normally after cleanup (or should we exit with error?) } # really clean up -system('/opt/vyatta/sbin/xorp_tmpl_tool end_loading'); +system("$CWRAPPER end"); +restore_fds(); exit 0; + |