def start_dns_server(asynchronous=False): try: # start local DNS server, if present from localstack_ext import config as config_ext from localstack_ext.services import dns_server if config_ext.DNS_ADDRESS in config.FALSE_STRINGS: return if is_port_open(PORT_DNS): return if is_root(): result = dns_server.start_servers() if not asynchronous: sleep_forever() return result env_vars = {} for env_var in config.CONFIG_ENV_VARS: if env_var.startswith("DNS_"): value = os.environ.get(env_var, None) if value is not None: env_vars[env_var] = value # note: running in a separate process breaks integration with Route53 (to be fixed for local dev mode!) return run_process_as_sudo("dns", PORT_DNS, asynchronous=asynchronous, env_vars=env_vars) except Exception: pass
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_version(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: # 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 sleep_forever() 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()
def do_start_infra(asynchronous, apis, is_in_docker): 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 is_local_test_mode(): 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 sleep_forever() return thread
def start_dns_server(asynchronous=False): try: # start local DNS server, if present from localstack_ext import config as config_ext from localstack_ext.services import dns_server if config_ext.DNS_ADDRESS in config.FALSE_STRINGS: return if is_port_open(PORT_DNS): return if is_root(): result = dns_server.start_servers() if not asynchronous: sleep_forever() return result # note: running in a separate process breaks integration with Route53 (to be fixed for local dev mode!) return run_process_as_sudo("dns", PORT_DNS, asynchronous=asynchronous) except Exception: pass