Exemple #1
0
def main():
    add_common_opts()
    CONF(project='libra', version=__version__)

    logging.setup('libra')

    LOG.debug('Configuration:')
    CONF.log_opt_values(LOG, std_logging.DEBUG)

    server = Server()

    if not CONF['daemon']:
        server.main()
    else:
        pidfile = daemon.pidfile.TimeoutPIDLockFile(CONF['mgm']['pid'], 10)
        if daemon.runner.is_pidfile_stale(pidfile):
            pidfile.break_lock()

        descriptors = get_descriptors()
        context = daemon.DaemonContext(
            working_directory='/',
            umask=0o022,
            pidfile=pidfile,
            files_preserve=descriptors
        )
        if CONF['user']:
            context.uid = pwd.getpwnam(CONF['user']).pw_uid
        if CONF['group']:
            context.gid = grp.getgrnam(CONF['group']).gr_gid

        context.open()
        server.main()

    return 0
Exemple #2
0
def main():
    add_common_opts()
    CONF(project='libra', version=__version__)

    logging.setup('libra')

    LOG.debug('Configuration:')
    CONF.log_opt_values(LOG, std_logging.DEBUG)

    server = Server()

    if not CONF['daemon']:
        server.main()
    else:
        pidfile = daemon.pidfile.TimeoutPIDLockFile(CONF['mgm']['pid'], 10)
        if daemon.runner.is_pidfile_stale(pidfile):
            pidfile.break_lock()

        descriptors = get_descriptors()
        context = daemon.DaemonContext(working_directory='/',
                                       umask=0o022,
                                       pidfile=pidfile,
                                       files_preserve=descriptors)
        if CONF['user']:
            context.uid = pwd.getpwnam(CONF['user']).pw_uid
        if CONF['group']:
            context.gid = grp.getgrnam(CONF['group']).gr_gid

        context.open()
        server.main()

    return 0
Exemple #3
0
def main():
    add_common_opts()
    CONF(project='libra', version=__version__)

    logging.setup('libra')

    LOG.debug('Configuration:')
    CONF.log_opt_values(LOG, std_logging.DEBUG)

    drivers = []

    pc = get_pecan_config()

    sock = server.make_socket(CONF['admin_api']['host'],
                              CONF['admin_api']['port'],
                              CONF['admin_api']['ssl_keyfile'],
                              CONF['admin_api']['ssl_certfile'])

    if CONF['daemon']:
        pidfile = daemon.pidfile.TimeoutPIDLockFile(CONF['admin_api']['pid'],
                                                    10)
        if daemon.runner.is_pidfile_stale(pidfile):
            pidfile.break_lock()

        descriptors = get_descriptors()
        descriptors.append(sock.fileno())
        context = daemon.DaemonContext(
            working_directory='/',
            umask=0o022,
            pidfile=pidfile,
            files_preserve=descriptors
        )
        if CONF['user']:
            context.uid = pwd.getpwnam(CONF['user']).pw_uid
        if CONF['group']:
            context.gid = grp.getgrnam(CONF['group']).gr_gid
        context.open()

    try:
        check_gearman_ssl_files()
    except Exception as e:
        LOG.critical(str(e))
        return

    # Use the root logger due to lots of services using logger
    LOG.info('Starting on %s:%d', CONF.admin_api.host, CONF.admin_api.port)
    api = setup_app(pc)

    for driver in CONF['admin_api']['stats_driver']:
        drivers.append(importutils.import_class(known_drivers[driver]))

    MaintThreads(drivers)
    sys.stderr = LogStdout()

    wsgi.server(sock, api, keepalive=False)

    return 0
Exemple #4
0
def main():
    add_common_opts()
    CONF(project='libra', version=__version__)

    logging.setup('libra')

    LOG.debug('Configuration:')
    CONF.log_opt_values(LOG, std_logging.DEBUG)

    drivers = []

    pc = get_pecan_config()

    sock = server.make_socket(CONF['admin_api']['host'],
                              CONF['admin_api']['port'],
                              CONF['admin_api']['ssl_keyfile'],
                              CONF['admin_api']['ssl_certfile'])

    if CONF['daemon']:
        pidfile = daemon.pidfile.TimeoutPIDLockFile(CONF['admin_api']['pid'],
                                                    10)
        if daemon.runner.is_pidfile_stale(pidfile):
            pidfile.break_lock()

        descriptors = get_descriptors()
        descriptors.append(sock.fileno())
        context = daemon.DaemonContext(working_directory='/',
                                       umask=0o022,
                                       pidfile=pidfile,
                                       files_preserve=descriptors)
        if CONF['user']:
            context.uid = pwd.getpwnam(CONF['user']).pw_uid
        if CONF['group']:
            context.gid = grp.getgrnam(CONF['group']).gr_gid
        context.open()

    try:
        check_gearman_ssl_files()
    except Exception as e:
        LOG.critical(str(e))
        return

    # Use the root logger due to lots of services using logger
    LOG.info('Starting on %s:%d', CONF.admin_api.host, CONF.admin_api.port)
    api = setup_app(pc)

    for driver in CONF['admin_api']['stats_driver']:
        drivers.append(importutils.import_class(known_drivers[driver]))

    MaintThreads(drivers)
    sys.stderr = LogStdout()

    wsgi.server(sock, api, keepalive=False)

    return 0
Exemple #5
0
def main():
    add_common_opts()
    CONF(project='libra', version=__version__)

    logging.setup('libra')

    LOG.debug('Configuration:')
    CONF.log_opt_values(LOG, std_logging.DEBUG)

    pc = get_pecan_config()

    # NOTE: Let's not force anyone to actually have to use SSL, it shouldn't be
    # up to us to decide.
    sock = server.make_socket(CONF['api']['host'],
                              CONF['api']['port'],
                              CONF['api']['ssl_keyfile'],
                              CONF['api']['ssl_certfile'])

    if CONF['daemon']:
        pidfile = daemon.pidfile.TimeoutPIDLockFile(CONF['api']['pid'], 10)
        if daemon.runner.is_pidfile_stale(pidfile):
            pidfile.break_lock()

        descriptors = get_descriptors()
        descriptors.append(sock.fileno())

        context = daemon.DaemonContext(
            working_directory='/',
            umask=0o022,
            pidfile=pidfile,
            files_preserve=descriptors
        )
        if CONF['user']:
            context.uid = pwd.getpwnam(CONF['user']).pw_uid
        if CONF['group']:
            context.gid = grp.getgrnam(CONF['group']).gr_gid
        context.open()

    try:
        check_gearman_ssl_files()
    except Exception as e:
        LOG.critical(str(e))
        return

    LOG.info('Starting on %s:%d', CONF.api.host, CONF.api.port)
    api = setup_app(pc)
    sys.stderr = LogStdout()

    wsgi.server(sock, api, keepalive=False, debug=CONF['debug'])

    return 0
Exemple #6
0
def main():
    add_common_opts()
    CONF(project='libra', version=__version__)

    logging.setup('libra')

    LOG.debug('Configuration:')
    CONF.log_opt_values(LOG, std_logging.DEBUG)

    pc = get_pecan_config()

    # NOTE: Let's not force anyone to actually have to use SSL, it shouldn't be
    # up to us to decide.
    sock = server.make_socket(CONF['api']['host'], CONF['api']['port'],
                              CONF['api']['ssl_keyfile'],
                              CONF['api']['ssl_certfile'])

    if CONF['daemon']:
        pidfile = daemon.pidfile.TimeoutPIDLockFile(CONF['api']['pid'], 10)
        if daemon.runner.is_pidfile_stale(pidfile):
            pidfile.break_lock()

        descriptors = get_descriptors()
        descriptors.append(sock.fileno())

        context = daemon.DaemonContext(working_directory='/',
                                       umask=0o022,
                                       pidfile=pidfile,
                                       files_preserve=descriptors)
        if CONF['user']:
            context.uid = pwd.getpwnam(CONF['user']).pw_uid
        if CONF['group']:
            context.gid = grp.getgrnam(CONF['group']).gr_gid
        context.open()

    try:
        check_gearman_ssl_files()
    except Exception as e:
        LOG.critical(str(e))
        return

    LOG.info('Starting on %s:%d', CONF.api.host, CONF.api.port)
    api = setup_app(pc)
    sys.stderr = LogStdout()

    wsgi.server(sock, api, keepalive=False, debug=CONF['debug'])

    return 0
Exemple #7
0
def main():
    """ Main Python entry point for the worker utility. """

    add_common_opts()
    CONF(project='libra', version=__version__)

    logging.setup('libra')

    LOG.debug('Configuration:')
    CONF.log_opt_values(LOG, std_logging.DEBUG)

    # Import the device driver we are going to use. This will be sent
    # along to the Gearman task that will use it to communicate with
    # the device.

    selected_driver = CONF['worker']['driver']
    driver_class = importutils.import_class(known_drivers[selected_driver])

    if selected_driver == 'haproxy':
        if CONF['user']:
            user = CONF['user']
        else:
            user = getpass.getuser()

        if CONF['group']:
            group = CONF['group']
        else:
            group = None

        haproxy_service = CONF['worker:haproxy']['service']
        haproxy_logfile = CONF['worker:haproxy']['logfile']
        driver = driver_class(haproxy_services[haproxy_service],
                              user,
                              group,
                              haproxy_logfile=haproxy_logfile)
    else:
        driver = driver_class()

    server = EventServer()

    # Tasks to execute in parallel
    task_list = [(config_thread, (driver, ))]

    if not CONF['daemon']:
        server.main(task_list)
    else:

        pidfile = daemon.pidfile.TimeoutPIDLockFile(CONF['worker']['pid'], 10)
        if daemon.runner.is_pidfile_stale(pidfile):
            pidfile.break_lock()
        descriptors = get_descriptors()
        context = daemon.DaemonContext(working_directory='/etc/haproxy',
                                       umask=0o022,
                                       pidfile=pidfile,
                                       files_preserve=descriptors)
        if CONF['user']:
            context.uid = pwd.getpwnam(CONF['user']).pw_uid
        if CONF['group']:
            context.gid = grp.getgrnam(CONF['group']).gr_gid

        context.open()
        server.main(task_list)

    return 0
Exemple #8
0
def main():
    """ Main Python entry point for the worker utility. """

    add_common_opts()
    CONF(project='libra', version=__version__)

    logging.setup('libra')

    LOG.debug('Configuration:')
    CONF.log_opt_values(LOG, std_logging.DEBUG)

    # Import the device driver we are going to use. This will be sent
    # along to the Gearman task that will use it to communicate with
    # the device.

    selected_driver = CONF['worker']['driver']
    driver_class = importutils.import_class(known_drivers[selected_driver])

    if selected_driver == 'haproxy':
        if CONF['user']:
            user = CONF['user']
        else:
            user = getpass.getuser()

        if CONF['group']:
            group = CONF['group']
        else:
            group = None

        haproxy_service = CONF['worker:haproxy']['service']
        haproxy_logfile = CONF['worker:haproxy']['logfile']
        driver = driver_class(haproxy_services[haproxy_service],
                              user, group,
                              haproxy_logfile=haproxy_logfile)
    else:
        driver = driver_class()

    server = EventServer()

    # Tasks to execute in parallel
    task_list = [
        (config_thread, (driver,))
    ]

    if not CONF['daemon']:
        server.main(task_list)
    else:

        pidfile = daemon.pidfile.TimeoutPIDLockFile(CONF['worker']['pid'], 10)
        if daemon.runner.is_pidfile_stale(pidfile):
            pidfile.break_lock()
        descriptors = get_descriptors()
        context = daemon.DaemonContext(
            working_directory='/etc/haproxy',
            umask=0o022,
            pidfile=pidfile,
            files_preserve=descriptors
        )
        if CONF['user']:
            context.uid = pwd.getpwnam(CONF['user']).pw_uid
        if CONF['group']:
            context.gid = grp.getgrnam(CONF['group']).gr_gid

        context.open()
        server.main(task_list)

    return 0