rtmstart.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 import os,psutil,subprocess,socket,sys
4 from omniORB import CORBA
5 import CosNaming
6 
7 def start_cosname(cosnames, port_number):
8  p = None
9  pid = None
10  start_naming = True
11 
12  for p in psutil.process_iter():
13  try:
14  # find process using port_number
15  if filter(lambda c: c.local_address[1] == port_number, p.get_connections()):
16  print "\033[31m[rtmlaunch]", p.name, "is already started with port", port_number,"\033[0m"
17 
18  try:
19  orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
20  nameserver = orb.resolve_initial_references("NameService")
21  rootnc = nameserver._narrow(CosNaming.NamingContext)
22  def findObject(name, kind="", rnc=None) :
23  nc = CosNaming.NameComponent(name, kind)
24  if not rnc: rnc = rootnc
25  return rnc.resolve([nc])
26  cxt = findObject(socket.gethostname(), "host_cxt")
27  obj = findObject("manager", "mgr", cxt)
28  start_naming = False
29  except CosNaming.NamingContext.NotFound, ex:
30  # this is ok since host_cxt, manager is not bind
31  start_naming = False
32  pass
33  except:
34  print "\033[31m[rtmlaunch] name server is unreachable so kill process\033[0m"
35  print "\033[31m[rtmlaunch] kill ", cosnames, " of pid", p.pid,"\033[0m"
36  p.terminate()
37  except:
38  pass
39 
40  if not start_naming :
41  print "\033[31m[rtmlaunch] do not start", cosnames, ", exiting...\033[0m"
42  exit(0)
43  else:
44  print "\033[34m[rtmlaunch] Start", cosnames, "at port", port_number, "\033[0m"
45  logdir = "/tmp"
46  hostname = socket.gethostname()
47  try :
48  os.remove(logdir+"/omninames-"+hostname+".log")
49  os.remove(logdir+"/omninames-"+hostname+".bak")
50  except:
51  pass
52 
53  p = subprocess.Popen([cosnames,"-start", str(port_number), "-always", "-logdir", logdir])
54 
55  return p
56 
57 
58 
59 
def start_cosname(cosnames, port_number)
Definition: rtmstart.py:7


openrtm_tools
Author(s): Kei Okada
autogenerated on Mon May 10 2021 02:30:55