From b26ec591dddb0ec8d5987efc86eba5dd0e48f568 Mon Sep 17 00:00:00 2001 From: nri Date: Mon, 26 May 2003 15:43:11 +0000 Subject: [PATCH] NRI : Add new SALOME launch procedure. --- Makefile.in | 34 +---- bin/killSalome.py | 36 +++++ bin/orbmodule.py | 180 ++++++++++++++++++++++++ bin/runSalome | 21 +++ bin/runSalome.py | 347 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 590 insertions(+), 28 deletions(-) create mode 100755 bin/killSalome.py create mode 100755 bin/orbmodule.py create mode 100755 bin/runSalome create mode 100755 bin/runSalome.py diff --git a/Makefile.in b/Makefile.in index 4cedeabbf..c8c6007ae 100644 --- a/Makefile.in +++ b/Makefile.in @@ -86,35 +86,13 @@ Plugin \ SALOMEDS_Resources BIN_SCRIPT= \ -README \ -allkill \ -allkillWithPort \ -insertComputerRessourcesCatalog.sh \ -runClientDataTypeCatalog \ -runClientModuleCatalog \ -runClientRessourcesCatalog \ -runDataTypeCatalog \ -runModuleCatalog \ -runNS.sh \ -runNSWithPort.sh \ -runRessourcesCatalog \ -runSALOMEDS_Client \ -runSalome \ runIDLparser \ -runSalomeWithPort \ -runSalomeServers \ -runSalomeDesktop \ -runSession \ -runLoader \ -runTestContainer \ -runTestContainerPy2 \ -runTestContainerPy \ -runTestLifeCycle \ -runTestMED \ -runTestNotification \ -showNS \ -VERSION -#SuperVision.py +VERSION \ +orbmodule.py \ +runSalome.py \ +killSalome.py \ +runSalome \ +runNS.sh # copy header files in common directory ifeq ($(HAVE_SSTREAM),yes) diff --git a/bin/killSalome.py b/bin/killSalome.py new file mode 100755 index 000000000..3620f55ac --- /dev/null +++ b/bin/killSalome.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import sys,os,pickle,signal + +process_id={} + +# ----------------------------------------------------------------------------- +# +# Fonction d'arrêt de salome +# + +def killSalome(): + print "arret des serveurs SALOME" + for pid, cmd in process_id.items(): + print "arret du process %s : %s"% (pid, cmd[0]) + try: + os.kill(pid,signal.SIGKILL) + except: + print " ------------------ process %s : %s inexistant"% (pid, cmd[0]) + print "arret du naming service" + os.system("killall -9 omniNames") + +# ----------------------------------------------------------------------------- + +filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict' +#filedict='/tmp/'+os.getlogin()+'_SALOME_pidict' +try: + fpid=open(filedict, 'r') +except: + print "le fichier %s des process SALOME n'est pas accessible"% filedict + sys.exit(1) + +process_id=pickle.load(fpid) +fpid.close() + +killSalome() diff --git a/bin/orbmodule.py b/bin/orbmodule.py new file mode 100755 index 000000000..bd8e73b78 --- /dev/null +++ b/bin/orbmodule.py @@ -0,0 +1,180 @@ +import sys,os,time +import string +from omniORB import CORBA + +# Import the stubs for the Naming service +import CosNaming + +# ----------------------------------------------------------------------------- + +class Server: + XTERM="/usr/bin/X11/xterm -iconic -e " + CMD="" + + def run(self): + commande=self.XTERM+self.CMD + print commande + ier=os.system(commande) + if ier:print "Commande failed" + +# ----------------------------------------------------------------------------- + +class NamingServer(Server): + XTERM="" + CMD="runNS.sh > /tmp/salomeNS.log 2>&1" + +# ----------------------------------------------------------------------------- + +class client: + + def __init__(self): + # Initialise the ORB + self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID) + # Initialise the Naming Service + self.initNS() + + # -------------------------------------------------------------------------- + + def initNS(self): + # Obtain a reference to the root naming context + obj = self.orb.resolve_initial_references("NameService") + try: + self.rootContext = obj._narrow(CosNaming.NamingContext) + return + except CORBA.COMM_FAILURE: + self.rootContext = None + print "Lancement du Naming Service", + + # On lance le Naming Server (doit etre dans le PATH) + NamingServer().run() + print "Searching Naming Service ", + ncount=0 + delta=0.1 + while(ncount < 10): + ncount += 1 + try: + obj = self.orb.resolve_initial_references("NameService") + self.rootContext = obj._narrow(CosNaming.NamingContext) + break + except (CORBA.COMM_FAILURE,CORBA.OBJECT_NOT_EXIST): + self.rootContext = None + sys.stdout.write('+') + sys.stdout.flush() + time.sleep(delta) + + if self.rootContext is None: + print "Failed to narrow the root naming context" + sys.exit(1) + print " found in %s seconds " % ((ncount-1)*delta) + + # -------------------------------------------------------------------------- + + def showNScontext(self,context,dec=''): + bl,bi=context.list(0) + ok,b=bi.next_one() + while(ok): + for s in b.binding_name : + print "%s%s.%s" %(dec,s.id,s.kind) + if s.kind == "dir": + obj=context.resolve([s]) + scontext = obj._narrow(CosNaming.NamingContext) + self.showNScontext(scontext,dec=dec+' ') + ok,b=bi.next_one() + + # -------------------------------------------------------------------------- + + def showNS(self): + """ Show the content of NS""" + self.showNScontext(self.rootContext) + + # -------------------------------------------------------------------------- + + def Resolve(self, Path): + resolve_path=string.split(Path,'/') + if resolve_path[0] == '': del resolve_path[0] + dir_path=resolve_path[:-1] + context_name=[] + for e in dir_path: + context_name.append(CosNaming.NameComponent(e,"dir")) + context_name.append(CosNaming.NameComponent(resolve_path[-1],"object")) + + try: + obj = self.rootContext.resolve(context_name) + except CosNaming.NamingContext.NotFound, ex: + obj = None + except CosNaming.NamingContext.InvalidName, ex: + obj = None + except CosNaming.NamingContext.CannotProceed, ex: + obj = None + except CORBA.COMM_FAILURE, ex: + obj = None + return obj + + # -------------------------------------------------------------------------- + + def waitNS(self,name,typobj=None,maxcount=70): + count=0 + delta=0.3 + print "Searching %s in Naming Service " % name, + while(1): + count += 1 + if count > maxcount : raise "Impossible de trouver %s" % name + obj=self.Resolve(name) + if obj : + print " found in %s seconds " % ((count-1)*delta) + break + else: + sys.stdout.write('+') + sys.stdout.flush() + time.sleep(delta) + + if typobj is None:return obj + + nobj = obj._narrow(typobj) + if nobj is None: + print "%s exists but is not a %s" % (name,typobj) + return nobj + + # -------------------------------------------------------------------------- + + def ResolveLogger(self, name): + context_name=[] + context_name.append(CosNaming.NameComponent(name,"")) + + try: + obj = self.rootContext.resolve(context_name) + except CosNaming.NamingContext.NotFound, ex: + obj = None + except CosNaming.NamingContext.InvalidName, ex: + obj = None + except CosNaming.NamingContext.CannotProceed, ex: + obj = None + except CORBA.COMM_FAILURE, ex: + obj = None + return obj + + # -------------------------------------------------------------------------- + + def waitLogger(self,name,typobj=None,maxcount=10): + count=0 + delta=0.3 + print "Searching %s in Naming Service " % name, + while(1): + count += 1 + if count > maxcount : raise "Impossible de trouver %s" % name + obj=self.ResolveLogger(name) + if obj : + print " found in %s seconds " % ((count-1)*delta) + break + else: + sys.stdout.write('+') + sys.stdout.flush() + time.sleep(delta) + + if typobj is None:return obj + + nobj = obj._narrow(typobj) + if nobj is None: + print "%s exists but is not a %s" % (name,typobj) + return nobj + diff --git a/bin/runSalome b/bin/runSalome new file mode 100755 index 000000000..9a133bb9f --- /dev/null +++ b/bin/runSalome @@ -0,0 +1,21 @@ +#!/bin/sh + +export KERNEL_ROOT_DIR=/Salome2/KERNEL_install + +export GEOM_ROOT_DIR=/Salome2/GEOM_install +export MED_ROOT_DIR=/Salome2/MED_install +export SMESH_ROOT_DIR=/Salome2/SMESH_install +export SUPERV_ROOT_DIR=/Salome2/SUPERV_install +export VISU_ROOT_DIR=/Salome2/VISU_install + +python killSalome.py +python -i runSalome.py GEOM SMESH VISU SUPERV MED + +# ----------------------------------------------------------------------------- +# +# l'option -i permet de garder l'interpreteur python ouvert : +# par defaut, les differents serveurs ouvrent des fenêtres xterm +# (cf. runSalome.py) +# le serveur Logger n'est pas obligatoire (commenté dans runSalome.py) +# +# ----------------------------------------------------------------------------- diff --git a/bin/runSalome.py b/bin/runSalome.py new file mode 100755 index 000000000..0a6514bde --- /dev/null +++ b/bin/runSalome.py @@ -0,0 +1,347 @@ +#!/usr/bin/env python + +usage="""USAGE: runSalome.py module1 module2 ... + où modulen est le nom d'un module Salome à charger dans le catalogue + La variable d'environnement _ROOT_DIR doit etre préalablement + positionnée (modulen doit etre en majuscule). + KERNEL_ROOT_DIR est obligatoire. +""" + +import sys,os,string,glob,time,signal,pickle + +init_time=os.times() +liste_modules=sys.argv[1:] +modules_root_dir={} +process_id={} + +# ----------------------------------------------------------------------------- +# +# Vérification des variables d'environnement +# +try: + kernel_root_dir=os.environ["KERNEL_ROOT_DIR"] + modules_root_dir["KERNEL"]=kernel_root_dir +except: + print usage + sys.exit(1) + +for module in liste_modules : + try: + module=module.upper() + module_root_dir=os.environ[module +"_ROOT_DIR"] + modules_root_dir[module]=module_root_dir + except: + print usage + sys.exit(1) + +# il faut KERNEL en premier dans la liste des modules +# - l'ordre des modules dans le catalogue sera identique +# - la liste des modules presents dans le catalogue est exploitée pour charger les modules CORBA python, +# il faut charger les modules python du KERNEL en premier + +if "KERNEL" in liste_modules:liste_modules.remove("KERNEL") +liste_modules[:0]=["KERNEL"] +#print liste_modules +#print modules_root_dir + +import orbmodule + +# ----------------------------------------------------------------------------- +# +# Définition des classes d'objets pour le lancement des Server CORBA +# + +class Server: + CMD=[] + ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-e'] + #ARGS=[] + def run(self): + args = self.ARGS+self.CMD + #print "args = ", args + pid = os.spawnvp(os.P_NOWAIT, args[0], args) + process_id[pid]=self.CMD + +class CatalogServer(Server): + SCMD1=['SALOME_ModuleCatalog_Server','-common'] + SCMD2=['-personal','${HOME}/Salome/resources/CatalogModulePersonnel.xml'] + + def setpath(self,liste_modules): + cata_path=[] + for module in liste_modules: + module_root_dir=modules_root_dir[module] + module_cata=module+"Catalog.xml" + print " ", module_cata + cata_path.extend(glob.glob(os.path.join(module_root_dir,"share","salome","resources",module_cata))) + self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2 + +class SalomeDSServer(Server): + CMD=['SALOMEDS_Server'] + +class RegistryServer(Server): + CMD=['SALOME_Registry_Server', '--salome_session','theSession'] + +class ContainerCPPServer(Server): + CMD=['SALOME_Container','FactoryServer','-ORBInitRef','NameService=corbaname::localhost'] + +class ContainerPYServer(Server): + CMD=['SALOME_ContainerPy.py','FactoryServerPy','-ORBInitRef','NameService=corbaname::localhost'] + +class ContainerSUPERVServer(Server): + CMD=['SALOME_Container','SuperVisionContainer','-ORBInitRef','NameService=corbaname::localhost'] + +class LoggerServer(Server): + CMD=['SALOME_Logger_Server', 'logger.log'] + +class SessionServer(Server): + CMD=['SALOME_Session_Server'] + +class NotifyServer(Server): + CMD=['notifd','-c','${KERNEL_ROOT_DIR}/share/salome/resources/channel.cfg -DFactoryIORFileName=/tmp/${LOGNAME}_rdifact.ior -DChannelIORFileName=/tmp/${LOGNAME}_rdichan.ior'] + +# ----------------------------------------------------------------------------- +# +# Fonction d'arrêt de salome +# + +def killSalome(): + print "arret des serveurs SALOME" + for pid, cmd in process_id.items(): + print "arret du process %s : %s"% (pid, cmd[0]) + os.kill(pid,signal.SIGKILL) + print "arret du naming service" + os.system("killall -9 omniNames") + +# ----------------------------------------------------------------------------- +# +# Fonction de test +# + +def test(clt): + # create an LifeCycleCORBA instance + import LifeCycleCORBA + lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb) + med = lcc.FindOrLoadComponent("FactoryServer", "MED") + #pycalc = lcc.FindOrLoadComponent("FactoryServerPy", "CalculatorPy") + +# ----------------------------------------------------------------------------- +# +# Fonctions helper pour ajouter des variables d'environnement +# + +def add_path(directory): + os.environ["PATH"]=directory + ":" + os.environ["PATH"] + +def add_ld_library_path(directory): + os.environ["LD_LIBRARY_PATH"]=directory + ":" + os.environ["LD_LIBRARY_PATH"] + +def add_python_path(directory): + os.environ["PYTHONPATH"]=directory + ":" + os.environ["PYTHONPATH"] + sys.path[:0]=[directory] + +# ----------------------------------------------------------------------------- +# +# initialisation des variables d'environnement +# + +python_version="python%d.%d" % sys.version_info[0:2] + +# +# Ajout du chemin d'acces aux executables de KERNEL dans le PATH +# + +add_path(os.path.join(kernel_root_dir,"bin","salome")) +#print "PATH=",os.environ["PATH"] + +# +# Ajout des modules dans le LD_LIBRARY_PATH +# +for module in liste_modules: + module_root_dir=modules_root_dir[module] + add_ld_library_path(os.path.join(module_root_dir,"lib","salome")) +#print "LD_LIBRARY_PATH=",os.environ["LD_LIBRARY_PATH"] + +# +# Ajout des modules dans le PYTHONPATH (KERNEL prioritaire, donc en dernier) +# + +liste_modules_reverse=liste_modules[:] +liste_modules_reverse.reverse() +#print liste_modules +#print liste_modules_reverse +for module in liste_modules_reverse: + module_root_dir=modules_root_dir[module] + add_python_path(os.path.join(module_root_dir,"bin","salome")) + add_python_path(os.path.join(module_root_dir,"lib",python_version,"site-packages","salome")) + add_python_path(os.path.join(module_root_dir,"lib","salome")) + +#print "PYTHONPATH=",sys.path + +# +# ----------------------------------------------------------------------------- +# + +def startSalome(): + # + # Initialisation ORB et Naming Service + # + + clt=orbmodule.client() + + # (non obligatoire) Lancement Logger Server et attente de sa disponibilite dans le naming service + # + + #LoggerServer().run() + #clt.waitLogger("Logger") + + # + # Lancement Registry Server + # + + RegistryServer().run() + + # + # Attente de la disponibilité du Registry dans le Naming Service + # + + clt.waitNS("/Registry") + + # + # Lancement Catalog Server + # + + cataServer=CatalogServer() + cataServer.setpath(liste_modules) + cataServer.run() + + # + # Attente de la disponibilité du Catalog Server dans le Naming Service + # + + import SALOME_ModuleCatalog + clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog) + + # + # Lancement SalomeDS Server + # + + os.environ["CSF_PluginDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources") + os.environ["CSF_SALOMEDS_ResourcesDefaults"]=os.path.join(kernel_root_dir,"share","salome","resources") + SalomeDSServer().run() + + if "GEOM" in liste_modules: + print "GEOM OCAF Resources" + os.environ["CSF_GEOMDS_ResourcesDefaults"]=os.path.join(modules_root_dir["GEOM"],"share","salome","resources") + + + # + # Attente de la disponibilité du SalomeDS dans le Naming Service + # + + clt.waitNS("/myStudyManager") + + # + # Lancement Session Server + # + + SessionServer().run() + + # + # Attente de la disponibilité du Session Server dans le Naming Service + # + + import SALOME + session=clt.waitNS("/Kernel/Session",SALOME.Session) + + # + # Lancement Container C++ local + # + + ContainerCPPServer().run() + + # + # Attente de la disponibilité du Container C++ local dans le Naming Service + # + + theComputer = os.getenv("HOSTNAME") + computerSplitName = theComputer.split('.') + theComputer = computerSplitName[0] + + clt.waitNS("/Containers/" + theComputer + "/FactoryServer") + + # + # Lancement Container Python local + # + + ContainerPYServer().run() + + # + # Attente de la disponibilité du Container Python local dans le Naming Service + # + + clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy") + + + if "SUPERV" in liste_modules: + + # + # Lancement Container Supervision local + # + + ContainerSUPERVServer().run() + + # + # Attente de la disponibilité du Container Supervision local dans le Naming Service + # + + clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer") + + # + # Activation du GUI de Session Server + # + + session.GetInterface() + + end_time = os.times() + print + print "Start SALOME, elpased time : %5.1f seconds"% (end_time[4] - init_time[4]) + + return clt + +# +# ----------------------------------------------------------------------------- +# + +clt=None +try: + clt = startSalome() +except: + print + print + print "--- erreur au lancement Salome ---" + +#print process_id + + +filedict='/tmp/'+os.getenv('USER')+'_SALOME_pidict' +#filedict='/tmp/'+os.getlogin()+'_SALOME_pidict' + +fpid=open(filedict, 'w') +pickle.dump(process_id,fpid) +fpid.close() + +print +print "Sauvegarde du dictionnaire des process dans ", filedict +print "Pour tuer les process SALOME, executer : python killSalome.py depuis" +print "une console, ou bien killSalome() depuis le present interpreteur," +print "s'il n'est pas fermé." +print "runSalome commence par tuer les process restants d'une execution précédente." + +# +# Impression arborescence Naming Service +# + +if clt != None: + print + print " --- registered objects tree in Naming Service ---" + clt.showNS() + -- 2.39.2