コード例 #1
0
def main(cp=None, return_entries=False):
    """
    Main method for the osg-info-wrapper script.  This script safely runs the
    plugin and provider modules, caching where necessary, and combines it with
    the static data.  It then outputs the final GLUE information for this site.
    """

    log.debug("Starting up the osg-info-wrapper.")
    if cp == None:
        cp = config()

    temp_dir = os.path.expandvars(cp_get(cp, "gip", "temp_dir", \
        gipDir("$GIP_LOCATION/var/tmp", '/var/cache/gip')))
    plugin_dir = os.path.expandvars(cp_get(cp, "gip", "plugin_dir", \
        gipDir("$GIP_LOCATION/plugins", '/usr/libexec/gip/plugins')))
    provider_dir = os.path.expandvars(cp_get(cp, "gip", "provider_dir", \
        gipDir("$GIP_LOCATION/providers", '/usr/libexec/gip/providers')))
    static_dir = os.path.expandvars(cp_get(cp, "gip", "static_dir", \
        gipDir("$GIP_LOCATION/var/ldif", '/etc/gip/ldif.d')))

    # Make sure that our directories exist.
    create_if_not_exist(temp_dir, plugin_dir, provider_dir, static_dir)

    # Load up our add, alter, and delete attributes
    add_attributes = os.path.expandvars(cp_get(cp, "gip", \
        "add_attributes", vdtDir("$VDT_LOCATION/gip/etc/add-attributes.conf",
                                 '/etc/gip/add-attributes.conf')))
    alter_attributes = os.path.expandvars(cp_get(cp, "gip", \
        "alter_attributes", vdtDir("$VDT_LOCATION/gip/etc/alter-attributes.conf",
                                   '/etc/gip/alter-attributes.conf')))
    remove_attributes = os.path.expandvars(cp_get(cp, "gip", \
        "remove_attributes", vdtDir("$VDT_LOCATION/gip/etc/remove-attributes.conf",
                                    '/etc/gip/remove-attributes.conf')))

    # Flush the cache if appropriate
    do_flush_cache = cp_getBoolean(cp, "gip", "flush_cache", False)
    if do_flush_cache:
        log.info("Flushing cache upon request.")
        flush_cache(temp_dir)

    # Load up our parameters
    freshness = cp_getInt(cp, "gip", "freshness", 300)
    cache_ttl = cp_getInt(cp, "gip", "cache_ttl", 600)
    response = cp_getInt(cp, "gip", "response", 240)
    timeout = cp_getInt(cp, "gip", "timeout", 240)

    try:
        os.setpgrp()
    except OSError, oe:
        # If launched from a batch system (condor), we might not have perms
        if oe.errno != 1:
            raise
コード例 #2
0
ファイル: osg_info_wrapper.py プロジェクト: holzman/gip
def main(cp = None, return_entries=False):
    """
    Main method for the osg-info-wrapper script.  This script safely runs the
    plugin and provider modules, caching where necessary, and combines it with
    the static data.  It then outputs the final GLUE information for this site.
    """
    
    log.debug("Starting up the osg-info-wrapper.")
    if cp == None:
        cp = config()

    temp_dir = os.path.expandvars(cp_get(cp, "gip", "temp_dir", \
        gipDir("$GIP_LOCATION/var/tmp", '/var/cache/gip'))) 
    plugin_dir = os.path.expandvars(cp_get(cp, "gip", "plugin_dir", \
        gipDir("$GIP_LOCATION/plugins", '/usr/libexec/gip/plugins')))
    provider_dir = os.path.expandvars(cp_get(cp, "gip", "provider_dir", \
        gipDir("$GIP_LOCATION/providers", '/usr/libexec/gip/providers')))
    static_dir = os.path.expandvars(cp_get(cp, "gip", "static_dir", \
        gipDir("$GIP_LOCATION/var/ldif", '/etc/gip/ldif.d')))

    # Make sure that our directories exist.
    create_if_not_exist(temp_dir, plugin_dir, provider_dir, static_dir)

    # Load up our add, alter, and delete attributes
    add_attributes = os.path.expandvars(cp_get(cp, "gip", \
        "add_attributes", vdtDir("$VDT_LOCATION/gip/etc/add-attributes.conf",
                                 '/etc/gip/add-attributes.conf')))
    alter_attributes = os.path.expandvars(cp_get(cp, "gip", \
        "alter_attributes", vdtDir("$VDT_LOCATION/gip/etc/alter-attributes.conf",
                                   '/etc/gip/alter-attributes.conf')))
    remove_attributes = os.path.expandvars(cp_get(cp, "gip", \
        "remove_attributes", vdtDir("$VDT_LOCATION/gip/etc/remove-attributes.conf",
                                    '/etc/gip/remove-attributes.conf')))

    # Flush the cache if appropriate
    do_flush_cache = cp_getBoolean(cp, "gip", "flush_cache", False)
    if do_flush_cache:
        log.info("Flushing cache upon request.")
        flush_cache(temp_dir)

    # Load up our parameters
    freshness = cp_getInt(cp, "gip", "freshness", 300)
    cache_ttl = cp_getInt(cp, "gip", "cache_ttl", 600)
    response  = cp_getInt(cp, "gip", "response",  240)
    timeout = cp_getInt(cp, "gip",   "timeout",   240)

    try:
        os.setpgrp()
    except OSError, oe:
        # If launched from a batch system (condor), we might not have perms
        if oe.errno != 1:
            raise
コード例 #3
0
ファイル: osg_info_wrapper.py プロジェクト: bbockelm/gip
def _run_child(executable, orig_filename, timeout):
    log.info("Running module %s" % executable)
    os.setpgrp()
    pgrp = os.getpgrp()
    filename = '%s.%s' % (orig_filename, pgrp)
    def cleanup_handler(pid):
        try:
            os.unlink(filename)
        except:
            pass
        try:
            os.unlink(orig_filename)
        except:
            pass
        log.warning("The module %s timed out!" % executable)
        log.warning("Attempting to kill pgrp %i" % pgrp)
        try:
            os.kill(pid, signal.SIGKILL)
            os.killpg(pgrp, signal.SIGKILL)
        finally:
            log.warning("Exiting with status %i" % os.EX_SOFTWARE)
            os._exit(os.EX_SOFTWARE)
    log.debug("Set a %.2f second timeout." % timeout)
    t1 = -time.time()
    module_log_loc = os.path.expandvars(gipDir("$GIP_LOCATION/var/logs/module.log",
                                               '/var/log/gip/module.log'))
    try:
        sys.stderr = open(module_log_loc, 'a')
    except:
        log.warning("Unable to open %s; this might be a permissions error in" \
            " your GIP install if you are running as daemon." % module_log_loc)
        log.warning("Sending stderr to /dev/null")
        sys.stderr = open("/dev/null", "a")
    exec_name = executable.split('/')[-1]
    pid = os.spawnl(os.P_NOWAIT, "/bin/sh", exec_name, "-c", "%s > %s" % \
        (executable, filename))
    exit_code = None
    while t1+time.time() < timeout:
        time.sleep(.1)
        status = os.waitpid(pid, os.WNOHANG)
        if status[0] == pid: # If subprocess not done, status==(0, 0)
            exit_code = os.WEXITSTATUS(status[1])
            break
    if exit_code == None:
        log.debug("Pid %i, cleaning up" % os.getpid())
        cleanup_handler(pid)
    if exit_code == 0:
        log.debug("Pid %i, finishing successfully" % os.getpid())
        log.info("Executable %s ran successfully." % executable)
        if not os.path.exists(filename):
            log.error("Output file %s does not exist." % filename)
            os._exit(os.EX_DATAERR)
        try:
            os.rename(filename, orig_filename)
        except:
            os._exit(os.EX_CANTCREAT)
    else:
        log.info("Executable %s died with exit code %s" % (executable, \
            str(exit_code)))
        os._exit(exit_code)
    os._exit(os.EX_OK)
コード例 #4
0
def _run_child(executable, orig_filename, timeout):
    log.info("Running module %s" % executable)
    os.setpgrp()
    pgrp = os.getpgrp()
    filename = '%s.%s' % (orig_filename, pgrp)

    def cleanup_handler(pid):
        try:
            os.unlink(filename)
        except:
            pass
        try:
            os.unlink(orig_filename)
        except:
            pass
        log.warning("The module %s timed out!" % executable)
        log.warning("Attempting to kill pgrp %i" % pgrp)
        try:
            os.kill(pid, signal.SIGKILL)
            os.killpg(pgrp, signal.SIGKILL)
        finally:
            log.warning("Exiting with status %i" % os.EX_SOFTWARE)
            os._exit(os.EX_SOFTWARE)

    log.debug("Set a %.2f second timeout." % timeout)
    t1 = -time.time()
    module_log_loc = os.path.expandvars(
        gipDir("$GIP_LOCATION/var/logs/module.log", '/var/log/gip/module.log'))
    try:
        sys.stderr = open(module_log_loc, 'a')
    except:
        log.warning("Unable to open %s; this might be a permissions error in" \
            " your GIP install if you are running as daemon." % module_log_loc)
        log.warning("Sending stderr to /dev/null")
        sys.stderr = open("/dev/null", "a")
    exec_name = executable.split('/')[-1]
    pid = os.spawnl(os.P_NOWAIT, "/bin/sh", exec_name, "-c", "%s > %s" % \
        (executable, filename))
    exit_code = None
    while t1 + time.time() < timeout:
        time.sleep(.1)
        status = os.waitpid(pid, os.WNOHANG)
        if status[0] == pid:  # If subprocess not done, status==(0, 0)
            exit_code = os.WEXITSTATUS(status[1])
            break
    if exit_code == None:
        log.debug("Pid %i, cleaning up" % os.getpid())
        cleanup_handler(pid)
    if exit_code == 0:
        log.debug("Pid %i, finishing successfully" % os.getpid())
        log.info("Executable %s ran successfully." % executable)
        if not os.path.exists(filename):
            log.error("Output file %s does not exist." % filename)
            os._exit(os.EX_DATAERR)
        try:
            os.rename(filename, orig_filename)
        except:
            os._exit(os.EX_CANTCREAT)
    else:
        log.info("Executable %s died with exit code %s" % (executable, \
            str(exit_code)))
        os._exit(exit_code)
    os._exit(os.EX_OK)