-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_config.py
33 lines (26 loc) · 1 KB
/
delete_config.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
import os
import subprocess
def delete_domain(domain_name):
available_path = f"/etc/nginx/sites-available/{domain_name}"
enabled_path = f"/etc/nginx/sites-enabled/{domain_name}"
if os.path.islink(enabled_path):
os.remove(enabled_path)
print(f"Removed symlink: {enabled_path}")
else:
print(f"No symlink found for: {enabled_path}")
if os.path.exists(available_path):
os.remove(available_path)
print(f"Removed config file: {available_path}")
else:
print(f"No config file found for: {available_path}")
result = subprocess.run(["sudo", "nginx", "-t"], capture_output=True, text=True)
if result.returncode == 0:
subprocess.run(["sudo", "systemctl", "reload", "nginx"])
print("Nginx configuration is valid. Reloaded nginx.")
else:
print("Nginx configuration test failed:")
print(result.stdout)
print(result.stderr)
if __name__ == "__main__":
domain_to_delete = ""
delete_domain(domain_to_delete)