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


openrtm_tools
Author(s): Kei Okada
autogenerated on Thu Jun 6 2019 20:47:57