Пример #1
0
def persistent_connection(resource_config, logger):
    """Keep running a persistent master connection"""

    sleep_secs = 300
    hostname = resource_config['HOSTURL']

    # Mark this session as a multiplexing master to avoid races:
    # see further details in shared/ssh.py

    resource_config['SSHMULTIPLEXMASTER'] = True
    while True:
        try:
            logger.debug('connecting to %s' % hostname)
            (exit_code,
             executed) = execute_on_resource('sleep %d' % sleep_secs, False,
                                             resource_config, logger)
            if 0 != exit_code:
                msg = 'ssh multiplex %s: %s returned %i' % \
                      (hostname, executed, exit_code)
                print msg

                # make sure control_socket was cleaned up

                host = resource_config['HOSTURL']
                identifier = resource_config['HOSTIDENTIFIER']
                unique_id = '%s.%s' % (host, identifier)
                control_socket = \
                    os.path.join(configuration.resource_home,
                                 unique_id, 'ssh-multiplexing')
                try:
                    os.remove(control_socket)
                except:
                    pass
                sleep(sleep_secs)
        except StandardError, err:

            msg = '%s thread caught exception (%s) - retry later' % \
                  (hostname, err)
            print msg
            logger.error(msg)
            sleep(sleep_secs)
Пример #2
0
def persistent_connection(resource_config, logger):
    """Keep running a persistent master connection"""

    sleep_secs = 300
    hostname = resource_config['HOSTURL']

    # Mark this session as a multiplexing master to avoid races:
    # see further details in shared/ssh.py

    resource_config['SSHMULTIPLEXMASTER'] = True
    while True:
        try:
            logger.debug('connecting to %s' % hostname)
            (exit_code, executed) = execute_on_resource('sleep %d'
                     % sleep_secs, False, resource_config, logger)
            if 0 != exit_code:
                msg = 'ssh multiplex %s: %s returned %i' % (hostname,
                        executed, exit_code)
                print msg

                # make sure control_socket was cleaned up

                host = resource_config['HOSTURL']
                identifier = resource_config['HOSTIDENTIFIER']
                unique_id = '%s.%s' % (host, identifier)
                control_socket = \
                    os.path.join(configuration.resource_home,
                                 unique_id, 'ssh-multiplexing')
                try:
                    os.remove(control_socket)
                except:
                    pass
                sleep(sleep_secs)
        except StandardError, err:

            msg = '%s thread caught exception (%s) - retry later'\
                 % (hostname, err)
            print msg
            logger.error(msg)
            sleep(sleep_secs)
Пример #3
0
ssh_command = \
    'ssh -X %s@%s \\"cd %s; mv -f %s job-dir_%s; cd job-dir_%s; chmod +x %s; bash -c \'./%s\'\\"'\
     % (
    exe['execution_user'],
    exe['execution_node'],
    exe['execution_dir'],
    dest_filename,
    localjobname,
    localjobname,
    dest_filename,
    dest_filename,
    )
logger.info('execute_on_resource: %s' % ssh_command)
exit_code = -1
try:
    (exit_code, executed_command) = execute_on_resource(ssh_command,
            False, resource_config, logger)
except Exception, e:
    logger.error('Exception executing remote SSH from requestinteractivejob.py: %s '
                  % e)
    o.reply_and_exit(o.ERROR)

if exit_code != 0:
    logger.error('Error executing interactive job script on resource: %s command: %s exit code: %s'
                  % (unique_resource_name, executed_command, exit_code))
    o.reply_and_exit(o.ERROR)

o.out('requestinteractivejob OK. The job was started on the resource: %s exe: %s remote addr: %s'
       % (unique_resource_name, exe, os.getenv('REMOTE_ADDR')))
o.reply_and_exit(o.OK)
Пример #4
0
ssh_command = \
    'ssh -X %s@%s \\"cd %s; mv -f %s job-dir_%s; cd job-dir_%s; chmod +x %s; bash -c \'./%s\'\\"'\
     % (
    exe_conf['execution_user'],
    exe_conf['execution_node'],
    exe_conf['execution_dir'],
    dest_filename,
    localjobname,
    localjobname,
    dest_filename,
    dest_filename,
    )
logger.info('execute_on_resource: %s' % ssh_command)
exit_code = -1
try:
    (exit_code, executed_command) = execute_on_resource(ssh_command,
            False, resource_conf, logger)
except Exception, e:
    logger.error('Exception executing remote SSH from requestinteractivejob.py: %s '
                  % e)
    o.reply_and_exit(o.ERROR)

if exit_code != 0:
    logger.error('Error executing interactive job script on resource: %s command: %s exit code: %s'
                  % (unique_resource_name, executed_command, exit_code))
    o.reply_and_exit(o.ERROR)

o.out('requestinteractivejob OK. The job was started on the resource: %s exe: %s remote addr: %s'
       % (unique_resource_name, exe_conf, os.getenv('REMOTE_ADDR')))
o.reply_and_exit(o.OK)