From: barate Date: Mon, 24 Oct 2011 13:40:24 +0000 (+0000) Subject: Add possibility to launch Salome servers and local containers with a specific command... X-Git-Tag: Before_0020136~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b519d7c2dabf7606624de681a572331b50299ff1;p=modules%2Fkernel.git Add possibility to launch Salome servers and local containers with a specific command like srun --- diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index 54959618f..eddc8f524 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -707,6 +707,15 @@ def CreateOptionParser (theAdditionalOptions=[]): dest="wake_up_session", default=False, help=help_str) + # Launch server processes with a specific command. Default: False. + help_str = "Launch server processes with a specific command." + o_slc = optparse.Option("--server-launch-cmd", + metavar="", + type="string", + action="store", + dest="server_launch_cmd", + help=help_str) + # All options opt_list = [o_t,o_g, # GUI/Terminal o_d,o_o, # Desktop @@ -735,6 +744,7 @@ def CreateOptionParser (theAdditionalOptions=[]): o_shutdown, o_foreground, o_wake_up, + o_slc, # Server launch command ] #std_options = ["gui", "desktop", "log_file", "py_scripts", "resources", @@ -1082,6 +1092,10 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"): filename = cmd_opts.play_script_file args[play_nam] += re.split( "[:;,]", filename ) + # Server launch command + if cmd_opts.server_launch_cmd is not None: + args["server_launch_cmd"] = cmd_opts.server_launch_cmd + # return arguments os.environ[config_var] = separator.join(dirs) #print "Args: ", args diff --git a/bin/runSalome.py b/bin/runSalome.py index 24a718671..5dd6137c6 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -29,9 +29,8 @@ import sys, os, string, glob, time, pickle, re import orbmodule import setenv -from server import * from launchConfigureParser import verbose -from server import process_id +from server import process_id, Server if sys.platform == "win32": SEP = ";" @@ -416,6 +415,12 @@ def startSalome(args, modules_list, modules_root_dir): if verbose(): print "startSalome ", args + # + # Set server launch command + # + if args.has_key('server_launch_cmd'): + Server.set_server_launch_cmd(args['server_launch_cmd']) + # # Wake up session option # diff --git a/bin/server.py b/bin/server.py index dbef17779..3fde06b40 100755 --- a/bin/server.py +++ b/bin/server.py @@ -23,6 +23,7 @@ # import os, sys, string +from salome_utils import getHostName process_id = {} # ----------------------------------------------------------------------------- @@ -32,6 +33,8 @@ process_id = {} class Server: """Generic class for CORBA server launch""" + + server_launch_args = [] def initArgs(self): self.PID=None @@ -47,6 +50,13 @@ class Server: self.args=args self.initArgs() + @staticmethod + def set_server_launch_cmd(cmd): + if cmd == "srun": + Server.server_launch_args = ["srun", "-n", "1", "-N", "1"] + Server.server_launch_args += ["--share", "--nodelist=%s" % getHostName()] + else: + print >>sys.stderr, "Unknown server launch command:%s" % cmd def run(self): global process_id @@ -124,8 +134,9 @@ class Server: #I am a daemon os.close(0) #close stdin os.open("/dev/null", os.O_RDWR) # redirect standard input (0) to /dev/null + all_args = Server.server_launch_args + args try: - os.execvp(args[0], args) + os.execvp(all_args[0], all_args) except OSError, e: if args[0] != "notifd": print >>sys.stderr, "(%s) launch failed: %d (%s)" % (args[0],e.errno, e.strerror) diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 87de58880..8ad253294 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -444,10 +444,10 @@ SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& param std::string command; // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer" if( getenv("LIBBATCH_NODEFILE") != NULL && params.isMPI ) - command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe); + command = BuildCommandToLaunchLocalContainer(resource_selected, params, machFile, container_exe); // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer" else if(hostname == Kernel_Utils::GetHostname()) - command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe); + command = BuildCommandToLaunchLocalContainer(resource_selected, params, machFile, container_exe); // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer" else command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe); @@ -652,25 +652,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \ // SALOME_Container containerName &" - if (resInfo.Protocol == rsh) - command = "rsh "; - else if (resInfo.Protocol == ssh) - command = "ssh "; - else if (resInfo.Protocol == srun) - command = "srun -n 1 -N 1 --share --nodelist="; - else - throw SALOME_Exception("Unknown protocol"); - - // no need to redefine the user with srun, the job user is taken by default (note: for srun, user id can be specified with " --uid=") - if (resInfo.Protocol != srun && resInfo.UserName != "") - { - command += "-l "; - command += resInfo.UserName; - command += " "; - } - - command += resInfo.HostName; - command += " "; + command = getCommandToRunProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName); if (resInfo.AppliPath != "") command += resInfo.AppliPath; // path relative to user@machine $HOME @@ -740,7 +722,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer //============================================================================= std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer -(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe) +(const std::string & resource_name, const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe) { _TmpFileName = BuildTemporaryFileName(); std::string command; @@ -810,6 +792,10 @@ SALOME_ContainerManager::BuildCommandToLaunchLocalContainer #endif } } + + const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name); + o << getCommandToRunProcess(resInfo.Protocol); + if (isPythonContainer(params.container_name)) o << "SALOME_ContainerPy.py "; else @@ -1181,6 +1167,56 @@ std::set SALOME_ContainerManager::getpidofprogram(const std::string progr return thepids; } +std::string SALOME_ContainerManager::getCommandToRunProcess(AccessProtocolType protocol, + const std::string & hostname, + const std::string & username) +{ + std::string hostRealName = hostname; + std::string localHostRealName = Kernel_Utils::GetHostname(); + bool isLocal = false; + if (hostname == "localhost" || hostname == localHostRealName) + { + isLocal = true; + hostRealName = localHostRealName; + } + + std::ostringstream command; + switch (protocol) + { + case rsh: + if (!isLocal) + { + command << "rsh "; + if (username != "") + { + command << "-l " << username << " "; + } + command << hostRealName << " "; + } + break; + case ssh: + if (!isLocal) + { + command << "ssh "; + if (username != "") + { + command << "-l " << username << " "; + } + command << hostRealName << " "; + } + break; + case srun: + // no need to redefine the user with srun, the job user is taken by default + // (note: for srun, user id can be specified with " --uid=") + command << "srun -n 1 -N 1 --share --nodelist=" << hostRealName << " "; + break; + default: + throw SALOME_Exception("Unknown protocol"); + } + + return command.str(); +} + bool SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected) { diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 6aff78529..3aa218c2a 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -69,7 +69,8 @@ protected: const Engines::ContainerParameters& params, const std::string& container_exe="SALOME_Container"); - std::string BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, + std::string BuildCommandToLaunchLocalContainer(const std::string & resource_name, + const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe="SALOME_Container"); @@ -92,6 +93,10 @@ protected: std::set getpidofprogram(const std::string program); + std::string getCommandToRunProcess(AccessProtocolType protocol, + const std::string & hostname = "localhost", + const std::string & username = ""); + CORBA::ORB_var _orb; PortableServer::POA_var _poa; diff --git a/src/Launcher/Launcher_Job_SALOME.cxx b/src/Launcher/Launcher_Job_SALOME.cxx index 56fc41405..b9005c2e6 100644 --- a/src/Launcher/Launcher_Job_SALOME.cxx +++ b/src/Launcher/Launcher_Job_SALOME.cxx @@ -111,7 +111,13 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params) launch_script_stream << "NS_PORT_FILE_NAME=`basename $NS_PORT_FILE_PATH` &&\n"; // Launch SALOME with an appli - launch_script_stream << _resource_definition.AppliPath << "/runAppli --terminal --ns-port-log=$NS_PORT_FILE_NAME > logs/salome_" << _launch_date << ".log 2>&1 &&" << std::endl; + launch_script_stream << _resource_definition.AppliPath << "/runAppli --terminal --ns-port-log=$NS_PORT_FILE_NAME "; + if (_resource_definition.ClusterInternalProtocol != rsh && + _resource_definition.ClusterInternalProtocol != ssh) + { + launch_script_stream << "--server-launch-cmd=" << resource_protocol << " "; + } + 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"