]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix some bashisms and potential errors in Launcher service generated shell scripts
authorRenaud Barate <renaud.barate@edf.fr>
Fri, 9 Jan 2015 16:20:52 +0000 (17:20 +0100)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Wed, 4 Mar 2015 12:41:00 +0000 (13:41 +0100)
src/Launcher/Launcher_Job_Command.cxx
src/Launcher/Launcher_Job_PythonSALOME.cxx
src/Launcher/Launcher_Job_SALOME.cxx
src/Launcher/Launcher_Job_YACSFile.cxx

index 5c3b52aca56b243452125ccb976a2be488b11067..fd193e5211feb7ff892b8e3cdfb6e1517d96d1e6 100644 (file)
@@ -59,14 +59,14 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l
   launch_script_stream.open(launch_script.c_str(), std::ofstream::out);
    
   // Script
-  launch_script_stream << "#! /bin/bash -f" << std::endl;
+  launch_script_stream << "#!/bin/sh -f" << std::endl;
   launch_script_stream << "cd " << work_directory << std::endl;
   launch_script_stream << "export PYTHONPATH=" << work_directory << ":$PYTHONPATH" << std::endl;
   launch_script_stream << "export PATH=" << work_directory << ":$PATH" << std::endl;
   if (_env_file != "")
   {
     std::string::size_type last = _env_file.find_last_of("/");
-    launch_script_stream << "source ./" << _env_file.substr(last+1) << std::endl;
+    launch_script_stream << ". ./" << _env_file.substr(last+1) << std::endl;
   }
   launch_script_stream << "./" << _job_file_name_complete << " > " << work_directory <<"/logs/command_" << launch_date << ".log 2>&1" << std::endl;
 
index 19a3bb1c5dfadf7e2b4e5461512922772d4e67a2..4b0f6cb2ef3d4301747deff54a5089e4ce2c0243 100644 (file)
@@ -35,5 +35,5 @@ Launcher::Job_PythonSALOME::setJobFile(const std::string & job_file)
 void
 Launcher::Job_PythonSALOME::addJobTypeSpecificScript(std::ofstream & launch_script_stream)
 {
-  launch_script_stream << _resource_definition.AppliPath << "/salome shell -p $appli_port python " << _job_file_name_complete << " > logs/python_" << _launch_date << ".log 2>&1" << std::endl;
+  launch_script_stream << _resource_definition.AppliPath << "/salome shell -p \"$appli_port\" python " << _job_file_name_complete << " > logs/python_" << _launch_date << ".log 2>&1" << std::endl;
 }
index 0a50db1861e1ea2d71d3b08c7a0e52d8df1f1b30..c3b79b3f5d611f482072474a2a7f01814e618b4c 100644 (file)
@@ -90,37 +90,39 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params)
   launch_script_stream << "if [ \"x$LIBBATCH_NODEFILE\" != \"x\" ]; then " << std::endl;
   launch_script_stream << "CATALOG_FILE=" << "CatalogResources_" << _launch_date << ".xml" << std::endl;
   launch_script_stream << "export USER_CATALOG_RESOURCES_FILE=" << "$CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '<!DOCTYPE ResourcesCatalog>'  > $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '<resources>'                 >> $CATALOG_FILE" << std::endl;  
-  launch_script_stream << "cat $LIBBATCH_NODEFILE | sort | uniq -c | while read nbproc host"  << std::endl;
+  launch_script_stream << "{" << std::endl;
+  launch_script_stream << "echo '<!DOCTYPE ResourcesCatalog>'" << std::endl;
+  launch_script_stream << "echo '<resources>'" << std::endl;
+  launch_script_stream << "sort \"$LIBBATCH_NODEFILE\" | uniq -c | while read nbproc host"  << std::endl;
   launch_script_stream << "do"                                                  << std::endl;
   // Full name doesn't work. eg: sagittaire-7 instead of sagittaire-7.lyon.grid5000.fr
-  launch_script_stream << "host_basename=$(echo $host | cut -f1 -d.)"                                                  << std::endl;
-  launch_script_stream << "echo '<machine name='\\\"$host_basename\\\" >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         hostname='\\\"$host_basename\\\" >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         type=\"single_machine\"' >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         protocol=\"" << resource_protocol               << "\"' >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         userName=\"" << _resource_definition.UserName   << "\"' >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         appliPath=\"" << _resource_definition.AppliPath << "\"' >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         mpi=\"" << _resource_definition.getMpiImplTypeStr() << "\"' >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         nbOfNodes='\\\"$nbproc\\\" >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         nbOfProcPerNode=\"1\"' >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '         canRunContainers=\"true\"' >> $CATALOG_FILE" << std::endl;
-  launch_script_stream << "echo '/>'                                                              >> $CATALOG_FILE" << std::endl;
+  launch_script_stream << "host_basename=$(echo \"$host\" | cut -f1 -d.)"                                                  << std::endl;
+  launch_script_stream << "echo '<machine name='\\\"\"$host_basename\"\\\"" << std::endl;
+  launch_script_stream << "echo '         hostname='\\\"\"$host_basename\"\\\"" << std::endl;
+  launch_script_stream << "echo '         type=\"single_machine\"'" << std::endl;
+  launch_script_stream << "echo '         protocol=\"" << resource_protocol               << "\"'" << std::endl;
+  launch_script_stream << "echo '         userName=\"" << _resource_definition.UserName   << "\"'" << std::endl;
+  launch_script_stream << "echo '         appliPath=\"" << _resource_definition.AppliPath << "\"'" << std::endl;
+  launch_script_stream << "echo '         mpi=\"" << _resource_definition.getMpiImplTypeStr() << "\"'" << std::endl;
+  launch_script_stream << "echo '         nbOfNodes='\\\"\"$nbproc\"\\\"" << std::endl;
+  launch_script_stream << "echo '         nbOfProcPerNode=\"1\"'" << std::endl;
+  launch_script_stream << "echo '         canRunContainers=\"true\"'" << std::endl;
+  launch_script_stream << "echo '/>'" << std::endl;
   launch_script_stream << "done"                                 << std::endl;
-  launch_script_stream << "echo '</resources>' >> $CATALOG_FILE" << std::endl;
+  launch_script_stream << "echo '</resources>'" << std::endl;
+  launch_script_stream << "} > $CATALOG_FILE" << std::endl;
   launch_script_stream << "fi" << std::endl;
 
   // Create file for ns-port-log
-  launch_script_stream << "NS_PORT_FILE_PATH=`mktemp " << _resource_definition.AppliPath << "/USERS/nsport_XXXXXX` &&\n";
-  launch_script_stream << "NS_PORT_FILE_NAME=`basename $NS_PORT_FILE_PATH` &&\n";
+  launch_script_stream << "NS_PORT_FILE_PATH=$(mktemp " << _resource_definition.AppliPath << "/USERS/nsport_XXXXXX) &&\n";
+  launch_script_stream << "NS_PORT_FILE_NAME=$(basename \"$NS_PORT_FILE_PATH\") &&\n";
 
   // Launch SALOME with an appli
-  launch_script_stream << _resource_definition.AppliPath << "/salome start --terminal --ns-port-log=$NS_PORT_FILE_NAME --server-launch-mode=fork ";
+  launch_script_stream << _resource_definition.AppliPath << "/salome start --terminal --ns-port-log=\"$NS_PORT_FILE_NAME\" --server-launch-mode=fork ";
   launch_script_stream << "> logs/salome_" << _launch_date << ".log 2>&1 &&" << std::endl;
   launch_script_stream << "current=0 &&\n"
                        << "stop=20 &&\n"
-                       << "while ! test -s $NS_PORT_FILE_PATH\n"
+                       << "while ! test -s \"$NS_PORT_FILE_PATH\"\n"
                        << "do\n"
                        << "  sleep 2\n"
                        << "  current=$((current+1))\n"
@@ -129,14 +131,14 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params)
                        << "    exit\n"
                        << "  fi\n"
                        << "done &&\n"
-                       << "appli_port=`cat $NS_PORT_FILE_PATH` &&\n"
-                       << "rm $NS_PORT_FILE_PATH &&\n";
+                       << "appli_port=$(cat \"$NS_PORT_FILE_PATH\") &&\n"
+                       << "rm \"$NS_PORT_FILE_PATH\" &&\n";
 
   // Call real job type
   addJobTypeSpecificScript(launch_script_stream);
 
   // End
-  launch_script_stream << _resource_definition.AppliPath << "/salome shell -p $appli_port shutdownSalome.py" << std::endl;
+  launch_script_stream << _resource_definition.AppliPath << "/salome shell -p \"$appli_port\" shutdownSalome.py" << std::endl;
   //launch_script_stream << "sleep 10" << std::endl;
 
   // Return
index 896ac09e0dab0b5717edc697fde0db75be39eb66..b1bda42c54dfce7cb7ade2302b488c414c809f77 100644 (file)
@@ -40,7 +40,7 @@ Launcher::Job_YACSFile::setJobFile(const std::string & job_file)
 void
 Launcher::Job_YACSFile::addJobTypeSpecificScript(std::ofstream & launch_script_stream)
 {
-  launch_script_stream << _resource_definition.AppliPath << "/salome shell -p $appli_port driver args:-k,$appli_port," << _job_file_name_complete;
+  launch_script_stream << _resource_definition.AppliPath << "/salome shell -p \"$appli_port\" driver args:-k,\"$appli_port\"," << _job_file_name_complete;
   if (_dumpState > 0)
     launch_script_stream << ",--dump=" << _dumpState;
   launch_script_stream << " > logs/yacs_" << _launch_date << ".log 2>&1" << std::endl;