Salome HOME
Bug IPAL14904
[modules/kernel.git] / bin / runNS.py
1 #!/usr/bin/env python
2
3 #log files localization
4
5 import os, commands, sys, re, string, socket
6 from Utils_Identity import getShortHostName
7
8 if sys.platform == "win32":
9         # temporarily using home directory for Namning Service logs
10         # to be replaced with TEMP later...
11         os.environ["BaseDir"]=os.environ["HOME"]
12 else:
13         os.environ["BaseDir"]="/tmp"
14
15 os.environ["Username"]=os.environ["USER"]
16
17 # kill OmniNames if exists
18
19 #killall -q -9 omniNames
20
21 # clear log files
22
23 def startOmni():
24         try:
25           os.mkdir(os.environ["BaseDir"] + "/logs")
26           os.chmod(os.environ["BaseDir"] + "/logs", 0777)
27         except:
28           #print "Can't create " + os.environ["BaseDir"] + "/logs"
29           pass
30         
31         upath = os.environ["BaseDir"] + "/logs/" + os.environ["Username"]
32
33         try:
34           os.mkdir(upath)
35         except:
36           #print "Can't create " + upath
37           pass
38
39         #os.system("touch " + upath + "/dummy")
40         for fname in os.listdir(upath):
41           try:
42             os.remove(upath + "/" + fname)
43           except:
44             pass
45         #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log")
46
47         print "Name Service... "
48         #hname=os.environ["HOST"] #commands.getoutput("hostname")
49         if sys.platform == "win32":
50           hname=getShortHostName()
51         else:
52           hname=socket.gethostname()
53
54         print "hname=",hname
55         
56         f=open(os.environ["OMNIORB_CONFIG"])
57         ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read())
58         print "ss = ", ss
59         f.close()
60         aPort=re.findall("\d+", ss[0])[0]
61         
62         #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/"
63         #print "sed command = ", aSedCommand
64         #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"])
65         global process_id
66         print "port=", aPort
67         if sys.platform == "win32":          
68           #import win32pm
69           #command = ['omniNames -start ' , aPort , ' -logdir ' , '\"' + upath + '\"']
70           #os.system("start omniNames -start " + aPort + " -logdir " + "\"" + upath + "\"" )
71           command = "start omniNames -start " + aPort + " -logdir " + "\"" + upath + "\""
72           #print command
73           pid = win32pm.spawnpid( string.join(command, " "), -nc )
74           process_id[pid]=command
75         else:
76           os.system("omniNames -start " + aPort + " -logdir " + upath + " &")
77
78         print "ok"
79         print "to list contexts and objects bound int the context with the specified name : showNS "
80
81 # In LifeCycleCORBA, FactoryServer is started with rsh on the requested
82 #    computer if this Container does not exist. Default is localhost.
83 #    Others Containers are started with start_impl method of FactoryServer Container.
84 # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file
85 # Warning : on RedHat the file /etc/hosts contains by default a line like :
86 # 127.0.0.1               bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost  
87 #   (bordolex is the station name). omniNames on bordolex will be accessible from other
88 #   computers only if the computer name is removed on that line like :
89 #   127.0.0.1               bordolex.paris1.matra-dtv.fr localhost.localdomain localhost
90
91 # To start dynamically Containers on several computers you need to
92 # put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost"
93 # example : ORBInitRef NameService=corbaname::dm2s0017
94
95 # If you need to use several omniNames running on the same computer, you have to :
96 #1. put in your ${OMNIORB_CONFIG} file a computer name and port number
97 # example : ORBInitRef NameService=corbaname::dm2s0017:1515
98 #2. start omninames with this port number in runNS.sh
99 # example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} &