def __init__(self, name="service_fork", execparams={}): self.name = name self._baseLog = logging.getLogger(self.name) self._log = logging.getLogger(self.name) sp = _utils.Popen( ['python', '../../../dev/services/service_fork/python/loop.py']) self._pid = sp.pid
def kickDomain(domain_name=None, kick_device_managers=True, device_managers=[], detached=False, sdrroot=None, stdout=None, logfile=None): """Kick-start a REDHAWK domain. domain_name: the name that should be used kick_device_managers: one or more Device Managers should be automatically started device_managers: if kick_device_managers set to True, list of Device Managers to start. If the list is empty, then start all Device Managers in $SDRROOT/dev/nodes detached: determine whether the life cycle of the started Domain and Device Managers should follow the lifecycle of the current Python session sdrroot: use this sdr root. If set to None, then use $SDRROOT stdout: filename where stdout should be redirected. None sends stdout to /dev/null """ if sdrroot == None: try: sdrroot = _os.getenv('SDRROOT') except: print "The environment variable SDRROOT must be set or an sdrroot value must be passed as an argument" args = ['nodeBooter'] args.append('-D') args.append('-sdrroot') args.append(sdrroot) if logfile: args.append('-logcfgfile') args.append(logfile) if domain_name != None: args.append('--domainname') args.append(domain_name) else: dmd_file = sdrroot + '/dom/domain/DomainManager.dmd.xml' try: fp = open(dmd_file, 'r') dmd_contents = fp.read() fp.close except: print "Unable to read domain profile " + dmd_file return None try: dmd = _minidom.parseString(dmd_contents) domain_name = str( dmd.getElementsByTagName('domainmanagerconfiguration') [0].getAttribute('name')) except: print "Invalid domain profile " + dmd_file return None _devnull = open('/dev/null') if stdout == None: stdout_fp = None elif stdout == 0: stdout_fp = open('/dev/null', 'w') else: stdout_fp = open(stdout, 'w') if stdout_fp == None: sp = _utils.Popen(args, executable=None, cwd=_os.getcwd(), close_fds=True, stdin=_devnull, preexec_fn=_os.setpgrp) else: sp = _utils.Popen(args, executable=None, cwd=_os.getcwd(), close_fds=True, stdin=_devnull, stdout=stdout_fp, preexec_fn=_os.setpgrp) if globals().has_key('currentdomain'): globals()['currentdomain'] = None globals()['currentdomain'] = _envContainer(sp.pid, stdout_fp) if kick_device_managers: if len(device_managers) == 0: base = sdrroot + '/dev/nodes' for (directory, sub, files) in _os.walk(base): foundDCD = False filename = '' for file in files: if file[-8:] == '.dcd.xml': filename = file foundDCD = True break if foundDCD: device_managers.append(directory[len(sdrroot) + 4:] + '/' + filename) for device_manager in device_managers: args = ['nodeBooter'] args.append('-d') args.append(device_manager) args.append('-sdrroot') args.append(sdrroot) args.append('--domainname') args.append(domain_name) if logfile: args.append('-logcfgfile') args.append(logfile) sp = _utils.Popen(args, executable=None, cwd=_os.getcwd(), close_fds=True, stdin=_devnull, stdout=stdout_fp, preexec_fn=_os.setpgrp) dom = attach(domain_name) return dom
def kickDomain(domain_name=None, kick_device_managers=True, device_managers=[], detached=False, sdrroot=None, stdout=None, logfile=None, debug_level=None, device_managers_debug_levels=[]): """Kick-start a REDHAWK domain. domain_name: the name that should be used kick_device_managers: one or more Device Managers should be automatically started device_managers: if kick_device_managers set to True, list of Device Managers to start. If the list is empty, then start all Device Managers in $SDRROOT/dev/nodes. List can be node names i.e. GPP_node or absolute path to DCD files detached: determine whether the life cycle of the started Domain and Device Managers should follow the lifecycle of the current Python session sdrroot: use this sdr root. If set to None, then use $SDRROOT stdout: filename where stdout should be redirected. None sends stdout to /dev/null debug_level: debug level to pass on command line: FATAL, ERROR, WARN, INFO, DEBUG, TRACE device_managers_debug_levels = list of debug levels to pass on command line with corresponding device_managers """ if sdrroot == None: try: sdrroot = _os.getenv('SDRROOT') except: print "The environment variable SDRROOT must be set or an sdrroot value must be passed as an argument" args = ['nodeBooter'] args.append('-D') args.append('-sdrroot') args.append(sdrroot) if logfile: args.append('-logcfgfile') args.append(logfile) if debug_level: args.append('-debug') args.append(str(ConvertLevelNameToDebugLevel(debug_level))) # Unconditionally turn off persistence; if persistence support is desired, # a "dburi" argument can be added args.append('--nopersist') if domain_name != None: args.append('--domainname') args.append(domain_name) else: dmd_file = sdrroot+'/dom/domain/DomainManager.dmd.xml' try: fp = open(dmd_file,'r') dmd_contents = fp.read() fp.close except: print "Unable to read domain profile "+dmd_file return None try: dmd = _minidom.parseString(dmd_contents) domain_name = str(dmd.getElementsByTagName('domainmanagerconfiguration')[0].getAttribute('name')) except: print "Invalid domain profile "+dmd_file return None _devnull = open('/dev/null') if stdout == None: stdout_fp = None elif stdout == 0: stdout_fp = open('/dev/null','w') else: stdout_fp = open(stdout,'w') if stdout_fp == None: sp = _utils.Popen(args, executable=None, cwd=_os.getcwd(), close_fds=True, stdin=_devnull, preexec_fn=_os.setpgrp) else: sp = _utils.Popen(args, executable=None, cwd=_os.getcwd(), close_fds=True, stdin=_devnull, stdout=stdout_fp, preexec_fn=_os.setpgrp) if globals().has_key('currentdomain'): globals()['currentdomain'] = None globals()['currentdomain'] = _envContainer(sp, stdout_fp) if kick_device_managers: dm_procs=[] if len(device_managers) == 0: base = sdrroot + '/dev/nodes' for (directory,sub,files) in _os.walk(base): foundDCD = False filename = '' for file in files: if file[-8:] == '.dcd.xml': filename = file foundDCD = True break if foundDCD: device_managers.append(directory[len(sdrroot)+4:]+'/'+filename) for idx, device_manager in enumerate(device_managers): dcd_file = _getDCDFile(sdrroot, device_manager) if not dcd_file: print "Unable to locate DCD file for '%s'" % device_manager continue args = ['nodeBooter'] args.append('-d') args.append(dcd_file) args.append('-sdrroot') args.append(sdrroot) args.append('--domainname') args.append(domain_name) if logfile: args.append('-logcfgfile') args.append(logfile) if device_managers_debug_levels and len(device_managers_debug_levels) > 0 : dlevel = None if idx < len(device_managers_debug_levels): dlevel = device_managers_debug_levels[idx] if dlevel: args.append('-debug') args.append(str(ConvertLevelNameToDebugLevel(dlevel))) sp = _utils.Popen(args, executable=None, cwd=_os.getcwd(), close_fds=True, stdin=_devnull, stdout=stdout_fp, preexec_fn=_os.setpgrp) dm_procs.append( _envContainer(sp, stdout_fp) ) if globals().has_key('currentdevmgrs'): globals()['currentdevmgrs'].append(dm_procs) else: globals()['currentdevmgrs'] = dm_procs dom = attach(domain_name) return dom