You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
# -*- coding: utf-8 -*-
|
|
import subprocess
|
|
import multiprocessing
|
|
import os
|
|
import json
|
|
|
|
|
|
def load_config():
|
|
with open("config.json", "r") as f:
|
|
return json.load(f)
|
|
|
|
|
|
config = load_config()
|
|
PREFIX = "clash-multi-"
|
|
START = 1
|
|
END = config["total_container"]
|
|
|
|
|
|
def stop_and_remove_container(container_id):
|
|
container_name = f"{PREFIX}{container_id}"
|
|
print(f"Processing container: {container_name}")
|
|
|
|
try:
|
|
rm_cmd = ["docker", "rm", "-f", container_name]
|
|
subprocess.run(rm_cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
|
print(f"Successfully removed container: {container_name}")
|
|
except subprocess.CalledProcessError as e:
|
|
error_message = e.stderr.decode().strip() if e.stderr else "Unknown error"
|
|
print(f"Error processing container {container_name}: {error_message}")
|
|
|
|
|
|
def main():
|
|
with multiprocessing.Pool(processes=os.cpu_count() or 4) as pool:
|
|
pool.map(stop_and_remove_container, range(START, END + 1))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|