Ejemplo n.º 1
0
def start_infra(asynchronous=False, apis=None):
    try:
        os.environ[LOCALSTACK_INFRA_PROCESS] = '1'

        is_in_docker = in_docker()
        # print a warning if we're not running in Docker but using Docker based LAMBDA_EXECUTOR
        if not is_in_docker and 'docker' in config.LAMBDA_EXECUTOR and not is_linux():
            print(('!WARNING! - Running outside of Docker with $LAMBDA_EXECUTOR=%s can lead to '
                   'problems on your OS. The environment variable $LOCALSTACK_HOSTNAME may not '
                   'be properly set in your Lambdas.') % config.LAMBDA_EXECUTOR)

        if is_in_docker and config.LAMBDA_REMOTE_DOCKER and not os.environ.get('HOST_TMP_FOLDER'):
            print('!WARNING! - Looks like you have configured $LAMBDA_REMOTE_DOCKER=1 - '
                  "please make sure to configure $HOST_TMP_FOLDER to point to your host's $TMPDIR")

        # apply patches
        patch_urllib3_connection_pool(maxsize=128)

        # load plugins
        load_plugins()

        # with plugins loaded, now start the infrastructure
        do_start_infra(asynchronous, apis, is_in_docker)

    except KeyboardInterrupt:
        print('Shutdown')
    except Exception as e:
        print('Error starting infrastructure: %s %s' % (e, traceback.format_exc()))
        sys.stdout.flush()
        raise e
    finally:
        if not asynchronous:
            stop_infra()
Ejemplo n.º 2
0
def start_infra(asynchronous=False, apis=None):
    try:
        # load plugins
        load_plugins()

        event_publisher.fire_event(event_publisher.EVENT_START_INFRA,
            {'d': in_docker() and 1 or 0, 'c': in_ci() and 1 or 0})

        # set up logging
        setup_logging()

        # prepare APIs
        apis = canonicalize_api_names(apis)
        # set environment
        os.environ['AWS_REGION'] = config.DEFAULT_REGION
        os.environ['ENV'] = ENV_DEV
        # register signal handlers
        if not os.environ.get(ENV_INTERNAL_TEST_RUN):
            register_signal_handlers()
        # make sure AWS credentials are configured, otherwise boto3 bails on us
        check_aws_credentials()
        # install libs if not present
        install.install_components(apis)
        # Some services take a bit to come up
        sleep_time = 5
        # start services
        thread = None

        if 'elasticsearch' in apis or 'es' in apis:
            sleep_time = max(sleep_time, 10)

        # loop through plugins and start each service
        for name, plugin in SERVICE_PLUGINS.items():
            if name in apis:
                t1 = plugin.start(asynchronous=True)
                thread = thread or t1

        time.sleep(sleep_time)
        # ensure that all infra components are up and running
        check_infra(apis=apis)
        # restore persisted data
        restore_persisted_data(apis=apis)
        print('Ready.')
        sys.stdout.flush()
        if not asynchronous and thread:
            # this is a bit of an ugly hack, but we need to make sure that we
            # stay in the execution context of the main thread, otherwise our
            # signal handlers don't work
            while True:
                time.sleep(1)
        return thread
    except KeyboardInterrupt:
        print('Shutdown')
    except Exception as e:
        print('Error starting infrastructure: %s %s' % (e, traceback.format_exc()))
        sys.stdout.flush()
        raise e
    finally:
        if not asynchronous:
            stop_infra()
Ejemplo n.º 3
0
def main():
    LOG.info('LocalStack version: %s' % constants.VERSION)
    # set basic CLI commands
    config.CLI_COMMANDS['infra'] = {
        'description': 'Commands to manage the infrastructure',
        'function': cmd_infra
    }
    config.CLI_COMMANDS['start'] = {
        'description': 'Shorthand to start the infrastructure',
        'function': cmd_infra
    }
    config.CLI_COMMANDS['web'] = {
        'description': 'Commands to manage the Web dashboard (deprecated)',
        'function': cmd_web
    }
    config.CLI_COMMANDS['ssh'] = {
        'description': 'Shorthand to obtain a shell in the running container',
        'function': cmd_ssh
    }

    # load CLI plugins
    bootstrap.load_plugins(scope=bootstrap.PLUGIN_SCOPE_COMMANDS)

    # create final usage string
    additional_params = []
    additional_commands = ''
    for cmd in sorted(config.CLI_COMMANDS.keys()):
        cmd_details = config.CLI_COMMANDS[cmd]
        additional_commands += '\n  %s%s%s' % (cmd, (20 - len(cmd)) * ' ',
                                               cmd_details['description'])
        for param in cmd_details.get('parameters', []):
            additional_params.append(param)
    additional_params = '\n'.join(additional_params)
    doc_string = __doc__ % (additional_commands, additional_params)

    args = docopt(doc_string, options_first=True)

    if args['--version']:
        print(constants.VERSION)
        sys.exit(0)

    if args['--debug']:
        os.environ['DEBUG'] = '1'

    # invoke subcommand
    argv = [args['<command>']] + args['<args>']
    subcommand = config.CLI_COMMANDS.get(args['<command>'])
    if subcommand:
        try:
            subcommand['function'](argv, args)
        except Exception as e:
            if os.environ.get('DEBUG') in ['1', 'true']:
                print(traceback.format_exc())
            print('ERROR: %s' % e)
            sys.exit(1)
    else:
        print('ERROR: Invalid command "%s"' % args['<command>'])
        sys.exit(1)
Ejemplo n.º 4
0
def serve(port):
    ensure_webapp_installed()
    load_plugins()

    def noecho(*args, **kwargs):
        pass

    click.echo = noecho
    logging.getLogger('werkzeug').setLevel(logging.ERROR)
    app.run(port=int(port), threaded=True, host='0.0.0.0')
Ejemplo n.º 5
0
def serve(port):
    os.environ[LOCALSTACK_WEB_PROCESS] = '1'
    ensure_webapp_installed()
    load_plugins()
    canonicalize_api_names()

    backend_url = 'http://localhost:%s' % port
    config.USE_SSL = True
    services_infra.start_proxy(config.PORT_WEB_UI_SSL, backend_url)

    generic_proxy.serve_flask_app(app=app, port=port, quiet=True)
Ejemplo n.º 6
0
def start_infra(asynchronous=False, apis=None):
    try:
        os.environ[LOCALSTACK_INFRA_PROCESS] = "1"

        is_in_docker = in_docker()
        # print a warning if we're not running in Docker but using Docker based LAMBDA_EXECUTOR
        if not is_in_docker and "docker" in config.LAMBDA_EXECUTOR and not is_linux():
            print(
                (
                    "!WARNING! - Running outside of Docker with $LAMBDA_EXECUTOR=%s can lead to "
                    "problems on your OS. The environment variable $LOCALSTACK_HOSTNAME may not "
                    "be properly set in your Lambdas."
                )
                % config.LAMBDA_EXECUTOR
            )

        if (
            is_in_docker
            and not config.LAMBDA_REMOTE_DOCKER
            and not os.environ.get("HOST_TMP_FOLDER")
        ):
            print(
                "!WARNING! - Looks like you have configured $LAMBDA_REMOTE_DOCKER=0 - "
                "please make sure to configure $HOST_TMP_FOLDER to point to your host's $TMPDIR"
            )

        print_runtime_information(is_in_docker)

        # apply patches
        patch_urllib3_connection_pool(maxsize=128)
        patch_instance_tracker_meta()

        # load plugins
        load_plugins()

        # with plugins loaded, now start the infrastructure
        thread = do_start_infra(asynchronous, apis, is_in_docker)

        if not asynchronous and thread:
            # We're making sure that we stay in the execution context of the
            # main thread, otherwise our signal handlers don't work
            SHUTDOWN_INFRA.wait()

        return thread

    except KeyboardInterrupt:
        print("Shutdown")
    except Exception as e:
        print("Error starting infrastructure: %s %s" % (e, traceback.format_exc()))
        sys.stdout.flush()
        raise e
    finally:
        if not asynchronous:
            stop_infra()
Ejemplo n.º 7
0
def install_all_components():
    # load plugins
    os.environ[LOCALSTACK_INFRA_PROCESS] = '1'
    bootstrap.load_plugins()
    # install all components
    install_components(DEFAULT_SERVICE_PORTS.keys())
Ejemplo n.º 8
0
def start_infra(asynchronous=False, apis=None):
    try:
        os.environ[LOCALSTACK_INFRA_PROCESS] = '1'

        is_in_docker = in_docker()
        # print a warning if we're not running in Docker but using Docker based LAMBDA_EXECUTOR
        if not is_in_docker and 'docker' in config.LAMBDA_EXECUTOR and not is_linux(
        ):
            print((
                '!WARNING! - Running outside of Docker with $LAMBDA_EXECUTOR=%s can lead to '
                'problems on your OS. The environment variable $LOCALSTACK_HOSTNAME may not '
                'be properly set in your Lambdas.') % config.LAMBDA_EXECUTOR)

        if is_in_docker and config.LAMBDA_REMOTE_DOCKER and not os.environ.get(
                'HOST_TMP_FOLDER'):
            print(
                '!WARNING! - Looks like you have configured $LAMBDA_REMOTE_DOCKER=1 - '
                "please make sure to configure $HOST_TMP_FOLDER to point to your host's $TMPDIR"
            )

        # apply patches
        patch_urllib3_connection_pool(maxsize=128)

        # load plugins
        load_plugins()

        event_publisher.fire_event(event_publisher.EVENT_START_INFRA, {
            'd': is_in_docker and 1 or 0,
            'c': in_ci() and 1 or 0
        })

        # set up logging
        setup_logging()

        # prepare APIs
        apis = canonicalize_api_names(apis)
        # set environment
        os.environ['AWS_REGION'] = config.DEFAULT_REGION
        os.environ['ENV'] = ENV_DEV
        # register signal handlers
        if not os.environ.get(ENV_INTERNAL_TEST_RUN):
            register_signal_handlers()
        # make sure AWS credentials are configured, otherwise boto3 bails on us
        check_aws_credentials()
        # install libs if not present
        install.install_components(apis)
        # Some services take a bit to come up
        sleep_time = 5
        # start services
        thread = None

        # loop through plugins and start each service
        for name, plugin in SERVICE_PLUGINS.items():
            if plugin.is_enabled(api_names=apis):
                record_service_health(name, 'starting')
                t1 = plugin.start(asynchronous=True)
                thread = thread or t1

        time.sleep(sleep_time)
        # ensure that all infra components are up and running
        check_infra(apis=apis)
        # restore persisted data
        persistence.restore_persisted_data(apis=apis)
        print('Ready.')
        sys.stdout.flush()
        if not asynchronous and thread:
            # this is a bit of an ugly hack, but we need to make sure that we
            # stay in the execution context of the main thread, otherwise our
            # signal handlers don't work
            while True:
                time.sleep(1)
        return thread
    except KeyboardInterrupt:
        print('Shutdown')
    except Exception as e:
        print('Error starting infrastructure: %s %s' %
              (e, traceback.format_exc()))
        sys.stdout.flush()
        raise e
    finally:
        if not asynchronous:
            stop_infra()
Ejemplo n.º 9
0
def main():
    LOG.info("LocalStack version: %s" % constants.VERSION)
    # set basic CLI commands
    config.CLI_COMMANDS["infra"] = {
        "description": "Commands to manage the infrastructure",
        "function": cmd_infra,
    }
    config.CLI_COMMANDS["start"] = {
        "description": "Shorthand to start the infrastructure",
        "function": cmd_infra,
    }
    config.CLI_COMMANDS["ssh"] = {
        "description": "Shorthand to obtain a shell in the running container",
        "function": cmd_ssh,
    }
    config.CLI_COMMANDS["status"] = {
        "description": "Obtain status details about the installation",
        "function": cmd_status,
    }
    config.CLI_COMMANDS["config"] = {
        "description": "Validate docker configurations",
        "function": cmd_config,
    }

    # load CLI plugins
    bootstrap.load_plugins(scope=bootstrap.PLUGIN_SCOPE_COMMANDS)

    # create final usage string
    additional_params = []
    additional_commands = ""
    for cmd in sorted(config.CLI_COMMANDS.keys()):
        cmd_details = config.CLI_COMMANDS[cmd]
        additional_commands += "\n  %s%s%s" % (
            cmd,
            (20 - len(cmd)) * " ",
            cmd_details["description"],
        )
        for param in cmd_details.get("parameters", []):
            additional_params.append(param)
    additional_params = "\n".join(additional_params)
    doc_string = __doc__ % (additional_commands, additional_params)

    args = docopt(doc_string, options_first=True)

    if args["--version"]:
        print(constants.VERSION)
        sys.exit(0)

    if args["--debug"]:
        config.DEBUG = True
        os.environ["DEBUG"] = "1"

    # set up logging (after DEBUG has been configured)
    setup_logging()

    # invoke subcommand
    argv = [args["<command>"]] + args["<args>"]
    subcommand = config.CLI_COMMANDS.get(args["<command>"])
    if subcommand:
        try:
            subcommand["function"](argv, args)
        except Exception as e:
            if os.environ.get("DEBUG") in ["1", "true"]:
                print(traceback.format_exc())
            print("ERROR: %s" % e)
            sys.exit(1)
    else:
        print('ERROR: Invalid command "%s"' % args["<command>"])
        sys.exit(1)
Ejemplo n.º 10
0
def install_all_components():
    # load plugins
    bootstrap.load_plugins()
    # install all components
    install_components(DEFAULT_SERVICE_PORTS.keys())