Python oslo_service.service.launch() Examples

The following are 30 code examples of oslo_service.service.launch(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_service.service , or try the search function .
Example #1
Source File: compute.py    From zun with Apache License 2.0 6 votes vote down vote up
def main():
    priv_context.init(root_helper=shlex.split(utils.get_root_helper()))
    zun_service.prepare_service(sys.argv)

    LOG.info('Starting server in PID %s', os.getpid())
    CONF.log_opt_values(LOG, logging.DEBUG)

    CONF.import_opt('topic', 'zun.conf.compute', group='compute')

    from zun.compute import manager as compute_manager
    endpoints = [
        compute_manager.Manager(),
    ]

    server = rpc_service.Service.create(CONF.compute.topic, CONF.host,
                                        endpoints, binary='zun-compute')
    launcher = service.launch(CONF, server, restart_method='mutate')
    launcher.wait() 
Example #2
Source File: agent.py    From f5-openstack-agent with Apache License 2.0 6 votes vote down vote up
def main():
    """F5 LBaaS agent for OpenStack."""
    cfg.CONF.register_opts(OPTS)
    cfg.CONF.register_opts(manager.OPTS)
    cfg.CONF.register_opts(interface.OPTS)

    config.register_agent_state_opts_helper(cfg.CONF)
    config.register_root_helper(cfg.CONF)

    common_config.init(sys.argv[1:])
    # alias for common_config.setup_logging()...
    config.setup_logging()

    mgr = manager.LbaasAgentManager(cfg.CONF)

    svc = F5AgentService(
        host=mgr.agent_host,
        topic=f5constants.TOPIC_LOADBALANCER_AGENT_V2,
        manager=mgr
    )
    service.launch(cfg.CONF, svc).wait() 
Example #3
Source File: tacker_server.py    From tacker with Apache License 2.0 6 votes vote down vote up
def main():
    # the configuration will be read into the cfg.CONF global data structure
    config.init(sys.argv[1:])
    objects.register_all()
    if not cfg.CONF.config_file:
        sys.exit(_("ERROR: Unable to find configuration file via the default"
                   " search paths (~/.tacker/, ~/, /etc/tacker/, /etc/) and"
                   " the '--config-file' option!"))

    try:
        tacker_api = service.serve_wsgi(service.TackerApiService)
        launcher = common_service.launch(cfg.CONF, tacker_api,
                                         workers=cfg.CONF.api_workers or None,
                                         restart_method='mutate')
        launcher.wait()
    except KeyboardInterrupt:
        pass
    except RuntimeError as e:
        sys.exit(_("ERROR: %s") % e) 
Example #4
Source File: health_manager.py    From senlin with Apache License 2.0 6 votes vote down vote up
def main():
    config.parse_args(sys.argv, 'senlin-health-manager')
    logging.setup(CONF, 'senlin-health-manager')
    logging.set_defaults()
    gmr.TextGuruMeditation.setup_autorun(version)
    objects.register_all()
    messaging.setup()

    from senlin.health_manager import service as health_manager

    profiler.setup('senlin-health-manager', CONF.host)
    srv = health_manager.HealthManagerService(CONF.host,
                                              consts.HEALTH_MANAGER_TOPIC)
    launcher = service.launch(CONF, srv,
                              workers=CONF.health_manager.workers,
                              restart_method='mutate')
    launcher.wait() 
Example #5
Source File: engine.py    From senlin with Apache License 2.0 6 votes vote down vote up
def main():
    config.parse_args(sys.argv, 'senlin-engine')
    logging.setup(CONF, 'senlin-engine')
    logging.set_defaults()
    gmr.TextGuruMeditation.setup_autorun(version)
    objects.register_all()
    messaging.setup()

    from senlin.engine import service as engine

    profiler.setup('senlin-engine', CONF.host)
    srv = engine.EngineService(CONF.host,
                               consts.ENGINE_TOPIC)
    launcher = service.launch(CONF, srv,
                              workers=CONF.engine.workers,
                              restart_method='mutate')
    launcher.wait() 
Example #6
Source File: conductor.py    From senlin with Apache License 2.0 6 votes vote down vote up
def main():
    config.parse_args(sys.argv, 'senlin-conductor')
    logging.setup(CONF, 'senlin-conductor')
    logging.set_defaults()
    gmr.TextGuruMeditation.setup_autorun(version)
    objects.register_all()
    messaging.setup()

    from senlin.conductor import service as conductor

    profiler.setup('senlin-conductor', CONF.host)
    srv = conductor.ConductorService(CONF.host, consts.CONDUCTOR_TOPIC)
    launcher = service.launch(CONF, srv,
                              workers=CONF.conductor.workers,
                              restart_method='mutate')
    # the following periodic tasks are intended serve as HA checking
    # srv.create_periodic_tasks()
    launcher.wait() 
Example #7
Source File: retry_scheduler.py    From barbican with Apache License 2.0 6 votes vote down vote up
def main():
    try:
        CONF = config.CONF
        CONF(sys.argv[1:], project='barbican',
             version=version.version_info.version_string)

        # Import and configure logging.
        log.setup(CONF, 'barbican-retry-scheduler')
        LOG = log.getLogger(__name__)
        LOG.debug("Booting up Barbican worker retry/scheduler node...")

        # Queuing initialization (as a client only).
        queue.init(CONF, is_server_side=False)

        service.launch(
            CONF,
            retry_scheduler.PeriodicServer(),
            restart_method='mutate'
        ).wait()
    except RuntimeError as e:
        fail(1, e) 
Example #8
Source File: worker.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
def main():
    try:
        CONF = config.CONF

        # Import and configure logging.
        log.setup(CONF, 'barbican')
        LOG = log.getLogger(__name__)
        LOG.debug("Booting up Barbican worker node...")

        # Queuing initialization
        queue.init(CONF)

        service.launch(
            CONF,
            server.TaskServer(),
            workers=CONF.queue.asynchronous_workers
        ).wait()
    except RuntimeError as e:
        fail(1, e) 
Example #9
Source File: retry_scheduler.py    From sgx-kms with Apache License 2.0 6 votes vote down vote up
def main():
    try:
        CONF = config.CONF

        # Import and configure logging.
        log.setup(CONF, 'barbican-retry-scheduler')
        LOG = log.getLogger(__name__)
        LOG.debug("Booting up Barbican worker retry/scheduler node...")

        # Queuing initialization (as a client only).
        queue.init(CONF, is_server_side=False)

        service.launch(
            CONF,
            retry_scheduler.PeriodicServer()
        ).wait()
    except RuntimeError as e:
        fail(1, e) 
Example #10
Source File: worker.py    From barbican with Apache License 2.0 6 votes vote down vote up
def main():
    try:
        CONF = config.CONF
        CONF(sys.argv[1:], project='barbican',
             version=version.version_info.version_string)

        # Import and configure logging.
        log.setup(CONF, 'barbican')
        LOG = log.getLogger(__name__)
        LOG.debug("Booting up Barbican worker node...")

        # Queuing initialization
        queue.init(CONF)

        service.launch(
            CONF,
            server.TaskServer(),
            workers=CONF.queue.asynchronous_workers,
            restart_method='mutate'
        ).wait()
    except RuntimeError as e:
        fail(1, e) 
Example #11
Source File: keystone_listener.py    From barbican with Apache License 2.0 5 votes vote down vote up
def main():
    try:
        config.setup_remote_pydev_debug()

        CONF = config.CONF
        CONF(sys.argv[1:], project='barbican',
             version=version.version_info.version_string)

        # Import and configure logging.
        log.setup(CONF, 'barbican')

        LOG = log.getLogger(__name__)
        LOG.info("Booting up Barbican Keystone listener node...")

        # Queuing initialization
        queue.init(CONF)

        if getattr(getattr(CONF, queue.KS_NOTIFICATIONS_GRP_NAME), 'enable'):
            service.launch(
                CONF,
                keystone_listener.MessageServer(CONF),
                restart_method='mutate'
            ).wait()
        else:
            LOG.info("Exiting as Barbican Keystone listener is not enabled...")
    except RuntimeError as e:
        fail(1, e) 
Example #12
Source File: test_service.py    From oslo.service with Apache License 2.0 5 votes vote down vote up
def test_launch_wrong_service_base_class(self):
        # check that services that do not subclass service.ServiceBase
        # can not be launched.
        svc = mock.Mock()
        self.assertRaises(TypeError, service.launch, self.conf, svc) 
Example #13
Source File: conductor_server.py    From tacker with Apache License 2.0 5 votes vote down vote up
def main(manager='tacker.conductor.conductor_server.Conductor'):
    init(sys.argv[1:])
    objects.register_all()
    logging.setup(CONF, "tacker")
    oslo_messaging.set_transport_defaults(control_exchange='tacker')
    logging.setup(CONF, "tacker")
    CONF.log_opt_values(LOG, logging.DEBUG)
    server = tacker_service.Service.create(
        binary='tacker-conductor',
        topic=topics.TOPIC_CONDUCTOR,
        manager=manager)
    service.launch(CONF, server, restart_method='mutate').wait() 
Example #14
Source File: service.py    From watcher with Apache License 2.0 5 votes vote down vote up
def launch(conf, service_, workers=1, restart_method='mutate'):
    return service.launch(conf, service_, workers, restart_method) 
Example #15
Source File: test_service.py    From oslo.service with Apache License 2.0 5 votes vote down vote up
def test_graceful_shutdown(self):
        # test that services are given a chance to clean up:
        svc = _Service()

        launcher = service.launch(self.conf, svc)
        # wait on 'init' so we know the service had time to start:
        svc.init.wait()

        launcher.stop()
        self.assertTrue(svc.cleaned_up)

        # make sure stop can be called more than once.  (i.e. play nice with
        # unit test fixtures in nova bug #1199315)
        launcher.stop() 
Example #16
Source File: conductor.py    From cyborg with Apache License 2.0 5 votes vote down vote up
def main():
    # Parse config file and command line options, then start logging
    cyborg_service.prepare_service(sys.argv)

    mgr = cyborg_service.RPCService('cyborg.conductor.manager',
                                    'ConductorManager',
                                    constants.CONDUCTOR_TOPIC)

    launcher = service.launch(CONF, mgr, restart_method='mutate')
    launcher.wait() 
Example #17
Source File: agent.py    From cyborg with Apache License 2.0 5 votes vote down vote up
def main():
    # Parse config file and command line options, then start logging
    cyborg_service.prepare_service(sys.argv)
    priv_context.init(root_helper=shlex.split('sudo'))

    mgr = cyborg_service.RPCService('cyborg.agent.manager',
                                    'AgentManager',
                                    constants.AGENT_TOPIC)

    launcher = service.launch(CONF, mgr, restart_method='mutate')
    launcher.wait() 
Example #18
Source File: api.py    From qinling with Apache License 2.0 5 votes vote down vote up
def main():
    try:
        config.parse_args(args=common.get_properly_ordered_parameters())
        common.print_server_info("api")
        logging.setup(CONF, 'qinling')
        # Initialize RPC configuration.
        rpc.get_transport()

        api_server = api_service.WSGIService()
        launcher = service.launch(CONF, api_server, workers=api_server.workers,
                                  restart_method='mutate')
        launcher.wait()
    except RuntimeError as excp:
        sys.stderr.write("ERROR: %s\n" % excp)
        sys.exit(1) 
Example #19
Source File: service.py    From karbor with Apache License 2.0 5 votes vote down vote up
def serve(server, workers=None):
    global _launcher
    if _launcher:
        raise RuntimeError(_('serve() can only be called once'))

    _launcher = service.launch(CONF, server, workers=workers) 
Example #20
Source File: test_service.py    From oslo.service with Apache License 2.0 5 votes vote down vote up
def test_multiple_worker(self, mock_launch, alarm_mock):
        svc = service.Service()
        service.launch(self.conf, svc, workers=3)
        mock_launch.assert_called_with(svc, workers=3) 
Example #21
Source File: test_service.py    From oslo.service with Apache License 2.0 5 votes vote down vote up
def _test_launch_single(self, workers, mock_launch):
        svc = service.Service()
        service.launch(self.conf, svc, workers=workers)
        mock_launch.assert_called_with(svc, workers=workers) 
Example #22
Source File: test_service.py    From oslo.service with Apache License 2.0 5 votes vote down vote up
def test_mutate_hook_service_launcher(self):
        """Test mutate_config_files is called by ServiceLauncher on SIGHUP.

        Not using _spawn_service because ServiceLauncher doesn't fork and it's
        simplest to stay all in one process.
        """
        mutate = multiprocessing.Event()
        self.conf.register_mutate_hook(lambda c, f: mutate.set())
        launcher = service.launch(
            self.conf, ServiceWithTimer(), restart_method='mutate')

        self.assertFalse(mutate.is_set(), "Hook was called too early")
        launcher.restart()
        self.assertTrue(mutate.is_set(), "Hook wasn't called") 
Example #23
Source File: test_service.py    From oslo.service with Apache License 2.0 5 votes vote down vote up
def _spawn_service(self,
                       workers=1,
                       service_maker=None,
                       launcher_maker=None):
        self.workers = workers
        pid = os.fork()
        if pid == 0:
            os.setsid()
            # NOTE(johannes): We can't let the child processes exit back
            # into the unit test framework since then we'll have multiple
            # processes running the same tests (and possibly forking more
            # processes that end up in the same situation). So we need
            # to catch all exceptions and make sure nothing leaks out, in
            # particular SystemExit, which is raised by sys.exit(). We use
            # os._exit() which doesn't have this problem.
            status = 0
            try:
                serv = service_maker() if service_maker else ServiceWithTimer()
                if launcher_maker:
                    launcher = launcher_maker()
                    launcher.launch_service(serv, workers=workers)
                else:
                    launcher = service.launch(self.conf, serv, workers=workers)
                status = launcher.wait()
            except SystemExit as exc:
                status = exc.code
            except BaseException:
                # We need to be defensive here too
                try:
                    traceback.print_exc()
                except BaseException:
                    print("Couldn't print traceback")
                status = 2
            # Really exit
            os._exit(status or 0)
        return pid 
Example #24
Source File: eventlet_service.py    From oslo.service with Apache License 2.0 5 votes vote down vote up
def run(port_queue, workers=3, process_time=0):
    eventlet.patcher.monkey_patch()
    # Monkey patch the original current_thread to use the up-to-date _active
    # global variable. See https://bugs.launchpad.net/bugs/1863021 and
    # https://github.com/eventlet/eventlet/issues/592
    import __original_module_threading as orig_threading  # noqa
    import threading  # noqa
    orig_threading.current_thread.__globals__['_active'] = threading._active

    def hi_app(environ, start_response):
        # Some requests need to take time to process so the connection
        # remains active.
        time.sleep(process_time)
        start_response('200 OK', [('Content-Type', 'application/json')])
        yield 'hi'

    server = Server(hi_app)
    server.listen()
    launcher = service.launch(cfg.CONF, server, workers)

    port = server.socket.getsockname()[1]
    port_queue.put(port)

    sys.stdout.flush()

    launcher.wait() 
Example #25
Source File: df_bgp_service.py    From dragonflow with Apache License 2.0 5 votes vote down vote up
def main():
    df_config.init(sys.argv)
    nb_api = api_nb.NbApi.get_instance()
    server = BGPService(nb_api)
    df_service.register_service('df-bgp-service', nb_api)
    service.launch(cfg.CONF, server, restart_method='mutate').wait() 
Example #26
Source File: service.py    From masakari with Apache License 2.0 5 votes vote down vote up
def serve(server, workers=None):
    global _launcher
    if _launcher:
        raise RuntimeError(_('serve() can only be called once'))

    _launcher = service.launch(CONF, server, workers=workers,
                               restart_method='mutate') 
Example #27
Source File: service.py    From manila with Apache License 2.0 5 votes vote down vote up
def serve(server, workers=None):
    global _launcher
    if _launcher:
        raise RuntimeError('serve() can only be called once')
    _launcher = service.launch(CONF, server, workers=workers,
                               restart_method='mutate') 
Example #28
Source File: conductor.py    From magnum with Apache License 2.0 5 votes vote down vote up
def main():
    magnum_service.prepare_service(sys.argv)

    gmr.TextGuruMeditation.setup_autorun(version)

    LOG.info('Starting server in PID %s', os.getpid())
    LOG.debug("Configuration:")
    CONF.log_opt_values(LOG, logging.DEBUG)

    conductor_id = short_id.generate_id()
    endpoints = [
        indirection_api.Handler(),
        cluster_conductor.Handler(),
        conductor_listener.Handler(),
        ca_conductor.Handler(),
        federation_conductor.Handler(),
        nodegroup_conductor.Handler(),
    ]

    server = rpc_service.Service.create(CONF.conductor.topic,
                                        conductor_id, endpoints,
                                        binary='magnum-conductor')
    workers = CONF.conductor.workers
    if not workers:
        workers = processutils.get_worker_count()
    launcher = service.launch(CONF, server, workers=workers)

    # NOTE(mnaser): We create the periodic tasks here so that they
    #               can be attached to the main process and not
    #               duplicated in all the children if multiple
    #               workers are being used.
    server.create_periodic_tasks()
    server.start()

    launcher.wait() 
Example #29
Source File: l2gw_agent.py    From networking-l2gw with Apache License 2.0 5 votes vote down vote up
def main():
    config.register_ovsdb_opts_helper(cfg.CONF)
    agent_config.register_agent_state_opts_helper(cfg.CONF)
    common_config.init(sys.argv[1:])
    config.setup_logging()

    mgr = manager.OVSDBManager(cfg.CONF)
    svc = L2gatewayAgentService(
        host=cfg.CONF.host,
        topic=topics.L2GATEWAY_AGENT,
        manager=mgr
    )
    service.launch(cfg.CONF, svc).wait() 
Example #30
Source File: entry.py    From neutron-dynamic-routing with Apache License 2.0 5 votes vote down vote up
def main():
    register_options()
    common_config.init(sys.argv[1:])
    config.setup_logging()
    server = neutron_service.Service.create(
        binary='neutron-bgp-dragent',
        topic=bgp_consts.BGP_DRAGENT,
        report_interval=cfg.CONF.AGENT.report_interval,
        manager='neutron_dynamic_routing.services.bgp.agent.bgp_dragent.'
                'BgpDrAgentWithStateReport')
    service.launch(cfg.CONF, server, restart_method='mutate').wait()