-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·279 lines (245 loc) · 8.65 KB
/
start.sh
File metadata and controls
executable file
·279 lines (245 loc) · 8.65 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash
# ============================================================
# Backend_FastAPI Component Launcher
# ============================================================
# Starts selected components of the stack:
# 1 - Backend (FastAPI on :8000)
# 2 - Frontend (Svelte chat UI on :5173)
# 3 - Frontend-Kiosk (Kiosk UI on :5174)
# 4 - Frontend-CLI (Terminal chat client)
# 5 - Voice PWA (Voice UI on :5175)
#
# MCP servers run externally — on Proxmox in production, or
# locally from the mcp-servers repo during development.
# See docs/DEVELOPMENT_ENVIRONMENT.md for local setup.
# They do NOT need to be launched from this script.
#
# Usage:
# ./start.sh # Interactive menu
# ./start.sh 1 # Start Backend only
# ./start.sh 12 # Start Backend + Frontend
# ./start.sh dev # Start Backend + Frontend (local development)
# ./start.sh all # Start Backend + Frontend + Kiosk + Voice
# ============================================================
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Ensure we're in the project root
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Track background processes
PIDS=()
cleanup() {
echo ""
echo "Stopping all servers..."
for pid in "${PIDS[@]}"; do
if kill -0 "$pid" 2>/dev/null; then
kill "$pid" 2>/dev/null || true
fi
done
# Kill any child processes
pkill -P $$ 2>/dev/null || true
exit 0
}
trap cleanup SIGINT SIGTERM
# Kill any existing processes from a previous run
kill_existing() {
echo -e "${YELLOW}Killing any existing processes...${NC}"
# Kill uvicorn processes for this project
pkill -f "uvicorn backend.app:create_app" 2>/dev/null || true
# Kill node/npm processes for frontends
pkill -f "node.*frontend" 2>/dev/null || true
pkill -f "npm.*frontend" 2>/dev/null || true
pkill -f "vite.*5173" 2>/dev/null || true
pkill -f "vite.*5174" 2>/dev/null || true
pkill -f "vite.*5175" 2>/dev/null || true
# Give processes time to exit
sleep 1
}
# Kill existing processes before starting
kill_existing
# Helper: Wait for backend to be ready
wait_for_backend() {
local max_attempts=30
local attempt=0
echo -n "Waiting for backend..."
while [ $attempt -lt $max_attempts ]; do
if curl -s -k https://localhost:8000/health > /dev/null 2>&1; then
echo " ready!"
return 0
fi
sleep 0.5
attempt=$((attempt + 1))
echo -n "."
done
echo " timeout (backend may still be starting)"
return 1
}
# Get selection from argument or prompt
if [[ -n "$1" ]]; then
selection="$1"
else
# Display menu
echo ""
echo -e "${BOLD}╔════════════════════════════════════════════╗${NC}"
echo -e "${BOLD}║ Backend_FastAPI Component Launcher ║${NC}"
echo -e "${BOLD}╚════════════════════════════════════════════╝${NC}"
echo ""
echo -e " ${CYAN}1${NC} - Backend (FastAPI on :8000)"
echo -e " ${CYAN}2${NC} - Frontend (Svelte chat UI on :5173)"
echo -e " ${CYAN}3${NC} - Frontend-Kiosk (Kiosk UI on :5174)"
echo -e " ${CYAN}4${NC} - Frontend-CLI (Terminal chat client)"
echo -e " ${CYAN}5${NC} - Voice PWA (Voice UI on :5175)"
echo ""
echo -e " ${YELLOW}MCP servers are always-on (external). No launch needed.${NC}"
echo ""
echo -e " ${CYAN}dev${NC} - Start 1 + 2 (Backend + Frontend for local development)
${CYAN}all${NC} - Start 1, 2, 3, and 5 (full web stack)"
echo ""
echo -e "${BOLD}Enter selection (e.g., '12' or '135' or 'all'):${NC} "
read -r selection
fi
# Handle shortcuts
if [[ "$selection" == "all" ]]; then
selection="1235"
fi
if [[ "$selection" == "dev" ]]; then
selection="12"
fi
# Validate input
if [[ -z "$selection" ]]; then
echo -e "${RED}No selection made. Exiting.${NC}"
exit 1
fi
if [[ ! "$selection" =~ ^[1-5]+$ ]]; then
echo -e "${RED}Invalid selection. Use only numbers 1-5, 'dev', or 'all'.${NC}"
exit 1
fi
echo ""
# Track what we're starting
START_BACKEND=false
START_FRONTEND=false
START_KIOSK=false
START_CLI=false
START_VOICE=false
# Parse selection
[[ "$selection" == *"1"* ]] && START_BACKEND=true
[[ "$selection" == *"2"* ]] && START_FRONTEND=true
[[ "$selection" == *"3"* ]] && START_KIOSK=true
[[ "$selection" == *"4"* ]] && START_CLI=true
[[ "$selection" == *"5"* ]] && START_VOICE=true
# Start Backend (option 1)
if $START_BACKEND; then
echo -e "${GREEN}[1] Starting Backend...${NC}"
uv run python scripts/kill_port.py 8000
uv run uvicorn backend.app:create_app \
--factory \
--host 0.0.0.0 \
--ssl-keyfile=certs/server.key \
--ssl-certfile=certs/server.crt \
--reload &
PIDS+=($!)
sleep 2
fi
# Avoid frontend proxy errors by waiting for backend to accept requests.
if $START_BACKEND && ($START_FRONTEND || $START_KIOSK || $START_VOICE); then
wait_for_backend
fi
# Start Frontend (option 2)
if $START_FRONTEND; then
echo -e "${GREEN}[2] Starting Frontend (Svelte)...${NC}"
uv run python scripts/kill_port.py 5173
cd frontend && npm run dev &
PIDS+=($!)
cd "$SCRIPT_DIR"
fi
# Start Kiosk (option 3)
if $START_KIOSK; then
echo -e "${GREEN}[3] Starting Frontend-Kiosk...${NC}"
uv run python scripts/kill_port.py 5174
cd frontend-kiosk && npm run dev &
PIDS+=($!)
cd "$SCRIPT_DIR"
fi
# Start Voice PWA (option 5)
if $START_VOICE; then
echo -e "${GREEN}[5] Starting Voice PWA...${NC}"
uv run python scripts/kill_port.py 5175
cd frontend-voice && npm run dev &
PIDS+=($!)
cd "$SCRIPT_DIR"
fi
# Start CLI (option 4) - interactive, runs in foreground
if $START_CLI; then
if $START_BACKEND || $START_FRONTEND || $START_KIOSK || $START_VOICE; then
# Other services running, start CLI after them
echo -e "${GREEN}[4] Starting Frontend-CLI...${NC}"
echo ""
sleep 1
source .venv/bin/activate && shell-chat
# After CLI exits, keep waiting for other services
echo ""
echo -e "${YELLOW}CLI exited. Background services still running.${NC}"
echo -e "Press ${RED}Ctrl+C${NC} to stop all servers"
else
# CLI is the only selection
echo -e "${GREEN}[4] Starting Frontend-CLI...${NC}"
echo -e "${YELLOW}Note: Backend is not running. Start with './start.sh 14' to run both.${NC}"
echo ""
source .venv/bin/activate && shell-chat
exit 0
fi
fi
# Show status (only if we have background services)
if $START_BACKEND || $START_FRONTEND || $START_KIOSK || $START_VOICE; then
echo ""
echo -e "${BOLD}═══════════════════════════════════════════════${NC}"
echo -e "${BOLD}Running Services:${NC}"
if $START_SLIDESHOW; then
echo -e " ${GREEN}✓${NC} Slideshow: Photos synced"
fi
if $START_BACKEND; then
echo -e " ${GREEN}✓${NC} Backend: https://localhost:8000"
fi
if $START_FRONTEND; then
echo -e " ${GREEN}✓${NC} Frontend: http://localhost:5173"
fi
if $START_KIOSK; then
echo -e " ${GREEN}✓${NC} Frontend-Kiosk: http://localhost:5174"
fi
if $START_VOICE; then
echo -e " ${GREEN}✓${NC} Voice PWA: http://localhost:5175"
fi
echo -e " ${CYAN}ℹ${NC} MCP Servers: Always-on (external)"
# Show network access info
LOCAL_IP=$(hostname -I 2>/dev/null | awk '{print $1}')
if [ -z "$LOCAL_IP" ]; then
LOCAL_IP=$(ip route get 1 2>/dev/null | awk '{print $7}' | head -1)
fi
if [ -n "$LOCAL_IP" ]; then
echo ""
echo -e "${BOLD}Network Access (from other machines):${NC}"
if $START_BACKEND; then
echo -e " Backend: https://${LOCAL_IP}:8000"
fi
if $START_FRONTEND; then
echo -e " Frontend: http://${LOCAL_IP}:5173"
fi
if $START_KIOSK; then
echo -e " Frontend-Kiosk: http://${LOCAL_IP}:5174"
fi
if $START_VOICE; then
echo -e " Voice PWA: http://${LOCAL_IP}:5175"
fi
fi
echo -e "${BOLD}═══════════════════════════════════════════════${NC}"
echo -e "Press ${RED}Ctrl+C${NC} to stop all servers"
echo ""
# Wait for all background processes
wait
fi