forked from kortix-ai/suna
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
252 lines (206 loc) · 8.46 KB
/
start.py
File metadata and controls
252 lines (206 loc) · 8.46 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/usr/bin/env python3
import subprocess
import sys
import platform
import os
import json
IS_WINDOWS = platform.system() == "Windows"
PROGRESS_FILE = ".setup_progress"
# --- ANSI Colors ---
class Colors:
HEADER = "\033[95m"
BLUE = "\033[94m"
CYAN = "\033[96m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RED = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
def load_progress():
"""Loads the last saved step and data from setup."""
if os.path.exists(PROGRESS_FILE):
with open(PROGRESS_FILE, "r") as f:
try:
return json.load(f)
except (json.JSONDecodeError, KeyError):
return {"step": 0, "data": {}}
return {"step": 0, "data": {}}
def get_setup_method():
"""Gets the setup method chosen during setup."""
progress = load_progress()
return progress.get("data", {}).get("setup_method")
def detect_docker_compose_command():
"""Detects whether 'docker compose' or 'docker-compose' is available."""
candidates = [
["docker", "compose"],
["docker-compose"],
]
for cmd in candidates:
try:
subprocess.run(
cmd + ["version"],
capture_output=True,
text=True,
check=True,
shell=IS_WINDOWS,
)
return cmd
except (subprocess.CalledProcessError, FileNotFoundError):
continue
print(f"{Colors.RED}Docker Compose command not found. Install Docker Desktop or docker-compose.{Colors.ENDC}")
return None
def format_compose_cmd(compose_cmd):
"""Formats the compose command list for display."""
return " ".join(compose_cmd) if compose_cmd else "docker compose"
def check_docker_available():
"""Check if Docker is available and running."""
try:
result = subprocess.run(["docker", "version"], capture_output=True, shell=IS_WINDOWS, check=True)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
print(f"{Colors.RED}❌ Docker is not running or not installed.{Colors.ENDC}")
print(f"{Colors.YELLOW}Please start Docker and try again.{Colors.ENDC}")
return False
def check_docker_compose_up(compose_cmd):
result = subprocess.run(
compose_cmd + ["ps", "-q"],
capture_output=True,
text=True,
shell=IS_WINDOWS,
)
return len(result.stdout.strip()) > 0
def print_manual_instructions(compose_cmd_str):
"""Prints instructions for manually starting Suna services."""
progress = load_progress()
supabase_setup_method = progress.get("data", {}).get("supabase_setup_method")
print(f"\n{Colors.BLUE}{Colors.BOLD}🚀 Manual Startup Instructions{Colors.ENDC}\n")
print("To start Suna, you need to run these commands in separate terminals:\n")
step_num = 1
# Show Supabase start command for local setup
if supabase_setup_method == "local":
print(f"{Colors.BOLD}{step_num}. Start Local Supabase (in backend directory):{Colors.ENDC}")
print(f"{Colors.CYAN} cd backend && npx supabase start{Colors.ENDC}\n")
step_num += 1
print(f"{Colors.BOLD}{step_num}. Start Infrastructure (in project root):{Colors.ENDC}")
print(f"{Colors.CYAN} {compose_cmd_str} up redis -d{Colors.ENDC}\n")
step_num += 1
print(f"{Colors.BOLD}{step_num}. Start Frontend (in a new terminal):{Colors.ENDC}")
print(f"{Colors.CYAN} cd frontend && npm run dev{Colors.ENDC}\n")
step_num += 1
print(f"{Colors.BOLD}{step_num}. Start Backend (in a new terminal):{Colors.ENDC}")
print(f"{Colors.CYAN} cd backend && uv run api.py{Colors.ENDC}\n")
step_num += 1
print(f"{Colors.BOLD}{step_num}. Start Background Worker (in a new terminal):{Colors.ENDC}")
print(
f"{Colors.CYAN} cd backend && uv run dramatiq run_agent_background{Colors.ENDC}\n"
)
# Show stop commands for local Supabase
if supabase_setup_method == "local":
print(f"{Colors.BOLD}To stop Local Supabase:{Colors.ENDC}")
print(f"{Colors.CYAN} cd backend && npx supabase stop{Colors.ENDC}\n")
print("Once all services are running, access Suna at: http://localhost:3000\n")
print(
f"{Colors.YELLOW}💡 Tip:{Colors.ENDC} You can use '{Colors.CYAN}./start.py{Colors.ENDC}' to start/stop the infrastructure services."
)
def main():
setup_method = get_setup_method()
if "--help" in sys.argv:
print("Usage: ./start.py [OPTION]")
print("Manage Suna services based on your setup method")
print("\nOptions:")
print(" -f\tForce start containers without confirmation")
print(" --help\tShow this help message")
return
# If setup hasn't been run or method is not determined, default to docker
if not setup_method:
print(
f"{Colors.YELLOW}⚠️ Setup method not detected. Run './setup.py' first or using Docker Compose as default.{Colors.ENDC}"
)
setup_method = "docker"
if setup_method == "manual":
# For manual setup, we only manage infrastructure services (redis)
# and show instructions for the rest
print(f"{Colors.BLUE}{Colors.BOLD}Manual Setup Detected{Colors.ENDC}")
print("Managing infrastructure services (Redis)...\n")
force = "-f" in sys.argv
if force:
print("Force awakened. Skipping confirmation.")
if not check_docker_available():
return
compose_cmd = detect_docker_compose_command()
if not compose_cmd:
return
compose_cmd_str = format_compose_cmd(compose_cmd)
print(f"Using Docker Compose command: {compose_cmd_str}")
is_infra_up = subprocess.run(
compose_cmd + ["ps", "-q", "redis"],
capture_output=True,
text=True,
shell=IS_WINDOWS,
)
is_up = len(is_infra_up.stdout.strip()) > 0
if is_up:
action = "stop"
msg = "🛑 Stop infrastructure services? [y/N] "
else:
action = "start"
msg = "⚡ Start infrastructure services? [Y/n] "
if not force:
response = input(msg).strip().lower()
if action == "stop":
if response != "y":
print("Aborting.")
return
else:
if response == "n":
print("Aborting.")
return
if action == "stop":
subprocess.run(compose_cmd + ["down"], shell=IS_WINDOWS)
print(f"\n{Colors.GREEN}✅ Infrastructure services stopped.{Colors.ENDC}")
else:
subprocess.run(
compose_cmd + ["up", "redis", "-d"], shell=IS_WINDOWS
)
print(f"\n{Colors.GREEN}✅ Infrastructure services started.{Colors.ENDC}")
print_manual_instructions(compose_cmd_str)
else: # docker setup
print(f"{Colors.BLUE}{Colors.BOLD}Docker Setup Detected{Colors.ENDC}")
print("Managing all Suna services with Docker Compose...\n")
force = "-f" in sys.argv
if force:
print("Force awakened. Skipping confirmation.")
if not check_docker_available():
return
compose_cmd = detect_docker_compose_command()
if not compose_cmd:
return
compose_cmd_str = format_compose_cmd(compose_cmd)
print(f"Using Docker Compose command: {compose_cmd_str}")
is_up = check_docker_compose_up(compose_cmd)
if is_up:
action = "stop"
msg = "🛑 Stop all Suna services? [y/N] "
else:
action = "start"
msg = "⚡ Start all Suna services? [Y/n] "
if not force:
response = input(msg).strip().lower()
if action == "stop":
if response != "y":
print("Aborting.")
return
else:
if response == "n":
print("Aborting.")
return
if action == "stop":
subprocess.run(compose_cmd + ["down"], shell=IS_WINDOWS)
print(f"\n{Colors.GREEN}✅ All Suna services stopped.{Colors.ENDC}")
else:
subprocess.run(compose_cmd + ["up", "-d"], shell=IS_WINDOWS)
print(f"\n{Colors.GREEN}✅ All Suna services started.{Colors.ENDC}")
print(f"{Colors.CYAN}🌐 Access Suna at: http://localhost:3000{Colors.ENDC}")
if __name__ == "__main__":
main()