예제 #1
0
def run_etcd_service(etcd, service, addr, run_server, attr=None):
    """
    addr format:
        127.0.0.1:80
        tcp://127.0.0.1:80
    """
    if addr.find('://')>=0:
        addr = addr.split('://', 1)[1]

    if attr is None:
        attr = {}

    host, port = addr.split(':')
    if host in ['0.0.0.0', '127.0.0.1']:
        host = get_ip_address() or host

    addr = ':'.join([host, port])

    def cleanup():
        WARN("warm shutdown service: %s %s" % (service, addr))
        etcd.unregister_service(service, addr)

    def trap(*args):
        sys.exit(0)

    try:
        etcd.register_service(service, addr, attr)
        signal.signal(signal.SIGINT, trap)
        signal.signal(signal.SIGTERM, trap)
        run_server()
    finally:
        cleanup()
예제 #2
0
 def get_service_config(self, service):
     for e in get_etcd_list():
         host_list = None
         if QUANT_SERVICED_DEV:
             host_list = [network_utils.get_ip_address()]
         r = e.find_service(service, host_list=host_list)
         if r is not None:
             addr, attr = r
             if attr is None:
                 attr = {}
             dict_utils.set_dict_defaults(attr, type='zerorpc', name=service)
             return addr, attr