Пример #1
0
def main():
    args, command = parse_args()
    setup_logging(args.verbose)

    session = consul.Consul(*args.consul_agent)

    service = Service(
        command,
        session=session,
        ttl=args.ttl,
        service_name=args.service_name,
        service_id=args.id,
        tags=args.tags,
        port=args.port,
        tag_file=args.tag_file,
        default_tags=args.default_tags
    )

    service.start()

    def signal_handler(signal_number, *_):
        service.process.send_signal(signal_number)

    for signal_name in SIGNALS:
        try:
            signum = getattr(signal, signal_name)
            signal.signal(signum, signal_handler)
        except RuntimeError:
            # signals that cannot be catched will raise RuntimeException
            # (SIGKILL) ...
            pass
        except OSError:
            # ... or OSError (SIGSTOP)
            pass

    while sleep(args.heartbeat) or service.is_up():
        service.keep_alive()

    logger.info("process quit with errorcode %s %s" % (
        service.process.poll(),
        "(signal)" if service.process.poll() and service.process.poll() < 0
        else ""
    ))

    service.deregister()
Пример #2
0
def main():
    args, command = parse_args()
    setup_logging(args.verbose)

    session = consul.Consul(*args.consul_agent)

    service = Service(
        command,
        session=session,
        ttl=args.ttl,
        service_name=args.service_name,
        service_id=args.id,
        tags=args.tags,
        port=args.port
    )

    service.start()

    def signal_handler(signal_number, *_):
        service.process.send_signal(signal_number)

    for signal_name in SIGNALS:
        try:
            signum = getattr(signal, signal_name)
            signal.signal(signum, signal_handler)
        except RuntimeError:
            # signals that cannot be catched will raise RuntimeException
            # (SIGKILL) ...
            pass
        except OSError:
            # ... or OSError (SIGSTOP)
            pass

    while sleep(args.heartbeat) or service.is_up():
        service.keep_alive()

    logger.info("process quit with errorcode %s %s" % (
        service.process.poll(),
        "(signal)" if service.process.poll() and service.process.poll() < 0
        else ""
    ))

    service.deregister()
Пример #3
0
def test_default_heartbeat():
    args, invocation = args_parser.parse_args()
    assert args.heartbeat == TEST_TTL / 10.
Пример #4
0
def test_parse_port():
    args, invocation = args_parser.parse_args()
    assert args.port == 1234
Пример #5
0
def test_parse_args():
    args, invocation = args_parser.parse_args()
    assert invocation == ['tail', '-f', 'something']