def parse_service_ports(): """ Parses the environment variable $SERVICE_PORTS with a comma-separated list of services and (optional) ports they should run on: 'service1:port1,service2,service3:port3' """ service_ports = os.environ.get('SERVICES', '').strip() if not service_ports: return DEFAULT_SERVICE_PORTS result = {} for service_port in re.split(r'\s*,\s*', service_ports): parts = re.split(r'[:=]', service_port) service = parts[0] result[service] = int(parts[-1]) if len(parts) > 1 else DEFAULT_SERVICE_PORTS.get(service) # Fix Elasticsearch port - we have 'es' (AWS ES API) and 'elasticsearch' (actual Elasticsearch API) if result.get('es') and not result.get('elasticsearch'): result['elasticsearch'] = DEFAULT_SERVICE_PORTS.get('elasticsearch') return result
def set_service_status(data): command = data.get('command') service = data.get('service') service_ports = config.parse_service_ports() if command == 'start': existing = service_ports.get(service) port = DEFAULT_SERVICE_PORTS.get(service) if existing: status = get_service_status(service, port) if status == 'running': return key_upper = service.upper().replace('-', '_') port_variable = 'PORT_%s' % key_upper service_list = os.environ.get('SERVICES', '').strip() services = [e for e in re.split(r'[\s,]+', service_list) if e] contained = [s for s in services if s.startswith(service)] if not contained: services.append(service) update_config_variable(port_variable, port) new_service_list = ','.join(services) os.environ['SERVICES'] = new_service_list config.populate_configs() LOG.info('Starting service %s on port %s' % (service, port)) SERVICE_PLUGINS[service].start(asynchronous=True) return {}
def parse_service_ports(): """ Parses the environment variable $SERVICES with a comma-separated list of services and (optional) ports they should run on: 'service1:port1,service2,service3:port3' """ service_ports = os.environ.get('SERVICES', '').strip() if not service_ports: return DEFAULT_SERVICE_PORTS result = {} for service_port in re.split(r'\s*,\s*', service_ports): parts = re.split(r'[:=]', service_port) service = parts[0] key_upper = service.upper().replace('-', '_') port_env_name = '%s_PORT' % key_upper # (1) set default port number port_number = DEFAULT_SERVICE_PORTS.get(service) # (2) set port number from <SERVICE>_PORT environment, if present if os.environ.get(port_env_name): port_number = os.environ.get(port_env_name) # (3) set port number from <service>:<port> portion in $SERVICES, if present if len(parts) > 1: port_number = int(parts[-1]) # (4) try to parse as int, fall back to 0 (invalid port) try: port_number = int(port_number) except Exception: port_number = 0 result[service] = port_number return result
def set_service_status(data): command = data.get("command") service = data.get("service") service_ports = config.parse_service_ports() if command == "start": existing = service_ports.get(service) port = DEFAULT_SERVICE_PORTS.get(service) if existing: status = get_service_status(service, port) if status == "running": return key_upper = service.upper().replace("-", "_") port_variable = "PORT_%s" % key_upper service_list = os.environ.get("SERVICES", "").strip() services = [e for e in re.split(r"[\s,]+", service_list) if e] contained = [s for s in services if s.startswith(service)] if not contained: services.append(service) config_listener.update_config_variable(port_variable, port) new_service_list = ",".join(services) os.environ["SERVICES"] = new_service_list # TODO: expensive operation - check if we need to do this here for each service, should be optimized! config.populate_configs() LOG.info("Starting service %s on port %s" % (service, port)) SERVICE_PLUGINS[service].start(asynchronous=True) return {}
def parse_service_ports(): """ Parses the environment variable $SERVICE_PORTS with a comma-separated list of services and (optional) ports they should run on: 'service1:port1,service2,service3:port3' """ service_ports = os.environ.get('SERVICES', '').strip() if not service_ports: return DEFAULT_SERVICE_PORTS result = {} for service_port in re.split(r'\s*,\s*', service_ports): parts = re.split(r'[:=]', service_port) service = parts[0] result[service] = int(parts[-1]) if len(parts) > 1 else DEFAULT_SERVICE_PORTS.get(service) return result
def populate_config_env_var_names(): global CONFIG_ENV_VARS for key, value in DEFAULT_SERVICE_PORTS.items(): clean_key = key.upper().replace("-", "_") CONFIG_ENV_VARS += [ clean_key + "_BACKEND", clean_key + "_PORT_EXTERNAL", "PROVIDER_OVERRIDE_" + clean_key, ] # create variable aliases prefixed with LOCALSTACK_ (except LOCALSTACK_HOSTNAME) CONFIG_ENV_VARS += [ "LOCALSTACK_" + v for v in CONFIG_ENV_VARS if not v.startswith("LOCALSTACK_") ] CONFIG_ENV_VARS = list(set(CONFIG_ENV_VARS))
def install_all_components(): # load plugins os.environ[LOCALSTACK_INFRA_PROCESS] = '1' bootstrap.load_plugins() # install all components install_components(DEFAULT_SERVICE_PORTS.keys())
def install_all_components(): install_components(DEFAULT_SERVICE_PORTS.keys())
def install_all_components(): hooks.install.run() # install all components install_components(DEFAULT_SERVICE_PORTS.keys())
def install_all_components(): # install dependencies - make sure that install_components(..) is called before hooks.install below! install_components(DEFAULT_SERVICE_PORTS.keys()) hooks.install.run()
def install_all_components(): # load plugins bootstrap.load_plugins() # install all components install_components(DEFAULT_SERVICE_PORTS.keys())