-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_all_servers_venv.py
More file actions
170 lines (133 loc) · 5.37 KB
/
start_all_servers_venv.py
File metadata and controls
170 lines (133 loc) · 5.37 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"""
Script to start all backend servers using virtual environment Python
"""
import subprocess
import sys
import os
from pathlib import Path
# Get the project root directory
PROJECT_ROOT = Path(__file__).parent
BACKEND_DIR = PROJECT_ROOT / "backend"
# Virtual environment paths (adjust if your venv has a different name)
VENV_DIR = PROJECT_ROOT / "venv"
# Determine Python executable path based on OS
if sys.platform == "win32":
VENV_PYTHON = VENV_DIR / "Scripts" / "python.exe"
else:
VENV_PYTHON = VENV_DIR / "bin" / "python"
# Define all server paths
SERVERS = [
("TCP Chat Server", BACKEND_DIR / "tcp_chat" / "server.py", 9009),
("File Transfer Server", BACKEND_DIR / "file_transfer" / "server.py", 9010),
("Collab Server", BACKEND_DIR / "collab" / "server.py", 9011),
("Code Exec Server", BACKEND_DIR / "code_exec" / "server.py", 9012),
("Room MGMT Server", BACKEND_DIR / "room_mgmt" / "server.py", 9013),
]
def check_venv():
"""Check if virtual environment exists"""
if not VENV_DIR.exists():
print(f"❌ Virtual environment not found at: {VENV_DIR}")
print("\nTo create a virtual environment, run:")
print(f" python -m venv venv")
print(f" .\\venv\\Scripts\\activate (Windows)")
print(f" pip install -r requirements.txt")
return False
if not VENV_PYTHON.exists():
print(f"❌ Python executable not found at: {VENV_PYTHON}")
return False
print(f"✓ Virtual environment found: {VENV_DIR}")
print(f"✓ Python executable: {VENV_PYTHON}")
return True
def start_servers():
"""Start all servers in separate terminal windows using venv Python"""
if not check_venv():
sys.exit(1)
print("\n" + "=" * 50)
print("Starting all backend servers with venv...")
print("=" * 50 + "\n")
started_count = 0
for name, server_path, port in SERVERS:
if not server_path.exists():
print(f"❌ {name}: File not found at {server_path}")
continue
try:
if sys.platform == "win32":
# Windows: Open each server in a new CMD window with venv Python
cmd = f'start "{name} (Port {port})" cmd /k ""{VENV_PYTHON}" "{server_path}""'
subprocess.Popen(cmd, shell=True, cwd=str(server_path.parent))
else:
# Unix/Linux/Mac: Use gnome-terminal, xterm, or run in background
subprocess.Popen(
[str(VENV_PYTHON), str(server_path)],
cwd=str(server_path.parent),
start_new_session=True
)
print(f"✓ {name} (Port {port}): Started")
started_count += 1
except Exception as e:
print(f"❌ {name}: Failed to start - {e}")
print("\n" + "=" * 50)
print(f"Started {started_count}/{len(SERVERS)} servers")
print("=" * 50)
print("\nEach server is running in its own terminal window.")
print("Close the terminal windows to stop the servers.")
print("\nServer Ports:")
print(" - TCP Chat: http://localhost:9009")
print(" - File Transfer: http://localhost:9010")
print(" - Collab: http://localhost:9011")
print(" - Code Exec: http://localhost:9012")
print(" - Room MGMT: http://localhost:9013")
def start_frontend():
"""Optionally start the Streamlit frontend"""
frontend_path = PROJECT_ROOT / "frontend" / "app.py"
if not frontend_path.exists():
print(f"\n❌ Frontend not found at: {frontend_path}")
return
print("\n" + "=" * 50)
print("Starting Streamlit Frontend...")
print("=" * 50)
try:
if sys.platform == "win32":
# Get streamlit from venv Scripts folder
streamlit_exe = VENV_DIR / "Scripts" / "streamlit.exe"
if streamlit_exe.exists():
cmd = f'start "SyncroX Frontend" cmd /k ""{streamlit_exe}" run "{frontend_path}""'
else:
# Fallback: use python -m streamlit
cmd = f'start "SyncroX Frontend" cmd /k ""{VENV_PYTHON}" -m streamlit run "{frontend_path}""'
subprocess.Popen(cmd, shell=True, cwd=str(PROJECT_ROOT))
else:
subprocess.Popen(
[str(VENV_PYTHON), "-m", "streamlit", "run", str(frontend_path)],
cwd=str(PROJECT_ROOT),
start_new_session=True
)
print("✓ Streamlit Frontend: Started")
print(" - URL: http://localhost:8501")
except Exception as e:
print(f"❌ Frontend: Failed to start - {e}")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Start SyncroX servers with venv")
parser.add_argument(
"--with-frontend", "-f",
action="store_true",
help="Also start the Streamlit frontend"
)
parser.add_argument(
"--frontend-only",
action="store_true",
help="Only start the Streamlit frontend"
)
args = parser.parse_args()
if args.frontend_only:
if check_venv():
start_frontend()
else:
start_servers()
if args.with_frontend:
start_frontend()
# Start backend servers
# python start_all_servers_venv.py
# Start frontend
# streamlit run frontend/streamlit_app/app.py --server.address 0.0.0.0