-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_stop_and_clean.py
58 lines (47 loc) · 1.99 KB
/
05_stop_and_clean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import subprocess
import os
def check_docker_compose_installed():
try:
subprocess.run(["docker-compose", "--version"], check=True, stdout=subprocess.DEVNULL)
print("Docker Compose is installed.")
except subprocess.CalledProcessError:
print("Docker Compose is not installed or not found in PATH.")
exit(1)
def stop_and_remove_containers():
try:
print("Stopping and removing containers...")
subprocess.run(["docker-compose", "down", "-v"], check=True)
print("Containers stopped and removed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error occurred while stopping containers: {e}")
exit(1)
def remove_solr_data():
data_dir = "./solr_data" # Adjust this path if your Solr data is stored elsewhere
if os.path.exists(data_dir):
try:
print(f"Removing Solr data directory: {data_dir}")
subprocess.run(["rm", "-rf", data_dir], check=True)
print("Solr data removed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error occurred while removing Solr data: {e}")
exit(1)
else:
print(f"Solr data directory not found: {data_dir}")
def clean_zookeeper_data():
zk_data_dir = "./zk_data" # Adjust this path if your ZooKeeper data is stored elsewhere
if os.path.exists(zk_data_dir):
try:
print(f"Removing ZooKeeper data directory: {zk_data_dir}")
subprocess.run(["rm", "-rf", zk_data_dir], check=True)
print("ZooKeeper data removed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error occurred while removing ZooKeeper data: {e}")
exit(1)
else:
print(f"ZooKeeper data directory not found: {zk_data_dir}")
if __name__ == "__main__":
check_docker_compose_installed()
stop_and_remove_containers()
remove_solr_data()
clean_zookeeper_data()
print("Cleanup completed successfully.")