def stop( self ): console_logger.info( "Stopping DRM4G .... " ) console_logger.debug( "Stopping gwd .... " ) if self.is_alive(): with open(self.gwd_pid) as pid_file: pid = next(pid_file) processes_to_kill = [pid] while processes_to_kill: for process in processes_to_kill: try: cmd = "ps ho pid --ppid %s" % (process) out , _ = exec_cmd( cmd ) processes_to_kill = [line.lstrip() for line in out.splitlines()] + processes_to_kill processes_to_kill.remove(process) os.kill( int(process), signal.SIGTERM ) except OSError as exc: if "No such process" in str(exc): continue raise while self.is_alive() : time.sleep(1) try: os.remove(self.gwd_pid) except OSError: console_logger.error(" '%s' does not exist", self.gwd_pid) console_logger.info( " OK" ) else: console_logger.info(" WARNING: daemon is already stopped")
def run(arg): try: daemon = Daemon() if not daemon.is_alive(): raise Exception('DRM4G is stopped. ') if arg['submit']: dependencies = '-d "%s"' % ' '.join( arg['--dep']) if arg['--dep'] else '' number_of_tasks = '-n %s' % arg['--ntasks'] if arg[ '--ntasks'] else '' cmd = 'gwsubmit %s -v %s %s' % (dependencies, arg['<template>'], number_of_tasks) elif arg['list']: cmd = 'gwps -o Jsetxjh ' if arg['<job_id>']: cmd = cmd + arg['<job_id>'][0] elif arg['history']: cmd = 'gwhistory %s' % (arg['<job_id>'][0]) elif arg['log']: directory = join( DRM4G_DIR_VAR, '%d00-%d99' % (int(int(float(arg['<job_id>'][0])) / 100), int(int(float(arg['<job_id>'][0])) / 100)), arg['<job_id>'][0], 'job.log') if not exists(directory): raise Exception('There is not a log available for this job.') cmd = 'cat %s' % (directory) else: cmd = 'gwkill -9 %s' % (' '.join(arg['<job_id>'])) out, err = exec_cmd(cmd) console_logger.info(out) if err: console_logger.info(err) except Exception as err: console_logger.error(str(err))
def run(arg): try: daemon = Daemon() daemon.stop() sleep(2.0) daemon.clear() except Exception as err: console_logger.error(str(err))
def run(arg): try: Daemon().stop() agent = Agent() if agent.is_alive(): agent.stop() except Exception as err: console_logger.error(str(err))
def update_hosts(self): """ Forces the host list to be updated """ try: GwImMad().do_DISCOVER("discover - - -", False) #GwImMad().do_MONITOR("monitor 2 %s -" % resname)#, False) except Exception as err: console_logger.error( "Could not update hosts:\n%s", str(err))
def run(arg): try: daemon = Daemon() if not daemon.is_alive(): raise Exception('DRM4G is stopped.') config = Configuration() config.load() if config.check(): raise Exception("Review the configuration of '%s'." % (arg['<resource_name>'])) if arg['<resource_name>'] not in config.resources: raise Exception("'%s' is not a configured resource." % (arg['<resource_name>'])) lrms = config.resources.get(arg['<resource_name>'])['lrms'] communicator = config.resources.get( arg['<resource_name>'])['communicator'] if lrms != 'cream' and lrms != 'rocci' and communicator == 'local': raise Exception("'%s' does not have an identity to configure." % (arg['<resource_name>'])) if lrms == 'cream' or lrms == 'rocci': comm = config.make_communicators()[arg['<resource_name>']] if communicator == 'op_ssh': #paramiko will always be used to renew the grid certificate config.resources.get( arg['<resource_name>'])['communicator'] = 'pk_ssh' comm = config.make_communicators()[arg['<resource_name>']] proxy = Proxy(config.resources[arg['<resource_name>']], comm) config.resources.get( arg['<resource_name>'])['communicator'] = communicator config.make_communicators() if communicator != 'local': agent = Agent(config.resources[arg['<resource_name>']]) if arg['init']: if communicator != 'local': agent.start() agent.add_key(arg['--lifetime']) agent.copy_key() if lrms == 'cream' or lrms == 'rocci': proxy.configure() proxy.create(arg['--lifetime']) elif arg['delete']: if lrms == 'cream' or lrms == 'rocci': proxy.destroy() if communicator != 'local': agent.delete_key() else: if communicator != 'local': agent.list_key() if lrms == 'cream' or lrms == 'rocci': proxy.check() except Exception as err: console_logger.error(str(err))
def run(arg): try: daemon = Daemon() if not daemon.is_alive(): raise Exception('DRM4G is stopped.') cmd = 'gwhost ' if arg['<hid>']: cmd = cmd + arg['<hid>'] out, err = exec_cmd(cmd) console_logger.info(out) if err: console_logger.info(err) except Exception as err: console_logger.error(str(err))
def _start(): # 's' option generates Bourne shell commands on stdout out , err = exec_cmd( 'ssh-agent -s ' ) console_logger.debug( out ) match = re.search( 'SSH_AUTH_SOCK=(?P<SSH_AUTH_SOCK>[^;]+);.*' \ + 'SSH_AGENT_PID=(?P<SSH_AGENT_PID>\d+);', out, re.DOTALL) if match : console_logger.debug( " OK" ) self.agent_env = match.groupdict() console_logger.debug( ' Agent pid: %s', self.agent_env['SSH_AGENT_PID']) else: console_logger.error( err ) raise Exception( ' Cannot determine agent data from output: %s' % out ) with open( self.agent_file , 'w') as f: f.write( self.agent_env['SSH_AGENT_PID'] + '\n' + self.agent_env['SSH_AUTH_SOCK'] )
def check_frontends( self ) : """ Check if the frontend of a given resource is reachable. """ self.check( ) communicators = self.config.make_communicators() for resname, resdict in sorted( self.config.resources.items() ) : if resdict[ 'enable' ] == 'true' : communicator = communicators.get( resname ) try : # if resdict[ 'communicator' ] == 'op_ssh' : # #it will use im's socket instead of creating a new one # communicator.parent_module = 'im' # communicator.configfile = join(DRM4G_DIR, 'etc', 'openssh_im.conf') communicator.connect() console_logger.info( "Resource '%s' :", resname ) console_logger.info( "--> The front-end '%s' is accessible\n", communicator.frontend ) except Exception : console_logger.error( "Resource '%s' :", resname ) console_logger.error( "--> The front-end '%s' is not accessible\n", communicator.frontend )
def run(arg): try: config = Configuration() resource = Resource(config) if arg['edit']: resource.edit() else: daemon = Daemon() if not daemon.is_alive(): raise Exception('DRM4G is stopped.') elif arg['check']: resource.check_frontends() elif arg['create']: resource.create_vms() elif arg['destroy']: resource.destroy_vms() elif arg['--all']: resource.list_resources() else: resource.list() except Exception as err: console_logger.error(str(err))
def run(arg): try: Daemon().start() except Exception as err: console_logger.error(str(err))