def main(): octavia_service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) launcher = service.launch(CONF, consumer.Consumer()) launcher.wait()
def main(): # comment out to improve logging service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) health_sender_proc = multiproc.Process(name='HM_sender', target=health_daemon.run_sender, args=(HM_SENDER_CMD_QUEUE,)) health_sender_proc.daemon = True health_sender_proc.start() # Initiate server class server_instance = server.Server() bind_ip_port = utils.ip_port_str(CONF.haproxy_amphora.bind_host, CONF.haproxy_amphora.bind_port) options = { 'bind': bind_ip_port, 'workers': 1, 'timeout': CONF.amphora_agent.agent_request_read_timeout, 'certfile': CONF.amphora_agent.agent_server_cert, 'ca_certs': CONF.amphora_agent.agent_server_ca, 'cert_reqs': True, 'preload_app': True, 'accesslog': '/var/log/amphora-agent.log', 'errorlog': '/var/log/amphora-agent.log', 'loglevel': 'debug', } AmphoraAgent(server_instance.app, options).run()
def main(): """Perform db cleanup for old resources. Remove load balancers from database, which have been deleted have since expired. """ # perform the rituals service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) signal.signal(signal.SIGHUP, _mutate_config) # Read configuration interval = CONF.house_keeping.cleanup_interval lb_expiry = CONF.house_keeping.load_balancer_expiry_age # initialize prometheus.start_http_server(PROMETHEUS_PORT) db_cleanup = house_keeping.DatabaseCleanup() LOG.info("Starting house keeping at %s", str(datetime.datetime.utcnow())) # start cleanup cycle while True: LOG.debug("Housekeeping") _metric_housekeeping.inc() try: db_cleanup.cleanup_load_balancers() except Exception as e: LOG.error( 'Housekeeping caught the following exception: {}'.format(e)) _metric_housekeeping_exceptions.inc() time.sleep(interval)
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) timestamp = str(datetime.datetime.utcnow()) LOG.info(_LI("Starting house keeping at %s"), timestamp) # Thread to perform spare amphora check spare_amp_thread = threading.Thread(target=spare_amphora_check) spare_amp_thread.daemon = True spare_amp_thread_event.set() spare_amp_thread.start() # Thread to perform db cleanup db_cleanup_thread = threading.Thread(target=db_cleanup) db_cleanup_thread.daemon = True db_cleanup_thread_event.set() db_cleanup_thread.start() # Try-Exception block should be at the end to gracefully exit threads try: while True: time.sleep(1) except KeyboardInterrupt: LOG.info(_LI("Attempting to gracefully terminate House-Keeping")) spare_amp_thread_event.clear() db_cleanup_thread_event.clear() spare_amp_thread.join() db_cleanup_thread.join() LOG.info(_LI("House-Keeping process terminated"))
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) processes = [] hm_listener_proc = multiprocessing.Process(name='HM_listener', target=hm_listener) processes.append(hm_listener_proc) hm_health_check_proc = multiprocessing.Process(name='HM_health_check', target=hm_health_check) processes.append(hm_health_check_proc) LOG.info(_LI("Health Manager listener process starts:")) hm_listener_proc.start() LOG.info(_LI("Health manager check process starts:")) hm_health_check_proc.start() try: for process in processes: process.join() except KeyboardInterrupt: LOG.info(_LI("Health Manager existing due to signal")) hm_listener_proc.terminate() hm_health_check_proc.terminate()
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) c = consumer.Consumer() c.listen()
def main(): # comment out to improve logging service.prepare_service(sys.argv) # Workaround for an issue with the auto-reload used below in werkzeug # Without it multiple health senders get started when werkzeug reloads if not os.environ.get('WERKZEUG_RUN_MAIN'): health_sender_proc = multiproc.Process(name='HM_sender', target=health_daemon.run_sender, args=(HM_SENDER_CMD_QUEUE,)) health_sender_proc.daemon = True health_sender_proc.start() # We will only enforce that the client cert is from the good authority # todo(german): Watch this space for security improvements ctx = OctaviaSSLContext(ssl.PROTOCOL_SSLv23) ctx.load_cert_chain(CONF.amphora_agent.agent_server_cert, ca=CONF.amphora_agent.agent_server_ca) # This will trigger a reload if any files change and # in particular the certificate file serving.run_simple(hostname=CONF.haproxy_amphora.bind_host, port=CONF.haproxy_amphora.bind_port, application=server.app, use_debugger=CONF.debug, ssl_context=ctx, use_reloader=True, extra_files=[CONF.amphora_agent.agent_server_cert])
def main(): service.prepare_service(sys.argv) timestamp = str(datetime.datetime.utcnow()) LOG.info(_LI("Starting house keeping at %s"), timestamp) # Thread to perform spare amphora check spare_amp_thread = threading.Thread(target=spare_amphora_check) spare_amp_thread.daemon = True spare_amp_thread_event.set() spare_amp_thread.start() # Thread to perform db cleanup db_cleanup_thread = threading.Thread(target=db_cleanup) db_cleanup_thread.daemon = True db_cleanup_thread_event.set() db_cleanup_thread.start() # Try-Exception block should be at the end to gracefully exit threads try: while True: time.sleep(1) except KeyboardInterrupt: LOG.info(_LI("Attempting to gracefully terminate House-Keeping")) spare_amp_thread_event.clear() db_cleanup_thread_event.clear() spare_amp_thread.join() db_cleanup_thread.join() LOG.info(_LI("House-Keeping process terminated"))
def main(): # comment out to improve logging service.prepare_service(sys.argv) # Workaround for an issue with the auto-reload used below in werkzeug # Without it multiple health senders get started when werkzeug reloads if not os.environ.get('WERKZEUG_RUN_MAIN'): health_sender_proc = multiproc.Process(name='HM_sender', target=health_daemon.run_sender, args=(HM_SENDER_CMD_QUEUE, )) health_sender_proc.daemon = True health_sender_proc.start() # We will only enforce that the client cert is from the good authority # todo(german): Watch this space for security improvements ctx = OctaviaSSLContext(ssl.PROTOCOL_SSLv23) ctx.load_cert_chain(CONF.amphora_agent.agent_server_cert, ca=CONF.amphora_agent.agent_server_ca) # This will trigger a reload if any files change and # in particular the certificate file serving.run_simple(hostname=CONF.haproxy_amphora.bind_host, port=CONF.haproxy_amphora.bind_port, application=server.app, use_debugger=CONF.debug, ssl_context=ctx, use_reloader=True, extra_files=[CONF.amphora_agent.agent_server_cert])
def main(): octavia_service.prepare_service(sys.argv) app = api_app.setup_app() host, port = cfg.CONF.bind_host, cfg.CONF.bind_port LOG.info(_LI("Starting API server on %(host)s:%(port)s"), {"host": host, "port": port}) srv = simple_server.make_server(host, port, app) srv.serve_forever()
def main(): octavia_service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) sm = cotyledon.ServiceManager() sm.add(consumer.ConsumerService, workers=CONF.controller_worker.workers, args=(CONF,)) oslo_config_glue.setup(sm, CONF, reload_method="mutate") sm.run()
def main(): octavia_service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) sm = cotyledon.ServiceManager() sm.add(consumer.ConsumerService, workers=CONF.controller_worker.workers, args=(CONF, )) oslo_config_glue.setup(sm, CONF) sm.run()
def main(): octavia_service.prepare_service(sys.argv) app = api_app.setup_app() host, port = cfg.CONF.bind_host, cfg.CONF.bind_port LOG.info(_LI("Starting API server on %(host)s:%(port)s"), { "host": host, "port": port }) srv = simple_server.make_server(host, port, app) srv.serve_forever()
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) processes = [] exit_event = multiprocessing.Event() status_listener_proc = multiprocessing.Process( name='status_listener', target=driver_listener.status_listener, args=(exit_event, )) processes.append(status_listener_proc) LOG.info("Driver agent status listener process starts:") status_listener_proc.start() stats_listener_proc = multiprocessing.Process( name='stats_listener', target=driver_listener.stats_listener, args=(exit_event, )) processes.append(stats_listener_proc) LOG.info("Driver agent statistics listener process starts:") stats_listener_proc.start() get_listener_proc = multiprocessing.Process( name='get_listener', target=driver_listener.get_listener, args=(exit_event, )) processes.append(get_listener_proc) LOG.info("Driver agent get listener process starts:") get_listener_proc.start() def process_cleanup(*args, **kwargs): LOG.info("Driver agent exiting due to signal") exit_event.set() status_listener_proc.join() stats_listener_proc.join() get_listener_proc.join() signal.signal(signal.SIGTERM, process_cleanup) signal.signal( signal.SIGHUP, partial(_handle_mutate_config, status_listener_proc.pid, stats_listener_proc.pid, get_listener_proc.pid)) try: for process in processes: process.join() except KeyboardInterrupt: process_cleanup()
def setup_app(pecan_config=None, debug=False, argv=None): """Creates and returns a pecan wsgi app.""" octavia_service.prepare_service(argv) if not pecan_config: pecan_config = get_pecan_config() pecan.configuration.set_config(dict(pecan_config), overwrite=True) return pecan.make_app(pecan_config.app.root, wrap_app=_wrap_app, debug=debug, hooks=pecan_config.app.hooks, wsme=pecan_config.wsme)
def main(): # comment out to improve logging service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) health_sender_proc = multiproc.Process(name='HM_sender', target=health_daemon.run_sender, args=(HM_SENDER_CMD_QUEUE, )) health_sender_proc.daemon = True health_sender_proc.start() # Initiate server class server_instance = server.Server() bind_ip_port = utils.ip_port_str(CONF.haproxy_amphora.bind_host, CONF.haproxy_amphora.bind_port) proto = CONF.amphora_agent.agent_tls_protocol.replace('.', '_') options = { 'bind': bind_ip_port, 'workers': 1, 'timeout': CONF.amphora_agent.agent_request_read_timeout, 'certfile': CONF.amphora_agent.agent_server_cert, 'ca_certs': CONF.amphora_agent.agent_server_ca, 'cert_reqs': True, 'ssl_version': getattr(ssl, "PROTOCOL_%s" % proto), 'preload_app': True, 'accesslog': '/var/log/amphora-agent.log', 'errorlog': '/var/log/amphora-agent.log', 'loglevel': 'debug', 'syslog': True, 'syslog_facility': 'local{}'.format(CONF.amphora_agent.administrative_log_facility), 'syslog_addr': 'unix://run/rsyslog/octavia/log#dgram', } AmphoraAgent(server_instance.app, options).run()
def setup_app(pecan_config=None, debug=False, argv=None): """Creates and returns a pecan wsgi app.""" octavia_service.prepare_service(argv) cfg.CONF.log_opt_values(LOG, logging.DEBUG) _init_drivers() if not pecan_config: pecan_config = get_pecan_config() pecan.configuration.set_config(dict(pecan_config), overwrite=True) return pecan.make_app(pecan_config.app.root, wrap_app=_wrap_app, debug=debug, hooks=pecan_config.app.hooks, wsme=pecan_config.wsme)
def setup_app(pecan_config=None, debug=False, argv=None): """Creates and returns a pecan wsgi app.""" octavia_service.prepare_service(argv) app_hooks = [hooks.ContextHook()] if not pecan_config: pecan_config = get_pecan_config() pecan.configuration.set_config(dict(pecan_config), overwrite=True) return pecan.make_app( pecan_config.app.root, debug=debug, hooks=app_hooks, wsme=pecan_config.wsme )
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) timestamp = str(datetime.datetime.utcnow()) LOG.info("Starting house keeping at %s", timestamp) threads = [] # Thread to perform spare amphora check spare_amp_thread = threading.Thread(target=spare_amphora_check) spare_amp_thread.daemon = True spare_amp_thread.start() threads.append(spare_amp_thread) # Thread to perform db cleanup db_cleanup_thread = threading.Thread(target=db_cleanup) db_cleanup_thread.daemon = True db_cleanup_thread.start() threads.append(db_cleanup_thread) # Thread to perform certificate rotation cert_rotate_thread = threading.Thread(target=cert_rotation) cert_rotate_thread.daemon = True cert_rotate_thread.start() threads.append(cert_rotate_thread) def process_cleanup(*args, **kwargs): LOG.info("Attempting to gracefully terminate House-Keeping") spare_amp_thread_event.set() db_cleanup_thread_event.set() cert_rotate_thread_event.set() spare_amp_thread.join() db_cleanup_thread.join() cert_rotate_thread.join() LOG.info("House-Keeping process terminated") signal.signal(signal.SIGTERM, process_cleanup) signal.signal(signal.SIGHUP, _mutate_config) try: for thread in threads: thread.join() except KeyboardInterrupt: process_cleanup()
def setup_app(pecan_config=None, debug=False, argv=None): """Creates and returns a pecan wsgi app.""" octavia_service.prepare_service(argv) cfg.CONF.log_opt_values(LOG, logging.DEBUG) _init_drivers() if not pecan_config: pecan_config = get_pecan_config() pecan.configuration.set_config(dict(pecan_config), overwrite=True) return pecan.make_app( pecan_config.app.root, wrap_app=_wrap_app, debug=debug, hooks=pecan_config.app.hooks, wsme=pecan_config.wsme )
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) processes = [] exit_event = multiprocessing.Event() status_listener_proc = multiprocessing.Process( name='status_listener', target=driver_listener.status_listener, args=(exit_event,)) processes.append(status_listener_proc) LOG.info("Driver agent status listener process starts:") status_listener_proc.start() stats_listener_proc = multiprocessing.Process( name='stats_listener', target=driver_listener.stats_listener, args=(exit_event,)) processes.append(stats_listener_proc) LOG.info("Driver agent statistics listener process starts:") stats_listener_proc.start() def process_cleanup(*args, **kwargs): LOG.info("Driver agent exiting due to signal") exit_event.set() status_listener_proc.join() stats_listener_proc.join() signal.signal(signal.SIGTERM, process_cleanup) signal.signal(signal.SIGHUP, partial( _handle_mutate_config, status_listener_proc.pid, stats_listener_proc.pid)) try: for process in processes: process.join() except KeyboardInterrupt: process_cleanup()
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) processes = [] exit_event = multiprocessing.Event() hm_listener_proc = multiprocessing.Process(name='HM_listener', target=hm_listener, args=(exit_event, )) processes.append(hm_listener_proc) hm_health_check_proc = multiprocessing.Process(name='HM_health_check', target=hm_health_check, args=(exit_event, )) processes.append(hm_health_check_proc) LOG.info("Health Manager listener process starts:") hm_listener_proc.start() LOG.info("Health manager check process starts:") hm_health_check_proc.start() def process_cleanup(*args, **kwargs): LOG.info("Health Manager exiting due to signal") exit_event.set() os.kill(hm_health_check_proc.pid, signal.SIGINT) hm_health_check_proc.join() hm_listener_proc.join() signal.signal(signal.SIGTERM, process_cleanup) signal.signal( signal.SIGHUP, partial(_handle_mutate_config, hm_listener_proc.pid, hm_health_check_proc.pid)) try: for process in processes: process.join() except KeyboardInterrupt: process_cleanup()
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) timestamp = str(datetime.datetime.utcnow()) LOG.info("Starting house keeping at %s", timestamp) # Thread to perform spare amphora check spare_amp_thread = threading.Thread(target=spare_amphora_check) spare_amp_thread.daemon = True spare_amp_thread.start() # Thread to perform db cleanup db_cleanup_thread = threading.Thread(target=db_cleanup) db_cleanup_thread.daemon = True db_cleanup_thread.start() # Thread to perform certificate rotation cert_rotate_thread = threading.Thread(target=cert_rotation) cert_rotate_thread.daemon = True cert_rotate_thread.start() signal.signal(signal.SIGHUP, _mutate_config) # Try-Exception block should be at the end to gracefully exit threads try: while True: time.sleep(1) except KeyboardInterrupt: LOG.info("Attempting to gracefully terminate House-Keeping") spare_amp_thread_event.set() db_cleanup_thread_event.set() cert_rotate_thread_event.set() spare_amp_thread.join() db_cleanup_thread.join() cert_rotate_thread.join() LOG.info("House-Keeping process terminated")
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) processes = [] exit_event = multiprocessing.Event() hm_listener_proc = multiprocessing.Process(name='HM_listener', target=hm_listener, args=(exit_event,)) processes.append(hm_listener_proc) hm_health_check_proc = multiprocessing.Process(name='HM_health_check', target=hm_health_check, args=(exit_event,)) processes.append(hm_health_check_proc) LOG.info("Health Manager listener process starts:") hm_listener_proc.start() LOG.info("Health manager check process starts:") hm_health_check_proc.start() def process_cleanup(*args, **kwargs): LOG.info("Health Manager exiting due to signal") exit_event.set() os.kill(hm_health_check_proc.pid, signal.SIGINT) hm_health_check_proc.join() hm_listener_proc.join() signal.signal(signal.SIGTERM, process_cleanup) signal.signal(signal.SIGHUP, partial( _handle_mutate_config, hm_listener_proc.pid, hm_health_check_proc.pid)) try: for process in processes: process.join() except KeyboardInterrupt: process_cleanup()
def main(): service.prepare_service(sys.argv) c = consumer.Consumer() c.listen()
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import sys from wsgiref import simple_server from oslo.config import cfg from octavia.api import app as api_app from octavia.common import service as octavia_service from octavia.i18n import _LI from octavia.openstack.common import log as logging LOG = logging.getLogger(__name__) if __name__ == '__main__': octavia_service.prepare_service(sys.argv) app = api_app.setup_app() host, port = cfg.CONF.bind_host, cfg.CONF.bind_port LOG.info(_LI("Starting API server on %(host)s:%(port)s") % {"host": host, "port": port}) srv = simple_server.make_server(host, port, app) srv.serve_forever()
def main(): service.prepare_service(sys.argv) gmr.TextGuruMeditation.setup_autorun(version) processes = [] exit_event = multiprocessing.Event() status_listener_proc = multiprocessing.Process( name='status_listener', target=_process_wrapper, args=(exit_event, 'status_listener', driver_listener.status_listener)) processes.append(status_listener_proc) LOG.info("Driver agent status listener process starts:") status_listener_proc.start() stats_listener_proc = multiprocessing.Process( name='stats_listener', target=_process_wrapper, args=(exit_event, 'stats_listener', driver_listener.stats_listener)) processes.append(stats_listener_proc) LOG.info("Driver agent statistics listener process starts:") stats_listener_proc.start() get_listener_proc = multiprocessing.Process( name='get_listener', target=_process_wrapper, args=(exit_event, 'get_listener', driver_listener.get_listener)) processes.append(get_listener_proc) LOG.info("Driver agent get listener process starts:") get_listener_proc.start() _start_provider_agents(exit_event) def process_cleanup(*args, **kwargs): LOG.info("Driver agent exiting due to signal.") exit_event.set() status_listener_proc.join() stats_listener_proc.join() get_listener_proc.join() for proc in PROVIDER_AGENT_PROCESSES: LOG.info( 'Waiting up to %s seconds for provider agent "%s" to ' 'shutdown.', CONF.driver_agent.provider_agent_shutdown_timeout, proc.name) try: proc.join(CONF.driver_agent.provider_agent_shutdown_timeout) if proc.exitcode is None: # TODO(johnsom) Change to proc.kill() once # python 3.7 or newer only os.kill(proc.pid, signal.SIGKILL) LOG.warning( 'Forcefully killed "%s" provider agent because it ' 'failed to shutdown in %s seconds.', proc.name, CONF.driver_agent.provider_agent_shutdown_timeout) except Exception as e: LOG.warning( 'Unknown error "%s" while shutting down "%s", ' 'ignoring and continuing shutdown process.', str(e), proc.name) else: LOG.info('Provider agent "%s" has succesfully shutdown.', proc.name) signal.signal(signal.SIGTERM, process_cleanup) signal.signal( signal.SIGHUP, partial(_handle_mutate_config, status_listener_proc.pid, stats_listener_proc.pid, get_listener_proc.pid)) try: for process in processes: process.join() except KeyboardInterrupt: process_cleanup()
LOG.debug("[%s] Processing %s amphorae: %s, vm: %s", amp.load_balancer_id, role, amp.id, amp.compute_id) lb_amp_dict[amp.load_balancer_id] = amp.id mgmt_port = get_vm_mgmt_port(net_driver, amp.compute_id, amp.lb_network_ip) disable_port(net_driver, mgmt_port) return lb_amp_dict if __name__ == '__main__': raw_input('First, please stop octavia house_keeping process, then press ' 'any key to continue...') service.prepare_service(sys.argv) session = db_api.get_session() amp_repo = repo.AmphoraRepository() amphealth_repo = repo.AmphoraHealthRepository() nova_manager = nova_driver.VirtualMachineManager() net_driver = allowed_address_pairs.AllowedAddressPairsDriver() # Delete all the amp vms in spare pool and corresponding db records. amps = get_spare_amphoras(session) LOG.debug("Step 1: Clean up %d amphorae vms in spare pool.", len(amps)) for amp in amps: delete_amp(nova_manager, session, amp_repo, amphealth_repo, amp) raw_input('Now, please start octavia house_keeping process, then press ' 'any key to continue...')