summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2008-02-20 18:19:08 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2008-02-20 18:19:08 -0800
commitea2f6c3e233d30e4ee37fa74a0d027c7478a1943 (patch)
tree751669b5e9fa72c5bee4d55957cbdb61830902fe
parenta77ffd90c19a203b5d0ebcc413c9f8f5b3b86a04 (diff)
downloadvyatta-cfg-ea2f6c3e233d30e4ee37fa74a0d027c7478a1943.tar.gz
vyatta-cfg-ea2f6c3e233d30e4ee37fa74a0d027c7478a1943.zip
add vyatta-cfg-cmd-wrapper to replace xorp_tmpl_tool.
-rw-r--r--Makefile.am2
-rwxr-xr-xscripts/vyatta-cfg-cmd-wrapper65
-rwxr-xr-xscripts/vyatta-config-loader.pl43
-rwxr-xr-xscripts/xorp_tmpl_tool162
4 files changed, 102 insertions, 170 deletions
diff --git a/Makefile.am b/Makefile.am
index 9e55aa1..5d41b2d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,7 +31,7 @@ src_my_delete_SOURCES = src/delete.c
src_my_set_SOURCES = src/set.c
src_check_tmpl_SOURCES = src/check_tmpl.c
-sbin_SCRIPTS = scripts/xorp_tmpl_tool
+sbin_SCRIPTS = scripts/vyatta-cfg-cmd-wrapper
sbin_SCRIPTS += scripts/vyatta-validate-type.pl
sbin_SCRIPTS += scripts/vyatta-find-type.pl
sbin_SCRIPTS += scripts/vyatta-config-loader.pl
diff --git a/scripts/vyatta-cfg-cmd-wrapper b/scripts/vyatta-cfg-cmd-wrapper
new file mode 100755
index 0000000..4a42105
--- /dev/null
+++ b/scripts/vyatta-cfg-cmd-wrapper
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+if grep -q union=aufs /proc/cmdline || grep -q aufs /proc/filesystems ; then
+ export UNIONFS=aufs
+else
+ export UNIONFS=unionfs
+fi
+
+UMASK_SAVE=`umask`
+umask 0002
+
+export VYATTA_EDIT_LEVEL=/;
+export VYATTA_TEMPLATE_LEVEL=/;
+export VYATTA_ACTIVE_CONFIGURATION_DIR=/opt/vyatta/config/active;
+
+export VYATTA_CHANGES_ONLY_DIR=/opt/vyatta/config/tmp/changes_only_$PPID;
+export VYATTA_TEMP_CONFIG_DIR=/opt/vyatta/config/tmp/new_config_$PPID;
+export VYATTA_CONFIG_TMP=/opt/vyatta/config/tmp/tmp_$PPID;
+
+RET_STATUS=0
+
+case "$1" in
+ begin)
+ # set up the environment/directories
+ mkdir -p $VYATTA_ACTIVE_CONFIGURATION_DIR
+ mkdir -p $VYATTA_CHANGES_ONLY_DIR
+ if [ ! -d $VYATTA_TEMP_CONFIG_DIR ]; then
+ mkdir -p $VYATTA_TEMP_CONFIG_DIR
+ sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:${VYATTA_ACTIVE_CONFIGURATION_DIR}=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR}
+ fi
+ mkdir -p $VYATTA_CONFIG_TMP
+ ;;
+ end)
+ # tear down the environment/directories
+ sudo umount ${VYATTA_TEMP_CONFIG_DIR}
+ rm -rf ${VYATTA_CHANGES_ONLY_DIR}
+ rm -rf ${VYATTA_CONFIG_TMP}
+ rm -rf ${VYATTA_TEMP_CONFIG_DIR}
+ ;;
+ cleanup)
+ sudo umount ${VYATTA_TEMP_CONFIG_DIR}
+ rm -rf $VYATTA_CHANGES_ONLY_DIR/* $VYATTA_CHANGES_ONLY_DIR/.modified
+ sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:${VYATTA_ACTIVE_CONFIGURATION_DIR}=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR}
+ ;;
+ set)
+ /opt/vyatta/sbin/my_set "${@:2}"
+ RET_STATUS=$?
+ ;;
+ delete)
+ /opt/vyatta/sbin/my_delete "${@:2}"
+ RET_STATUS=$?
+ ;;
+ commit)
+ /opt/vyatta/sbin/my_commit
+ RET_STATUS=$?
+ ;;
+ *)
+ echo "Invalid command \"$1\" for vyatta-cfg-cmd-wrapper"
+ RET_STATUS=1
+ ;;
+esac
+
+umask ${UMASK_SAVE}
+exit $RET_STATUS
+
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;
+
diff --git a/scripts/xorp_tmpl_tool b/scripts/xorp_tmpl_tool
deleted file mode 100755
index 014a53b..0000000
--- a/scripts/xorp_tmpl_tool
+++ /dev/null
@@ -1,162 +0,0 @@
-#!/bin/bash
-
-if grep -q union=aufs /proc/cmdline || grep -q aufs /proc/filesystems ; then
- export UNIONFS=aufs
-else
- export UNIONFS=unionfs
-fi
-
-UMASK_SAVE_G=`umask`
-umask 0111
-XORPLOGFILE=/tmp/xorp_tmpl_tool.log
-touch ${XORPLOGFILE}
-
-umask 0002
-
-#need to pass in value to change... as part of set command...
-## cli ENV_EDIT_LEVEL
-export VYATTA_EDIT_LEVEL=/;
-## cli ENV_TEMPLATE_LEVEL
-export VYATTA_TEMPLATE_LEVEL=/;
-
-## cli ENV_A_DIR
-export VYATTA_ACTIVE_CONFIGURATION_DIR=/opt/vyatta/config/active;
-mkdir -p $VYATTA_ACTIVE_CONFIGURATION_DIR
-
-#now need to grab the parent pid.
-## XXX eventually, we will use each session's bash shell pid for this.
-## however, for now, to interact with XORP we will rely on a global lock
-## instead of separate config dirs.
-#export VTID=$PPID
-export VTID=XORP
-
-# lock for XORP
-export XORP_LOCK="/opt/vyatta/config/active/.xorp.lck"
-
-## cli ENV_C_DIR
-export VYATTA_CHANGES_ONLY_DIR=/opt/vyatta/config/tmp/changes_only_$VTID;
-mkdir -p $VYATTA_CHANGES_ONLY_DIR
-
-## cli ENV_M_DIR
-export VYATTA_TEMP_CONFIG_DIR=/opt/vyatta/config/tmp/new_config_$VTID;
-if [ ! -d $VYATTA_TEMP_CONFIG_DIR ]
-then
- mkdir -p $VYATTA_TEMP_CONFIG_DIR
- sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR}
-fi
-
-## cli ENV_TMP_DIR
-export VYATTA_CONFIG_TMP=/opt/vyatta/config/tmp/tmp_$VTID;
-mkdir -p $VYATTA_CONFIG_TMP
-
-RET_STATUS=0
-#this needs to be the array string of commands, something like $[*] or whatever
-
-echo "Command: ${@}" | grep -v -i password >> ${XORPLOGFILE}
-
-#echo "ConfigDirectories BEFORE ========>>>>>>" >> ${XORPLOGFILE}
-#find /opt/vyatta/config -name "*" -print | grep interface >> ${XORPLOGFILE}
-#echo "<=========ConfigDirectories BEFORE" >> ${XORPLOGFILE}
-
-## for tracing command-line XRL calls.
-## 1 => info level
-## 2 => warning level
-#export CL_XRLTRACE=2
-
-UMASK_SAVE=`umask`
-umask 0111
-MYCMDERRLOGFILE=/tmp/my_cmd_err_${RANDOM}.log
-rm -rf ${MYCMDERRLOGFILE}
-umask ${UMASK_SAVE}
-
-case "$1" in
- set)
- /opt/vyatta/sbin/my_set "${@:2}" >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE}
- RET_STATUS=$?
- if [ $RET_STATUS != 0 ]; then
- rm -rf $XORP_LOCK >&/dev/null
- fi
- ;;
- delete)
- /opt/vyatta/sbin/my_delete "${@:2}" >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE}
- RET_STATUS=$?
- if [ $RET_STATUS != 0 ]; then
- rm -rf $XORP_LOCK >&/dev/null
- fi
- ;;
- commit)
- /opt/vyatta/sbin/my_commit >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE}
- RET_STATUS=$?
- rm -rf $XORP_LOCK >&/dev/null
- ;;
- test)
- "${@:2}"
- RET_STATUS=$?
- ;;
- cleanup)
-
- LOCKTRYCOUNTER=0
- LOCKTRYSTATUS=-1
-
- while [[ ${LOCKTRYCOUNTER} -lt 60 && ${LOCKTRYSTATUS} -ne 0 ]] ; do
-
- if mkdir $XORP_LOCK >&/dev/null ; then
- LOCKTRYSTATUS=0
- else
- LOCKTRYCOUNTER=`expr ${LOCKTRYCOUNTER} + 1`
- sleep 1;
- fi
- done
-
- if [ ${LOCKTRYCOUNTER} -ge 60 ] ; then
- echo "Cannot unlock configuration" >> ${MYCMDERRLOGFILE}
- rm -rf ${XORP_LOCK}
- mkdir $XORP_LOCK >&/dev/null
- fi
-
- sudo umount ${VYATTA_TEMP_CONFIG_DIR}
- sudo rm -rf $VYATTA_CHANGES_ONLY_DIR/* $VYATTA_CHANGES_ONLY_DIR/.modified
- sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR}
- RET_STATUS=0
- ;;
- end_loading)
- sudo umount ${VYATTA_TEMP_CONFIG_DIR}
- sudo rm -rf ${VYATTA_CHANGES_ONLY_DIR}
- sudo rm -rf ${VYATTA_CONFIG_TMP}
- sudo rm -rf ${VYATTA_TEMP_CONFIG_DIR}
- RET_STATUS=0
- ;;
- rtrmgr_indirect_cleanup)
- # do nothing now that we handle XORP interaction differently.
- RET_STATUS=0
- ;;
- *)
- rm -rf ${MYCMDERRLOGFILE}
- exit 1
- ;;
-esac
-
-if [ -f ${MYCMDERRLOGFILE} ] ; then
-
- echo -n "STDERR:" >>${XORPLOGFILE}
- cat ${MYCMDERRLOGFILE} >>${XORPLOGFILE}
- echo "end of STDERR" >>${XORPLOGFILE}
-
- cat ${MYCMDERRLOGFILE} 1>&2
-
- rm -rf ${MYCMDERRLOGFILE}
-
-fi
-
-#echo "ConfigDirectories AFTER ========>>>>>>" >> ${XORPLOGFILE}
-#find /opt/vyatta/config -name "*" -print | grep interface >> ${XORPLOGFILE}
-#echo "<=========ConfigDirectories AFTER" >> ${XORPLOGFILE}
-
-echo "ret=${RET_STATUS}" >> ${XORPLOGFILE}
-umask ${UMASK_SAVE_G}
-exit $RET_STATUS
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 4
-# End: