def __init__(self, params): props_file = params['properties_file'] env_vars = params['env_vars'] cmd = kclipy_helper.get_kcl_app_command('java', MULTI_LANG_DAEMON_CLASS, props_file) if not params['log_file']: params['log_file'] = '%s.log' % props_file TMP_FILES.append(params['log_file']) env = aws_stack.get_environment() quiet = aws_stack.is_local_env(env) ShellCommandThread.__init__(self, cmd, outfile=params['log_file'], env_vars=env_vars, quiet=quiet)
def do_run(cmd, asynchronous, print_output=None, env_vars={}): sys.stdout.flush() if asynchronous: if is_debug() and print_output is None: print_output = True outfile = subprocess.PIPE if print_output else None t = ShellCommandThread(cmd, outfile=outfile, env_vars=env_vars) t.start() TMP_THREADS.append(t) return t return run(cmd, env_vars=env_vars)
def do_run(cmd, asynchronous, print_output=None, env_vars={}, auto_restart=False): sys.stdout.flush() if asynchronous: if config.DEBUG and print_output is None: print_output = True outfile = subprocess.PIPE if print_output else None t = ShellCommandThread(cmd, outfile=outfile, env_vars=env_vars, auto_restart=auto_restart) t.start() TMP_THREADS.append(t) return t return run(cmd, env_vars=env_vars)
def do_run(cmd, asynchronous, print_output=False): sys.stdout.flush() if asynchronous: if is_debug(): print_output = True outfile = subprocess.PIPE if print_output else None t = ShellCommandThread(cmd, outfile=outfile) t.start() TMP_THREADS.append(t) return t else: return run(cmd)
def __init__(self, params): props_file = params['properties_file'] env_vars = params['env_vars'] cmd = kclipy_helper.get_kcl_app_command('java', MULTI_LANG_DAEMON_CLASS, props_file) if not params['log_file']: params['log_file'] = '%s.log' % props_file TMP_FILES.append(params['log_file']) # print(cmd) env = aws_stack.get_environment() quiet = env.region == REGION_LOCAL ShellCommandThread.__init__(self, cmd, outfile=params['log_file'], env_vars=env_vars, quiet=quiet)
def __init__(self, params): props_file = params["properties_file"] env_vars = params["env_vars"] cmd = kclipy_helper.get_kcl_app_command("java", MULTI_LANG_DAEMON_CLASS, props_file) if not params["log_file"]: params["log_file"] = "%s.log" % props_file TMP_FILES.append(params["log_file"]) env = aws_stack.get_environment() quiet = aws_stack.is_local_env(env) ShellCommandThread.__init__( self, cmd, outfile=params["log_file"], env_vars=env_vars, quiet=quiet )
def do_start_thread(self) -> FuncThread: cmd = self._create_shell_command() LOG.debug("starting kinesis process %s", cmd) t = ShellCommandThread( cmd, strip_color=True, log_listener=self._log_listener, auto_restart=True, ) TMP_THREADS.append(t) t.start() return t
def start_server_process(port): if '__server__' in API_SERVERS: return port = port or MULTI_SERVER_PORT API_SERVERS['__server__'] = config = {'port': port} LOG.info('Starting multi API server process on port %s' % port) cmd = '"%s" "%s" %s' % (sys.executable, __file__, port) env_vars = { 'PYTHONPATH': '.:%s' % constants.LOCALSTACK_ROOT_FOLDER } thread = ShellCommandThread(cmd, outfile=subprocess.PIPE, env_vars=env_vars, inherit_cwd=True) thread.start() TMP_THREADS.append(thread) config['thread'] = thread wait_for_port_open(port, retries=10, sleep_time=1) return thread
def start_server_process(port): if "__server__" in API_SERVERS: return API_SERVERS["__server__"]["thread"] port = port or get_multi_server_port() API_SERVERS["__server__"] = config = {"port": port} LOG.info("Starting multi API server process on port %s" % port) if RUN_SERVER_IN_PROCESS: cmd = '"%s" "%s" %s' % (sys.executable, __file__, port) env_vars = {"PYTHONPATH": ".:%s" % constants.LOCALSTACK_ROOT_FOLDER} thread = ShellCommandThread(cmd, outfile=subprocess.PIPE, env_vars=env_vars, inherit_cwd=True) thread.start() else: thread = start_server(port, asynchronous=True) TMP_THREADS.append(thread) config["thread"] = thread wait_for_port_open(port, retries=20, sleep_time=1) return thread
def do_start_thread(self) -> FuncThread: self._ensure_installed() self._init_directories() cmd = self._create_run_command(additional_settings=self.command_settings) cmd = " ".join(cmd) if is_root() and self.os_user: # run the opensearch process as a non-root user (when running in docker) cmd = f"su {self.os_user} -c '{cmd}'" env_vars = self._create_env_vars() LOG.info("starting %s: %s with env %s", self.bin_name, cmd, env_vars) t = ShellCommandThread( cmd, env_vars=env_vars, strip_color=True, log_listener=self._log_listener, ) t.start() return t
def do_run( cmd: Union[str, List], asynchronous: bool, print_output: bool = None, env_vars: Dict[str, str] = {}, auto_restart=False, strip_color: bool = False, ): sys.stdout.flush() if asynchronous: if config.DEBUG and print_output is None: print_output = True outfile = subprocess.PIPE if print_output else None t = ShellCommandThread( cmd, outfile=outfile, env_vars=env_vars, auto_restart=auto_restart, strip_color=strip_color, ) t.start() TMP_THREADS.append(t) return t return run(cmd, env_vars=env_vars)
def start_infra_in_docker(): # load plugins before starting the docker container plugin_configs = load_plugins() plugin_run_params = ' '.join([ entry.get('docker', {}).get('run_flags', '') for entry in plugin_configs]) services = os.environ.get('SERVICES', '') entrypoint = os.environ.get('ENTRYPOINT', '') cmd = os.environ.get('CMD', '') user_flags = os.environ.get('DOCKER_FLAGS', '') image_name = os.environ.get('IMAGE_NAME', constants.DOCKER_IMAGE_NAME) service_ports = config.SERVICE_PORTS force_noninteractive = os.environ.get('FORCE_NONINTERACTIVE', '') # construct port mappings ports_list = sorted(service_ports.values()) start_port = 0 last_port = 0 port_ranges = [] for i in range(0, len(ports_list)): if not start_port: start_port = ports_list[i] if not last_port: last_port = ports_list[i] if ports_list[i] > last_port + 1: port_ranges.append([start_port, last_port]) start_port = ports_list[i] elif i >= len(ports_list) - 1: port_ranges.append([start_port, ports_list[i]]) last_port = ports_list[i] port_mappings = ' '.join( '-p {start}-{end}:{start}-{end}'.format(start=entry[0], end=entry[1]) if entry[0] < entry[1] else '-p {port}:{port}'.format(port=entry[0]) for entry in port_ranges) if services: port_mappings = '' for service, port in service_ports.items(): port_mappings += ' -p {port}:{port}'.format(port=port) env_str = '' for env_var in config.CONFIG_ENV_VARS: value = os.environ.get(env_var, None) if value is not None: env_str += '-e %s="%s" ' % (env_var, value) data_dir_mount = '' data_dir = os.environ.get('DATA_DIR', None) if data_dir is not None: container_data_dir = '/tmp/localstack_data' data_dir_mount = '-v "%s:%s" ' % (data_dir, container_data_dir) env_str += '-e DATA_DIR="%s" ' % container_data_dir interactive = '' if force_noninteractive or in_ci() else '-it ' # append space if parameter is set user_flags = '%s ' % user_flags if user_flags else user_flags entrypoint = '%s ' % entrypoint if entrypoint else entrypoint plugin_run_params = '%s ' % plugin_run_params if plugin_run_params else plugin_run_params docker_cmd = ('docker run %s%s%s%s%s' + '-p 8080:8080 %s %s' + '-v "%s:/tmp/localstack" -v "%s:%s" ' + '-e DOCKER_HOST="unix://%s" ' + '-e HOST_TMP_FOLDER="%s" "%s" %s') % ( interactive, entrypoint, env_str, user_flags, plugin_run_params, port_mappings, data_dir_mount, config.TMP_FOLDER, config.DOCKER_SOCK, config.DOCKER_SOCK, config.DOCKER_SOCK, config.HOST_TMP_FOLDER, image_name, cmd ) mkdir(config.TMP_FOLDER) run_cmd_safe(cmd='chmod -R 777 "%s"' % config.TMP_FOLDER) print(docker_cmd) t = ShellCommandThread(docker_cmd, outfile=subprocess.PIPE) t.start() time.sleep(2) t.process.wait() sys.exit(t.process.returncode)
signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGINT, signal_handler) SIGNAL_HANDLERS_SETUP = True def is_debug(): return os.environ.get('DEBUG', '').strip() not in ['', '0', 'false'] def do_run(cmd, async, print_output=False): sys.stdout.flush() if async: if is_debug(): print_output = True outfile = subprocess.PIPE if print_output else None t = ShellCommandThread(cmd, outfile=outfile) t.start() TMP_THREADS.append(t) return t else: return run(cmd) def start_proxy_for_service(service_name, port, default_backend_port, update_listener, quiet=False, params={}): # check if we have a custom backend configured custom_backend_url = os.environ.get('%s_BACKEND' % service_name.upper()) backend_url = custom_backend_url or ('http://%s:%s' % (DEFAULT_BACKEND_HOST, default_backend_port)) return start_proxy(port, backend_url=backend_url, update_listener=update_listener, quiet=quiet, params=params) def start_proxy(port, backend_url, update_listener, quiet=False, params={}):
def start_infra_in_docker(): # load plugins before starting the docker container plugin_configs = load_plugins() plugin_run_params = ' '.join([ entry.get('docker', {}).get('run_flags', '') for entry in plugin_configs]) services = os.environ.get('SERVICES', '') entrypoint = os.environ.get('ENTRYPOINT', '') cmd = os.environ.get('CMD', '') image_name = os.environ.get('IMAGE_NAME', constants.DOCKER_IMAGE_NAME) service_ports = config.SERVICE_PORTS force_noninteractive = os.environ.get('FORCE_NONINTERACTIVE', '') # construct port mappings ports_list = sorted(service_ports.values()) start_port = 0 last_port = 0 port_ranges = [] for i in range(0, len(ports_list)): if not start_port: start_port = ports_list[i] if not last_port: last_port = ports_list[i] if ports_list[i] > last_port + 1: port_ranges.append([start_port, last_port]) start_port = ports_list[i] elif i >= len(ports_list) - 1: port_ranges.append([start_port, ports_list[i]]) last_port = ports_list[i] port_mappings = ' '.join( '-p {start}-{end}:{start}-{end}'.format(start=entry[0], end=entry[1]) if entry[0] < entry[1] else '-p {port}:{port}'.format(port=entry[0]) for entry in port_ranges) if services: port_mappings = '' for service, port in service_ports.items(): port_mappings += ' -p {port}:{port}'.format(port=port) env_str = '' for env_var in config.CONFIG_ENV_VARS: value = os.environ.get(env_var, None) if value is not None: env_str += '-e %s="%s" ' % (env_var, value) data_dir_mount = '' data_dir = os.environ.get('DATA_DIR', None) if data_dir is not None: container_data_dir = '/tmp/localstack_data' data_dir_mount = '-v "%s:%s" ' % (data_dir, container_data_dir) env_str += '-e DATA_DIR="%s" ' % container_data_dir interactive = '' if force_noninteractive or in_ci() else '-it ' # append space if parameter is set entrypoint = '%s ' % entrypoint if entrypoint else entrypoint plugin_run_params = '%s ' % plugin_run_params if plugin_run_params else plugin_run_params docker_cmd = ('docker run %s%s%s%s' + '-p 8080:8080 %s %s' + '-v "%s:/tmp/localstack" -v "%s:%s" ' + '-e DOCKER_HOST="unix://%s" ' + '-e HOST_TMP_FOLDER="%s" "%s" %s') % ( interactive, entrypoint, env_str, plugin_run_params, port_mappings, data_dir_mount, config.TMP_FOLDER, config.DOCKER_SOCK, config.DOCKER_SOCK, config.DOCKER_SOCK, config.HOST_TMP_FOLDER, image_name, cmd ) mkdir(config.TMP_FOLDER) run_cmd_safe(cmd='chmod -R 777 "%s"' % config.TMP_FOLDER) print(docker_cmd) t = ShellCommandThread(docker_cmd, outfile=subprocess.PIPE) t.start() time.sleep(2) t.process.wait() sys.exit(t.process.returncode)
signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGINT, signal_handler) SIGNAL_HANDLERS_SETUP = True def is_debug(): return os.environ.get('DEBUG', '').strip() not in ['', '0', 'false'] def do_run(cmd, async, print_output=False): sys.stdout.flush() if async: if is_debug(): print_output = True outfile = subprocess.PIPE if print_output else None t = ShellCommandThread(cmd, outfile=outfile) t.start() TMP_THREADS.append(t) return t else: return run(cmd) def start_proxy_for_service(service_name, port, default_backend_port, update_listener, quiet=False, params={}): # check if we have a custom backend configured custom_backend_url = os.environ.get('%s_BACKEND' % service_name.upper()) backend_url = custom_backend_url or ('http://%s:%s' % (DEFAULT_BACKEND_HOST, default_backend_port)) return start_proxy(port, backend_url=backend_url, update_listener=update_listener, quiet=quiet, params=params) def start_proxy(port, backend_url, update_listener, quiet=False, params={}):