-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_nginx.py
50 lines (38 loc) · 1.12 KB
/
control_nginx.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
import os
import subprocess
import time
def status():
result = subprocess.run(
["tasklist", "/FI", "IMAGENAME eq nginx.exe"], capture_output=True, text=True
)
if "nginx.exe" in result.stdout:
return "running"
else:
return "stopped"
# 1
def start(nginx_directory):
os.chdir(nginx_directory)
subprocess.Popen(["nginx"], capture_output=True, text=True)
# 2
def stop(nginx_directory):
os.chdir(nginx_directory)
if status() == "running":
subprocess.run(["nginx", "-s", "stop"], capture_output=True, text=True)
time.sleep(0.5)
# 3
def quit(nginx_directory):
os.chdir(nginx_directory)
if status() == "running":
subprocess.run(["nginx", "-s", "quit"], capture_output=True, text=True)
time.sleep(0.5)
# 4
def taskkill():
if status() == "running":
subprocess.run(
["taskkill", "/F", "/IM", "nginx.exe"], capture_output=True, text=True
)
# 5
def reload(nginx_directory):
os.chdir(nginx_directory)
if status() == "running":
subprocess.run(["nginx", "-s", "reload"], capture_output=True, text=True)