-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_dev.py
More file actions
103 lines (83 loc) · 2.54 KB
/
run_dev.py
File metadata and controls
103 lines (83 loc) · 2.54 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
import os
import shutil
import subprocess
import sys
import time
def _require_command(name: str, install_hint: str) -> bool:
if shutil.which(name):
return True
print(f"[Missing] `{name}` not found in PATH.")
print(f" {install_hint}")
return False
def _stop_process(proc: subprocess.Popen, label: str) -> None:
if proc.poll() is not None:
return
print(f"Stopping {label}...")
proc.terminate()
try:
proc.wait(timeout=5)
except subprocess.TimeoutExpired:
proc.kill()
def start_services() -> None:
root = os.path.dirname(os.path.abspath(__file__))
frontend_dir = os.path.join(root, "frontend")
backend_dir = os.path.join(root, "backend")
print("Starting 0xRIP split stack...")
ok = True
ok &= _require_command("bun", "Install Bun: https://bun.sh")
ok &= _require_command("uv", "Install uv: https://docs.astral.sh/uv/getting-started/installation/")
if not os.path.isdir(frontend_dir):
print(f"[Missing] frontend directory: {frontend_dir}")
ok = False
if not os.path.isdir(backend_dir):
print(f"[Missing] backend directory: {backend_dir}")
ok = False
if not ok:
sys.exit(1)
backend_cmd = [
"uv",
"run",
"uvicorn",
"backend.main:app",
"--host",
"0.0.0.0",
"--port",
"8000",
"--reload",
]
frontend_cmd = [
"bun",
"run",
"dev",
"--",
"--host",
"0.0.0.0",
"--port",
"5173",
]
print("Starting backend (uv + FastAPI) on :8000 ...")
backend_process = subprocess.Popen(backend_cmd, cwd=root)
time.sleep(1.5)
print("Starting frontend (bun + Vite) on :5173 ...")
frontend_process = subprocess.Popen(frontend_cmd, cwd=frontend_dir)
print("\nServices started:")
print("- Frontend: http://localhost:5173")
print("- Backend : http://localhost:8000")
print("Press Ctrl+C to stop.")
try:
while True:
if backend_process.poll() is not None:
print("Backend exited unexpectedly.")
break
if frontend_process.poll() is not None:
print("Frontend exited unexpectedly.")
break
time.sleep(1)
except KeyboardInterrupt:
print("\nReceived Ctrl+C. Shutting down...")
finally:
_stop_process(frontend_process, "frontend")
_stop_process(backend_process, "backend")
print("Bye.")
if __name__ == "__main__":
start_services()