示例#1
0
def manager_version():
    try:
        if os.path.exists("/var/lib/gwms-factory/work-dir/checksum.factory"):
            chksum_file = "checksum.factory"
        elif os.path.exists(
                "/var/lib/gwms-frontend/vofrontend/checksum.frontend"):
            chksum_file = "checksum.frontend"
        from glideinwms.lib import glideinWMSVersion
    except ImportError:
        return "UNKNOWN"
    try:
        return glideinWMSVersion.GlideinWMSDistro(chksum_file).version()
    except RuntimeError:
        return "UNKNOWN"
示例#2
0
def main(startup_dir):
    """
    Reads in the configuration file and starts up the factory

    @type startup_dir: String
    @param startup_dir: Path to glideinsubmit directory
    """
    # Force integrity checks on all condor operations
    glideFactoryLib.set_condor_integrity_checks()

    glideFactoryInterface.factoryConfig.lock_dir = os.path.join(startup_dir,
                                                                "lock")
    glideFactoryConfig.factoryConfig.glidein_descript_file = \
        os.path.join(startup_dir,
                     glideFactoryConfig.factoryConfig.glidein_descript_file)
    glideinDescript = glideFactoryConfig.GlideinDescript()
    frontendDescript = glideFactoryConfig.FrontendDescript()

    # set factory_collector at a global level, since we do not expect it to change
    glideFactoryInterface.factoryConfig.factory_collector = glideinDescript.data['FactoryCollector']

    # Setup the glideFactoryLib.factoryConfig so that we can process the
    # globals classads
    glideFactoryLib.factoryConfig.config_whoamI(
        glideinDescript.data['FactoryName'],
        glideinDescript.data['GlideinName'])
    glideFactoryLib.factoryConfig.config_dirs(
        startup_dir, glideinDescript.data['LogDir'],
        glideinDescript.data['ClientLogBaseDir'],
        glideinDescript.data['ClientProxiesBaseDir'])

    # Set the Log directory
    logSupport.log_dir = os.path.join(glideinDescript.data['LogDir'], "factory")

    # Configure factory process logging
    process_logs = eval(glideinDescript.data['ProcessLogs'])
    for plog in process_logs:
        if 'ADMIN' in plog['msg_types'].upper():
            logSupport.add_processlog_handler("factoryadmin",
                                              logSupport.log_dir,
                                              "DEBUG,INFO,WARN,ERR",
                                              plog['extension'],
                                              int(float(plog['max_days'])),
                                              int(float(plog['min_days'])),
                                              int(float(plog['max_mbytes'])),
                                              int(float(plog['backup_count'])),
                                              plog['compression'])
        else:
            logSupport.add_processlog_handler("factory",
                                              logSupport.log_dir,
                                              plog['msg_types'],
                                              plog['extension'],
                                              int(float(plog['max_days'])),
                                              int(float(plog['min_days'])),
                                              int(float(plog['max_mbytes'])),
                                              int(float(plog['backup_count'])),
                                              plog['compression'])
    logSupport.log = logging.getLogger("factory")
    logSupport.log.info("Logging initialized")

    if (glideinDescript.data['Entries'].strip() in ('', ',')):
        # No entries are enabled. There is nothing to do. Just exit here.
        log_msg = "No Entries are enabled. Exiting."

        logSupport.log.error(log_msg)
        sys.exit(1)

    write_descript(glideinDescript, frontendDescript, os.path.join(startup_dir, 'monitor/'))

    try:
        os.chdir(startup_dir)
    except:
        logSupport.log.exception("Failed starting Factory. Unable to change to startup_dir: ")
        raise

    try:
        if (is_file_old(glideinDescript.default_rsakey_fname,
                        int(glideinDescript.data['OldPubKeyGraceTime']))):
            # First backup and load any existing key
            logSupport.log.info("Backing up and loading old key")
            glideinDescript.backup_and_load_old_key()
            # Create a new key for this run
            logSupport.log.info("Recreating and loading new key")
            glideinDescript.load_pub_key(recreate=True)
        else:
            # Key is recent enough. Just reuse it.
            logSupport.log.info("Key is recent enough, reusing for this run")
            glideinDescript.load_pub_key(recreate=False)
            logSupport.log.info("Loading old key")
            glideinDescript.load_old_rsa_key()
    except RSAError as e:
        logSupport.log.exception("Failed starting Factory. Exception occurred loading factory keys: ")
        key_fname = getattr(e, 'key_fname', None)
        cwd = getattr(e, 'cwd', None)
        if key_fname and cwd:
            logSupport.log.error("Failed to load RSA key %s with current working direcotry %s", key_fname, cwd)
            logSupport.log.error("If you think the rsa key might be corrupted, try to remove it, and then reconfigure the factory to recreate it")
        raise
    except IOError as ioe:
        logSupport.log.exception("Failed starting Factory. Exception occurred loading factory keys: ")
        if ioe.filename == 'rsa.key' and ioe.errno == 2:
             logSupport.log.error("Missing rsa.key file. Please, reconfigure the factory to recreate it")
        raise
    except:
        logSupport.log.exception("Failed starting Factory. Exception occurred loading factory keys: ")
        raise

    glideFactoryMonitorAggregator.glideFactoryMonitoring.monitoringConfig.my_name = "%s@%s" % (glideinDescript.data['GlideinName'],
               glideinDescript.data['FactoryName'])

    glideFactoryInterface.factoryConfig.advertise_use_tcp = (glideinDescript.data['AdvertiseWithTCP'] in ('True', '1'))
    glideFactoryInterface.factoryConfig.advertise_use_multi = (glideinDescript.data['AdvertiseWithMultiple'] in ('True', '1'))
    sleep_time = int(glideinDescript.data['LoopDelay'])
    advertize_rate = int(glideinDescript.data['AdvertiseDelay'])
    restart_attempts = int(glideinDescript.data['RestartAttempts'])
    restart_interval = int(glideinDescript.data['RestartInterval'])

    try:
        glideinwms_dir = os.path.dirname(os.path.dirname(sys.argv[0]))
        glideFactoryInterface.factoryConfig.glideinwms_version = glideinWMSVersion.GlideinWMSDistro(glideinwms_dir, 'checksum.factory').version()
    except:
        logSupport.log.exception("Non critical Factory error. Exception occurred while trying to retrieve the glideinwms version: ")

    entries = sorted(glideinDescript.data['Entries'].split(','))

    glideFactoryMonitorAggregator.monitorAggregatorConfig.config_factory(
        os.path.join(startup_dir, "monitor"), entries,
        log=logSupport.log
    )

    # create lock file
    pid_obj = glideFactoryPidLib.FactoryPidSupport(startup_dir)

    increase_process_limit()

    # start
    try:
        pid_obj.register()
    except glideFactoryPidLib.pidSupport.AlreadyRunning as err:
        pid_obj.load_registered()
        logSupport.log.exception("Failed starting Factory. Instance with pid %s is aready running. Exception during pid registration: %s" %
                                 (pid_obj.mypid, err))
        raise
    try:
        try:
            spawn(sleep_time, advertize_rate, startup_dir, glideinDescript,
                  frontendDescript, entries, restart_attempts, restart_interval)
        except KeyboardInterrupt as e:
            raise e
        except HUPException as e:
            # inside spawn(), outermost try will catch HUPException, 
            # then the code within the finally will run
            # which will terminate glideFactoryEntryGroup children processes
            # and then the following 3 lines will be executed.
            logSupport.log.info("Received SIGHUP, reload config uid = %d" % os.getuid())
            # must empty the lock file so that when the thread returns from reconfig_glidein and 
            # begins from the beginning, it will not error out which will happen 
            # if the lock file is not empty
            pid_obj.relinquish()
            os.execv(os.path.join(FACTORY_DIR, "../creation/reconfig_glidein"),
                     ['reconfig_glidein', '-update_scripts', 'no', '-sighupreload', '-xml', '/etc/gwms-factory/glideinWMS.xml'])
        except:
            logSupport.log.exception("Exception occurred spawning the factory: ")
    finally:
        pid_obj.relinquish()