How to use stop_container method in localstack

Best Python code snippet using localstack_python

stop-clp

Source:stop-clp Github

copy

Full Screen

...51 container_exists, \52 validate_and_load_config_file, \53 validate_and_load_db_credentials_file, \54 validate_and_load_queue_credentials_file55def stop_container(container_name: str):56 if not container_exists(container_name):57 return58 logger.info(f"Stopping {container_name}...")59 cmd = ['docker', 'stop', container_name]60 subprocess.run(cmd, stdout=subprocess.DEVNULL, check=True)61 logger.info(f"Stopped {container_name}.")62def main(argv):63 default_config_file_path = clp_home / CLP_DEFAULT_CONFIG_FILE_RELATIVE_PATH64 args_parser = argparse.ArgumentParser(description="Stops CLP")65 args_parser.add_argument('--config', '-c', default=str(default_config_file_path),66 help="CLP package configuration file.")67 component_args_parser = args_parser.add_subparsers(dest='component_name')68 component_args_parser.add_parser(DB_COMPONENT_NAME)69 component_args_parser.add_parser(QUEUE_COMPONENT_NAME)70 component_args_parser.add_parser(SCHEDULER_COMPONENT_NAME)71 component_args_parser.add_parser(WORKER_COMPONENT_NAME)72 parsed_args = args_parser.parse_args(argv[1:])73 if parsed_args.component_name:74 component_name = parsed_args.component_name75 else:76 component_name = ""77 # Validate and load config file78 try:79 config_file_path = pathlib.Path(parsed_args.config)80 clp_config = validate_and_load_config_file(config_file_path, default_config_file_path, clp_home)81 # Validate and load necessary credentials82 if component_name in ['', DB_COMPONENT_NAME]:83 validate_and_load_db_credentials_file(clp_config, clp_home, False)84 if component_name in ['', QUEUE_COMPONENT_NAME, SCHEDULER_COMPONENT_NAME, WORKER_COMPONENT_NAME]:85 validate_and_load_queue_credentials_file(clp_config, clp_home, False)86 except:87 logger.exception("Failed to load config.")88 return -189 try:90 # Read instance ID from file91 logs_dir = clp_config.logs_directory92 instance_id_file_path = logs_dir / 'instance-id'93 if not (logs_dir.exists() and logs_dir.is_dir() and instance_id_file_path.exists()):94 # No instance ID file, so nothing to do95 return 096 with open(instance_id_file_path, 'r') as f:97 instance_id = f.readline()98 if '' == component_name or WORKER_COMPONENT_NAME == component_name:99 stop_container(f'clp-{WORKER_COMPONENT_NAME}-{instance_id}')100 if '' == component_name or SCHEDULER_COMPONENT_NAME == component_name:101 container_name = f'clp-{SCHEDULER_COMPONENT_NAME}-{instance_id}'102 stop_container(container_name)103 container_config_file_path = logs_dir / f'{container_name}.yml'104 if container_config_file_path.exists():105 container_config_file_path.unlink()106 if '' == component_name or QUEUE_COMPONENT_NAME == component_name:107 container_name = f'clp-{QUEUE_COMPONENT_NAME}-{instance_id}'108 stop_container(container_name)109 queue_config_file_path = logs_dir / f'{container_name}.conf'110 if queue_config_file_path.exists():111 queue_config_file_path.unlink()112 if '' == component_name or DB_COMPONENT_NAME == component_name:113 stop_container(f'clp-db-{instance_id}')114 if '' == component_name:115 # NOTE: We can only remove the instance ID file if all containers have been stopped.116 # Currently, we only remove the instance file when all containers are stopped at once.117 # If a single container is stopped, it's expensive to check if the others are running,118 # so instead we don't remove the instance file. In the worst case, a user will have to119 # remove it manually.120 instance_id_file_path.unlink()121 except:122 logger.exception("Failed to stop CLP.")123 return -1124 return 0125if '__main__' == __name__:...

Full Screen

Full Screen

cmd.py

Source:cmd.py Github

copy

Full Screen

1# coding=utf-82import os3import time4def cmd(stop_container, start_container):5 """6 关闭启动docker容器,防止连接数过多卡死7 """8 if isinstance(stop_container, str):9 os.system("docker stop " + stop_container)10 elif isinstance(stop_container, list):11 for i in range(len(stop_container)):12 os.system("docker stop " + stop_container[i])13 else:14 print('数据类型错误')15 time.sleep(1)16 if isinstance(start_container, str):17 os.system("docker stop " + start_container)18 elif isinstance(start_container, list):19 for i in range(len(start_container)):20 os.system("docker stop " + start_container[i])21 else:22 print('数据类型错误')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful