Esempio n. 1
0
def init_pygdb(logpath=None):
    """Initialize pygdb with logging
    NOTE: 1) A pygdb instance is needed at the top-most-level 
             of the debugged python program
          2) When debugging NON-daemons make sure to use 'cgi-bin'
    USAGE cgi-bin:
        1) At top-most-level: cgi-bin/X.py:
            from shared.debug import init_pygdb
            pygdb = init_pygdb()
        2) In any of the descendant modules:
            import pygdb.breakpoint
            pygdb.breakpoint.set()
    """
    configuration = get_configuration_object(skip_log=True)
    if not hasattr(configuration, 'gdb_logger'):
        if not logpath:
            logpath = os.path.join(configuration.log_dir, "gdb.log")

        logger = configuration.gdb_logger = daemon_logger(
            "gdb",
            level=configuration.loglevel,
            path=logpath)
    else:
        logger = configuration.gdb_logger

    if not pygdb:
        msg = "The python pygdb module is missing"
        logger.error(msg)
        raise RuntimeError(msg)

    pygdb.breakpoint.enable(logger=logger)

    return pygdb
Esempio n. 2
0
    last_expire = time.time()
    while True:
        httpserver.handle_request()
        if last_expire + min_expire_delay < time.time():
            last_expire = time.time()
            expired = expire_rate_limit(configuration, "openid")
            logger.debug("expired: %s" % expired)
            

if __name__ == '__main__':
    configuration = get_configuration_object()
    nossl = False
    expandusername = False

    # Use separate logger
    logger = daemon_logger("openid", configuration.user_openid_log, "debug")

    # Allow configuration overrides on command line
    if sys.argv[1:]:
        nossl = sys.argv[1].lower() in ('yes', 'true', '1')
    if sys.argv[2:]:
        expandusername = sys.argv[2].lower() in ('yes', 'true', '1')
    if sys.argv[3:]:
        configuration.user_openid_address = sys.argv[3]
    if sys.argv[4:]:
        configuration.user_openid_port = int(sys.argv[4])

    if not configuration.site_enable_openid:
        err_msg = "OpenID service is disabled in configuration!"
        logger.error(err_msg)
        print err_msg
Esempio n. 3
0
            in ['debug', 'info', 'warning', 'error']:
        log_level = sys.argv[argpos]
        argpos += 1
    if sys.argv[argpos:] and len(sys.argv[argpos].split('@')) == 2:
        emailaddr = sys.argv[argpos]
        argpos += 1
    if sys.argv[argpos:]:
        try:
            delay = int(sys.argv[argpos])
        except Exception, err:
            print "Invalid delay arg: %s" % (sys.argv[argpos])
            sys.exit(1)

    # Use separate logger

    logger = daemon_logger("notify", configuration.user_notify_log, log_level)
    configuration.logger = logger

    # Start unittest if requested

    if emailaddr:
        unittest_proc = multiprocessing.Process(target=unittest,
                                                args=(configuration, emailaddr,
                                                      delay))
        unittest_proc.start()
        info_msg = "Starting unit test process: email: %s, delay: %s" \
            % (emailaddr, delay)
        print info_msg
        logger.info("(%s) %s" % (unittest_proc.pid, info_msg))

    # Allow e.g. logrotate to force log re-open after rotates
Esempio n. 4
0
        file_handle.write(html)
        file_handle.close()
    except Exception, exc:
        print 'Could not write monitor page %s: %s' % (html_file, exc)


if __name__ == '__main__':
    # Force no log init since we use separate logger
    configuration = get_configuration_object(skip_log=True)

    log_level = configuration.loglevel
    if sys.argv[1:] and sys.argv[1] in ['debug', 'info', 'warning', 'error']:
        log_level = sys.argv[1]

    # Use separate logger
    logger = daemon_logger("monitor", configuration.user_monitor_log,
                           log_level)
    configuration.logger = logger

    # Allow e.g. logrotate to force log re-open after rotates
    register_hangup_handler(configuration)

    if not configuration.site_enable_jobs:
        err_msg = "Job support is disabled in configuration!"
        logger.error(err_msg)
        print err_msg
        sys.exit(1)

    print """
Running grid monitor generator.

Set the MIG_CONF environment to the server configuration path
Esempio n. 5
0
        logger.info(msg)
    except StandardError:
        pass
    sys.exit(0)


if __name__ == '__main__':
    # Force no log init since we use separate logger
    configuration = get_configuration_object(skip_log=True)

    log_level = configuration.loglevel
    if sys.argv[1:] and sys.argv[1] in ['debug', 'info', 'warning', 'error']:
        log_level = sys.argv[1]

    # Use separate logger
    logger = daemon_logger("sshmux", configuration.user_sshmux_log, log_level)
    configuration.logger = logger

    # Allow e.g. logrotate to force log re-open after rotates
    register_hangup_handler(configuration)

    if not configuration.site_enable_jobs:
        err_msg = "Job support is disabled in configuration!"
        logger.error(err_msg)
        print err_msg
        sys.exit(1)

    print """
Running grid ssh multiplexing server for resource ssh connection reuse.

Set the MIG_CONF environment to the server configuration path
Esempio n. 6
0
    handler.passive_ports = conf.user_ftps_pasv_ports
    server = ThreadedFTPServer(
        (conf.user_ftps_address, conf.user_ftps_ctrl_port), handler)
    server.serve_forever()


if __name__ == '__main__':
    # Force no log init since we use separate logger
    configuration = get_configuration_object(skip_log=True)

    log_level = configuration.loglevel
    if sys.argv[1:] and sys.argv[1] in ['debug', 'info', 'warning', 'error']:
        log_level = sys.argv[1]

    # Use separate logger
    logger = daemon_logger("ftps", configuration.user_ftps_log, log_level)
    configuration.logger = logger

    # Allow e.g. logrotate to force log re-open after rotates
    register_hangup_handler(configuration)

    # Allow configuration overrides on command line
    nossl = False
    if sys.argv[2:]:
        configuration.user_ftps_address = sys.argv[2]
    if sys.argv[3:]:
        configuration.user_ftps_ctrl_port = int(sys.argv[3])
    if sys.argv[4:]:
        nossl = (sys.argv[4].lower() in ('1', 'true', 'yes', 'on'))

    if not configuration.site_enable_ftps:
Esempio n. 7
0
    logger.info('(%s) Exiting crontab monitor' % pid)
    return 0


if __name__ == '__main__':
    # Force no log init since we use separate logger
    configuration = get_configuration_object(skip_log=True)

    log_level = configuration.loglevel
    if sys.argv[1:] and sys.argv[1] in ['debug', 'info', 'warning',
                                        'error']:
        log_level = sys.argv[1]

    # Use separate logger

    logger = daemon_logger('cron', configuration.user_cron_log,
                           log_level)
    configuration.logger = logger

    # Allow e.g. logrotate to force log re-open after rotates
    register_hangup_handler(configuration)

    # Allow clean shutdown on SIGINT only to main process
    signal.signal(signal.SIGINT, stop_handler)

    if not configuration.site_enable_crontab:
        err_msg = "Cron support is disabled in configuration!"
        logger.error(err_msg)
        print err_msg
        sys.exit(1)

    print '''This is the MiG cron handler daemon which monitors user crontab
Esempio n. 8
0
def handle_stop(signum, stack):
    print "Got signal %s - fake ctrl-c" % signum
    raise KeyboardInterrupt


if __name__ == '__main__':
    # Force no log init since we use separate logger
    configuration = get_configuration_object(skip_log=True)

    log_level = configuration.loglevel
    if sys.argv[1:] and sys.argv[1] in ['debug', 'info', 'warning', 'error']:
        log_level = sys.argv[1]

    # Use separate logger
    logger = daemon_logger("vmproxy", configuration.user_vmproxy_log,
                           log_level)
    configuration.logger = logger

    # Allow e.g. logrotate to force log re-open after rotates
    register_hangup_handler(configuration)

    # Allow clean exit
    signal.signal(signal.SIGTERM, handle_stop)

    if not configuration.site_enable_vmachines:
        err_msg = "VMachines and proxy helper is disabled in configuration!"
        logger.error(err_msg)
        print err_msg
        sys.exit(1)

    print """
Esempio n. 9
0
    handler.authorizer = authorizer
    handler.abstracted_fs = MiGRestrictedFilesystem
    handler.passive_ports = range(conf.user_ftps_pasv_ports[0],
                                  conf.user_ftps_pasv_ports[1])
    
    server = FTPServer((conf.user_ftps_address, conf.user_ftps_ctrl_port),
                       handler)
    server.serve_forever()
        

if __name__ == '__main__':
    configuration = get_configuration_object()
    nossl = False

    # Use separate logger
    logger = daemon_logger("ftps", configuration.user_ftps_log, "debug")

    # Allow configuration overrides on command line
    if sys.argv[1:]:
        nossl = bool(sys.argv[1])
    if sys.argv[2:]:
        configuration.user_ftps_address = sys.argv[2]
    if sys.argv[3:]:
        configuration.user_ftps_ctrl_port = int(sys.argv[3])

    if not configuration.site_enable_ftps:
        err_msg = "FTPS access to user homes is disabled in configuration!"
        logger.error(err_msg)
        print err_msg
        sys.exit(1)
    print """
Esempio n. 10
0
                                        daemon_conf['host_rsa_key'],
                                        daemon_conf,])
        worker.start()
        if last_expire + min_expire_delay < time.time():
            last_expire = time.time()
            expired = expire_rate_limit(configuration, "sftp-*")
            logger.debug("Expired rate limit entries: %s" % expired)
        


if __name__ == "__main__":
    configuration = get_configuration_object()

    # Use separate logger

    logger = daemon_logger("sftp", configuration.user_sftp_log, "info")
    
    # Allow configuration overrides on command line
    if sys.argv[1:]:
        configuration.user_sftp_address = sys.argv[1]
    if sys.argv[2:]:
        configuration.user_sftp_port = int(sys.argv[2])

    if not configuration.site_enable_sftp:
        err_msg = "SFTP access to user homes is disabled in configuration!"
        logger.error(err_msg)
        print err_msg
        sys.exit(1)
    print """
Running grid sftp server for user sftp access to their MiG homes.
Esempio n. 11
0
INVALID_MARKER = "_OUT_OF_BOUNDS_"

if __name__ == '__main__':
    configuration = get_configuration_object()
    verbose = False
    log_level = configuration.loglevel
    if sys.argv[1:] and sys.argv[1] in ['debug', 'info', 'warning', 'error']:
        log_level = sys.argv[1]
        verbose = True

    if verbose:
        print os.environ.get('MIG_CONF', 'DEFAULT'), configuration.server_fqdn

    # Use separate logger
    logger = daemon_logger("chkuserroot", configuration.user_chkuserroot_log,
                           log_level)
    configuration.logger = logger

    # Allow e.g. logrotate to force log re-open after rotates
    register_hangup_handler(configuration)

    if verbose:
        print '''This is simple user chroot check helper daemon which just
prints the real path for all allowed path requests and the invalid marker for
illegal ones.

Set the MIG_CONF environment to the server configuration path
unless it is available in mig/server/MiGserver.conf
'''
        print 'Starting chkuserroot helper daemon - Ctrl-C to quit'
Esempio n. 12
0
        if not self._transport:
            self._transport = Transport(self)
        return self._transport


if __name__ == '__main__':
    # We need to manualy extract MiG conf path since running from openssh
    conf_path = os.path.join(os.path.dirname(__file__), 'MiGserver.conf')
    os.putenv('MIG_CONF', conf_path)
    # Force no log init since we use separate logger
    configuration = get_configuration_object(skip_log=True)
    log_level = configuration.loglevel
    if sys.argv[1:] and sys.argv[1] in ['debug', 'info', 'warning', 'error']:
        log_level = sys.argv[1]
    # Use separate logger
    logger = daemon_logger('sftp-subsys', configuration.user_sftp_subsys_log,
                           log_level)
    configuration.logger = logger
    # Allow e.g. logrotate to force log re-open after rotates
    register_hangup_handler(configuration)
    pid = os.getpid()
    logger.info('(%d) Basic sftp subsystem initialized' % pid)
    # Lookup chroot exceptions once and for all
    chroot_exceptions = user_chroot_exceptions(configuration)
    # Any extra chmod exceptions here - we already cover invisible_path check
    # in acceptable_chmod helper.
    chmod_exceptions = []
    configuration.daemon_conf = {
        'root_dir': os.path.abspath(configuration.user_home),
        'chroot_exceptions': chroot_exceptions,
        'chmod_exceptions': chmod_exceptions,
        'allow_password': '******' in configuration.user_sftp_auth,
Esempio n. 13
0
            logger.info('handle %(status)s transfer %(transfer_id)s' %
                        transfer_dict)
            handle_transfer(configuration, client_id, transfer_dict)


if __name__ == '__main__':
    # Force no log init since we use separate logger
    configuration = get_configuration_object(skip_log=True)

    log_level = configuration.loglevel
    if sys.argv[1:] and sys.argv[1] in ['debug', 'info', 'warning', 'error']:
        log_level = sys.argv[1]

    # Use separate logger

    logger = daemon_logger('transfers', configuration.user_transfers_log,
                           log_level)
    configuration.logger = logger

    # Allow e.g. logrotate to force log re-open after rotates
    register_hangup_handler(configuration)

    if not configuration.site_enable_transfers:
        err_msg = "Data transfers are disabled in configuration!"
        logger.error(err_msg)
        print err_msg
        sys.exit(1)

    print '''This is the MiG data transfer handler daemon which runs requested
data transfers in the background on behalf of the users. It monitors the saved
data transfer files for changes and launches external client processes to take
care of the tranfers, writing status and output to a transfer output directory
Esempio n. 14
0
    logger.info('Listening on %(host)s (%(port)s)' % config)

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
        # forward KeyboardInterrupt to main thread
        raise

if __name__ == "__main__":
    configuration = get_configuration_object()
    nossl = False

    # Use separate logger - cherrypy hijacks root logger

    logger = daemon_logger("webdavs", configuration.user_davs_log, "DEBUG")

    # Allow configuration overrides on command line
    if sys.argv[1:]:
        nossl = bool(sys.argv[1])
    if sys.argv[2:]:
        configuration.user_davs_address = sys.argv[2]
    if sys.argv[3:]:
        configuration.user_davs_port = int(sys.argv[3])
        
    # Web server doesn't allow empty string alias for all interfaces
    if configuration.user_davs_address == '':
        configuration.user_davs_address = '0.0.0.0'

    configuration.dav_cfg = {
        'nossl': nossl,