[Swift-commit] r7375 - trunk/bin

davidk at ci.uchicago.edu davidk at ci.uchicago.edu
Wed Dec 4 13:37:08 CST 2013


Author: davidk
Date: 2013-12-04 13:37:08 -0600 (Wed, 04 Dec 2013)
New Revision: 7375

Modified:
   trunk/bin/swift
   trunk/bin/swiftrun
Log:
Save stdout and stderr from swift into run directory as runNNN/swift.out
Better error handling


Modified: trunk/bin/swift
===================================================================
--- trunk/bin/swift	2013-12-04 18:03:34 UTC (rev 7374)
+++ trunk/bin/swift	2013-12-04 19:37:08 UTC (rev 7375)
@@ -11,6 +11,7 @@
 CYGWIN=
 CPDELIM=":"
 HEAPMAX=1024M
+SWIFTOUTLOG=""
 
 if echo `uname` | grep -i "cygwin"; then
 	CYGWIN="yes"
@@ -160,6 +161,9 @@
          CMDLINE=$( echo $CMDLINE | sed s@$cmd@@g )
       elif [[ "$cmd" == *--SWIFTRUNQUIT* ]]; then
          exit 1
+      elif [[ "$cmd" == *-swiftoutlog=* ]]; then
+         SWIFTOUTLOG=$( echo $cmd | cut -d'=' -f2 )
+         CMDLINE=$( echo $CMDLINE | sed s@$cmd@@g ) 
       fi
    done
 fi
@@ -172,7 +176,11 @@
     eval java ${OPTIONS} ${COG_OPTS} ${EXEC} ${CMDLINE}
     export CLASSPATH=$CLASSPATHSAVE
 else
-    eval java ${OPTIONS} ${COG_OPTS} -classpath ${LOCALCLASSPATH} ${EXEC} ${CMDLINE}
+    if [ -n "$SWIFTOUTLOG" ] && [ -w "$( dirname $SWIFTOUTLOG )" ]; then
+       eval java ${OPTIONS} ${COG_OPTS} -classpath ${LOCALCLASSPATH} ${EXEC} ${CMDLINE} 2>&1 | tee $SWIFTOUTLOG
+    else
+       eval java ${OPTIONS} ${COG_OPTS} -classpath ${LOCALCLASSPATH} ${EXEC} ${CMDLINE}
+   fi
 fi
 return_code=$?
 

Modified: trunk/bin/swiftrun
===================================================================
--- trunk/bin/swiftrun	2013-12-04 18:03:34 UTC (rev 7374)
+++ trunk/bin/swiftrun	2013-12-04 19:37:08 UTC (rev 7375)
@@ -76,7 +76,6 @@
 sub property_to_xml {
    my $key = $_[0];
    my $value = $_[1];
-
    my ( $site, $sitename, $namespace, $property ) = split(/\./, $key);
 
    # Allow exceptions for swift properties with dot separators (ie key=slurm.properties)
@@ -103,7 +102,7 @@
 # Write apps to file in tc.data format
 sub write_apps {
    my $app_filename = $_[0];
-   open( APP_FILE, ">$run_directory/$app_filename" ) || die "Unable to open $run_directory/$app_filename\n";
+   open( APP_FILE, ">$run_directory/$app_filename" ) || &swiftquit("Unable to open $run_directory/$app_filename");
    print APP_FILE "* * * INSTALLED INTEL32::LINUX null\n";
 
    # Find app definitions
@@ -131,7 +130,7 @@
 # Write properties to file
 sub write_properties {
    my $property_filename = $_[0];
-   open( PROPERTY_FILE, ">$run_directory/$property_filename" ) || die "Unable to open $run_directory/$property_filename\n";
+   open( PROPERTY_FILE, ">$run_directory/$property_filename" ) || &swiftquit("Unable to open $run_directory/$property_filename");
    while( my( $key, $value ) = each( %properties ) ) {
       # Ignore properties that start with app. or site.
       next if $key =~ /^\s*app./;
@@ -184,7 +183,7 @@
    my $site = $_[0];
    my $sitexmlfile = "$ENV{HOME}/.swift/service/$site/sites.xml";
    my @xml;
-   open(SXML, $sitexmlfile) || die "Unable to open $sitexmlfile: $!\n";
+   open(SXML, $sitexmlfile) || &swiftquit("Unable to open $sitexmlfile: $!\n");
    while(<SXML>) {
       if(m/^<\?xml|^<config|config>$/i){ next; }
          push(@xml, $_);
@@ -203,7 +202,7 @@
 # Write sites.xml to disk
 sub write_sites {
    my $filename = $_[0];
-   open(SITES, ">$run_directory/$filename") || die "Unable to open $run_directory/$filename\n";
+   open(SITES, ">$run_directory/$filename") || &swiftquit("Unable to open $run_directory/$filename");
    print SITES "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    print SITES "<config xmlns=\"http://www.ci.uchicago.edu/swift/SwiftSites\">\n";
 
@@ -262,7 +261,7 @@
 
 # Verify Swift is found in PATH
 my $swift_etc_directory = dirname(dirname(`which swift`)) . "/etc";
-if( ! -d $swift_etc_directory ) { die "Unable to find a valid Swift installation"; }
+if( ! -d $swift_etc_directory ) { &swiftquit("Unable to find a valid Swift installation"); }
 
 # Set the search order for properties
 &add_property_file("$swift_etc_directory/swift.properties");
@@ -272,7 +271,7 @@
 
 # Set property values
 foreach my $property_file(@property_files) {
-   open(PROPERTIES, $property_file) || die "Unable to open $property_file";
+   open(PROPERTIES, $property_file) || &swiftquit("Unable to open $property_file");
 
    while( <PROPERTIES> ) {
       chomp;
@@ -339,9 +338,10 @@
 }
 
 $run_directory = getcwd() . "/" . sprintf "run%03s", $run_number;
-mkdir($run_directory) || die "Unable to create run directory $run_directory\n";
- at new_swift_args = ("-Dscript.dir=" . $run_directory . "/scripts");
-push(@new_swift_args, "-Drestart.log.name=" . $run_directory . "/restart.log");
+mkdir($run_directory) || &swiftquit("Unable to create run directory $run_directory");
+ at new_swift_args = ("-Dscript.dir=$run_directory/scripts");
+push(@new_swift_args, "-Drestart.log.name=$run_directory/restart.log");
+push(@new_swift_args, "-swiftoutlog=$run_directory/swift.out");
 
 # Write swift configuration files
 &write_sites("sites.xml") if defined( $option_siteslist ) || defined($properties{site});




More information about the Swift-commit mailing list