Go to the documentation of this file.00001
00002
00003 import sys; sys.path.insert(0,"/usr/lib/python{0}.{1}/dist-packages".format(sys.version_info[0],sys.version_info[1]))
00004
00005
00006 import os,psutil,subprocess,socket,sys
00007 from omniORB import CORBA
00008 import CosNaming
00009
00010 def start_cosname(cosnames, port_number):
00011 p = None
00012 pid = None
00013 start_naming = True
00014
00015 for p in psutil.process_iter():
00016 try:
00017
00018 if filter(lambda c: c.local_address[1] == port_number, p.get_connections()):
00019 print "\033[31m[rtmlaunch]", p.name, "is already started with port", port_number,"\033[0m"
00020
00021 try:
00022 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
00023 nameserver = orb.resolve_initial_references("NameService")
00024 rootnc = nameserver._narrow(CosNaming.NamingContext)
00025 def findObject(name, kind="", rnc=None) :
00026 nc = CosNaming.NameComponent(name, kind)
00027 if not rnc: rnc = rootnc
00028 return rnc.resolve([nc])
00029 cxt = findObject(socket.gethostname(), "host_cxt")
00030 obj = findObject("manager", "mgr", cxt)
00031 start_naming = False
00032 except CosNaming.NamingContext.NotFound, ex:
00033
00034 start_naming = False
00035 pass
00036 except:
00037 print "\033[31m[rtmlaunch] name server is unreachable so kill process\033[0m"
00038 print "\033[31m[rtmlaunch] kill ", cosnames, " of pid", p.pid,"\033[0m"
00039 p.terminate()
00040 except:
00041 pass
00042
00043 if not start_naming :
00044 print "\033[31m[rtmlaunch] do not start", cosnames, ", exiting...\033[0m"
00045 exit(0)
00046 else:
00047 print "\033[34m[rtmlaunch] Start", cosnames, "at port", port_number, "\033[0m"
00048 logdir = "/tmp"
00049 hostname = socket.gethostname()
00050 try :
00051 os.remove(logdir+"/omninames-"+hostname+".log")
00052 os.remove(logdir+"/omninames-"+hostname+".bak")
00053 except:
00054 pass
00055
00056 p = subprocess.Popen([cosnames,"-start", str(port_number), "-always", "-logdir", logdir])
00057
00058 return p
00059
00060
00061
00062