Ejemplo n.º 1
0
def main():
    setup_sentry()
    if not alias.get_initialized():
        _init_dockyards()
        alias.set_initialized()

    _save_runtime_settings()
Ejemplo n.º 2
0
def main():
    setup_sentry()
    if not alias.get_initialized():
        _init_dockyards()
        alias.set_initialized()

    _save_runtime_settings()
Ejemplo n.º 3
0
def main():
    setup_sentry()
    args = _parse_args()
    saved_containers_path = args.saved_containers_path

    if not args.force and not _is_recovery_completed():
        get_logger().info(
            'Recovery is not completed. Aborting saving running containers.')
        return

    try:
        wait_for_consul_ready()
        saved_containers = get_local_services()
        containers_parameters_dict = {}

        for container in saved_containers:
            container_dict = kv.kv_get(container)
            containers_parameters_dict[container] = container_dict

        if not containers_parameters_dict:
            get_logger().info(
                'Aborted saving container because list is empty.')
            return

        _save_containers_parameters_list_in_file(containers_parameters_dict,
                                                 saved_containers_path)
        get_logger().info(
            'Containers have been saved to {}.'.format(saved_containers_path))

    except Exception as e:
        get_logger().exception(e)
        sys.exit(1)
Ejemplo n.º 4
0
def main():
    setup_sentry()
    args = _parse_args()

    saved_containers_path = args.saved_containers_path
    try:
        wait_for_consul_ready()
        ship = get_ship_name()
        saved_containers = kv.kv_list('ships/{}/service/'.format(ship))
        containers_parameters_dict = {}
        if saved_containers:
            for container in saved_containers:
                container_dict = kv.kv_get(container)
                containers_parameters_dict[container] = container_dict

        if containers_parameters_dict:
            try:
                _save_containers_parameters_list_in_kv_store(containers_parameters_dict)
                get_logger().info('Containers have been saved to kv store.')
            except Exception as e:
                get_logger().exception(e)
            if not args.force and not _is_recovery_completed():
                get_logger().warning('Recovery is not completed. Aborting saving running containers.')
                return
            _save_containers_parameters_list_in_file(containers_parameters_dict, saved_containers_path)
            get_logger().info('Containers have been saved to {}.'.format(saved_containers_path))

        else:
            get_logger().info('Aborted saving container because of errors.')
    except Exception as e:
        get_logger().exception(e)
        sys.exit(1)
Ejemplo n.º 5
0
def main():
    setup_sentry()
    args = _parse_args()
    saved_containers_path = args.saved_containers_path

    if not args.force and not _is_recovery_completed():
        get_logger().info(
            'Recovery is not completed. Aborting saving running containers.')
        return

    try:
        wait_for_consul_ready()
        services_key = 'services/{}'.format(get_ship_name())
        containers_parameters = kv.kv_get_recurse(services_key,
                                                  strip_keys=False)

        if not containers_parameters:
            get_logger().info(
                'Aborted saving container because list is empty.')
            return

        _save_containers_parameters_list_in_file(containers_parameters,
                                                 saved_containers_path)
        get_logger().info(
            'Containers have been saved to {}.'.format(saved_containers_path))

    except Exception as e:
        get_logger().exception(e)
        sys.exit(1)
Ejemplo n.º 6
0
def main():
    setup_sentry()
    try:
        args = _parse_args()
        _add_running_services_at_startup()
        if args.force or _check_if_we_should_recover(args.saved_containers_path):
            _load_containers_to_kv_store(args.saved_containers_path)
            if not recover_containers_from_kv_store():
                sys.exit(1)
    finally:
        with open(RECOVERY_COMPLETED_PATH, 'w') as recovery_completed_file:
            recovery_completed_file.write('1')
Ejemplo n.º 7
0
def main():
    setup_sentry()
    _wait_for_armada_start()

    # We fetch data from courier as soon as possible to cover most common case of 1 courier running.
    courier_addresses = _get_courier_addresses()
    _fetch_hermes_from_couriers(courier_addresses)

    # We fetch data from other couriers that could register a little bit later.
    time.sleep(11)
    new_courier_addresses = _get_courier_addresses() - courier_addresses
    _fetch_hermes_from_couriers(new_courier_addresses)
Ejemplo n.º 8
0
def main():
    setup_sentry()
    _wait_for_armada_start()

    # We fetch data from courier as soon as possible to cover most common case of 1 courier running.
    courier_addresses = _get_courier_addresses()
    _fetch_hermes_from_couriers(courier_addresses)

    # We fetch data from other couriers that could register a little bit later.
    time.sleep(11)
    new_courier_addresses = _get_courier_addresses() - courier_addresses
    _fetch_hermes_from_couriers(new_courier_addresses)
Ejemplo n.º 9
0
def main():
    setup_sentry()
    try:
        args = _parse_args()
        _add_running_services_at_startup()
        if args.force or _check_if_we_should_recover(
                args.saved_containers_path):
            _load_containers_to_kv_store(args.saved_containers_path)
            if not recover_containers_from_kv_store():
                sys.exit(1)
    finally:
        with open(RECOVERY_COMPLETED_PATH, 'w') as recovery_completed_file:
            recovery_completed_file.write('1')
Ejemplo n.º 10
0
def main():
    setup_sentry()
    try:
        args = _parse_args()
        _add_running_services_at_startup()
        if args.force or _check_if_we_should_recover(args.saved_containers_path):
            _load_containers_to_kv_store(args.saved_containers_path)
            not_recovered = recover_containers_from_kv_store()
            if not_recovered:
                get_logger().error("Containers not recovered: %s", json.dumps(not_recovered))
                sys.exit(1)
            get_logger().info("All containers recovered :)")
    finally:
        with open(RECOVERY_COMPLETED_PATH, 'w') as recovery_completed_file:
            recovery_completed_file.write('1')
Ejemplo n.º 11
0
def main():
    setup_sentry()
    consul_mode, ship_ips, datacenter, ship_name = _get_runtime_settings()
    ship_external_ip = get_external_ip()
    if ship_name is None:
        ship_name = ship_external_ip
    consul_config_content = consul_config.get_consul_config(consul_mode, ship_ips, datacenter, ship_external_ip,
                                                            ship_name)

    with open(consul_config.CONFIG_PATH, 'w') as config_file:
        config_file.write(consul_config_content)

    command = '/usr/local/bin/consul agent -config-file {config_path}'.format(config_path=consul_config.CONFIG_PATH)
    get_logger().info('RUNNING: %s', command)

    args = command.split()
    os.execv(args[0], args)
Ejemplo n.º 12
0
        '/run',
        _get_module_path_to_class(Run),
        '/stop',
        _get_module_path_to_class(Stop),
        '/restart',
        _get_module_path_to_class(Restart),
        '/recover',
        _get_module_path_to_class(Recover),
        '/ssh-address',
        _get_module_path_to_class(SshAddress),
        '/hermes_address',
        _get_module_path_to_class(HermesAddress),
        '/env/(.*)/(.*)',
        _get_module_path_to_class(GetEnv),
        '/version',
        _get_module_path_to_class(GetVersion),
        '/images/(.*)',
        _get_module_path_to_class(Images),
        '/list',
        _get_module_path_to_class(List),
        '/info',
        _get_module_path_to_class(Info),
    )
    app = web.application(urls, globals(), autoreload=reload)
    app.run()


if __name__ == '__main__':
    setup_sentry(is_web=True)
    main()
Ejemplo n.º 13
0
def main():
    setup_sentry()
    while True:
        _deregister_not_running_services()
        _clean_up_kv_store()
        time.sleep(60 + random.uniform(-5, 5))
Ejemplo n.º 14
0
def main():
    setup_sentry()
    while True:
        _deregister_not_running_services()
        _clean_up_kv_store()
        time.sleep(60 + random.uniform(-5, 5))
Ejemplo n.º 15
0
    urls = (
        '/health', Health.__name__,

        '/name', _get_module_path_to_class(Name),
        '/join', _get_module_path_to_class(Join),
        '/promote', _get_module_path_to_class(Promote),
        '/shutdown', _get_module_path_to_class(Shutdown),

        '/create', _get_module_path_to_class(Create),
        '/start', _get_module_path_to_class(Start),
        '/run', _get_module_path_to_class(Run),
        '/stop', _get_module_path_to_class(Stop),
        '/restart', _get_module_path_to_class(Restart),
        '/recover', _get_module_path_to_class(Recover),

        '/ssh-address', _get_module_path_to_class(SshAddress),
        '/hermes_address', _get_module_path_to_class(HermesAddress),
        '/env/(.*)/(.*)', _get_module_path_to_class(GetEnv),
        '/version', _get_module_path_to_class(GetVersion),
        '/images/(.*)', _get_module_path_to_class(Images),
        '/list', _get_module_path_to_class(List),
        '/info', _get_module_path_to_class(Info),
    )
    app = web.application(urls, globals(), autoreload=reload)
    app.run()


if __name__ == '__main__':
    setup_sentry(is_web=True)
    main()