-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
108 lines (94 loc) · 3.56 KB
/
run.py
File metadata and controls
108 lines (94 loc) · 3.56 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import sys
import signal
import platform
import subprocess
from datetime import datetime
def print_colored(text, color):
colors = {
'GREEN': '\033[92m',
'YELLOW': '\033[93m',
'RED': '\033[91m',
'NC': '\033[0m'
}
print(f"{colors[color]}{text}{colors['NC']}")
class IntelStackServer:
def __init__(self):
self.debug = "--debug" in sys.argv
self.is_windows = platform.system() == "Windows"
# Use virtual environment python
if self.is_windows:
self.venv_python = os.path.join("venv", "Scripts", "python.exe")
else:
self.venv_python = os.path.join("venv", "bin", "python")
self.process = None
self.port = "8000" # Default port
def check_redis(self):
if self.is_windows:
redis_path = "C:\\Program Files\\Redis\\redis-server.exe"
if not os.path.exists(redis_path):
print_colored("Redis server not found!", "RED")
return False
else:
try:
subprocess.run(
["systemctl", "is-active", "--quiet", "redis-server"]
)
except subprocess.CalledProcessError:
print_colored("Starting Redis server...", "YELLOW")
subprocess.run(["sudo", "systemctl", "start", "redis-server"])
return True
def start(self):
if not self.check_redis():
return
print_colored("\n" + "="*50, "GREEN")
print_colored("Starting IntelStack server...", "GREEN")
base_url = f"http://localhost:{self.port}"
print_colored(f"\nApplication URLs:", "GREEN")
print_colored(f" Main URL: {base_url}", "GREEN")
print_colored(f" Admin URL: {base_url}/admin", "GREEN")
print_colored("\nPress Ctrl+C to stop the server", "YELLOW")
print_colored("="*50 + "\n", "GREEN")
# Build command using venv python directly
server_cmd = f'"{self.venv_python}" manage.py runserver 0.0.0.0:{self.port}'
try:
env = os.environ.copy()
env["PYTHONPATH"] = os.getcwd()
if self.debug:
# In debug mode, show output directly in console
self.process = subprocess.Popen(
server_cmd,
shell=True,
env=env
)
else:
# In normal mode, suppress output
self.process = subprocess.Popen(
server_cmd,
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
env=env
)
self.process.wait()
except KeyboardInterrupt:
self.stop()
except Exception as e:
print_colored(f"Error starting server: {str(e)}", "RED")
if self.debug:
import traceback
print_colored(traceback.format_exc(), "RED")
self.stop()
def stop(self):
if self.process:
print_colored("\nStopping IntelStack server...", "YELLOW")
if self.is_windows:
subprocess.run(["taskkill", "/F", "/T", "/PID", str(self.process.pid)])
else:
self.process.terminate()
self.process.wait()
print_colored("Server stopped", "GREEN")
if __name__ == "__main__":
server = IntelStackServer()
signal.signal(signal.SIGINT, lambda sig, frame: server.stop())
server.start()