-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·93 lines (77 loc) · 2.35 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·93 lines (77 loc) · 2.35 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
#!/usr/bin/env bash
set -e
# Regulatory Change Monitor — One-command launcher
# Usage: ./start.sh
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
API_PORT="${RCM_API_PORT:-8000}"
FRONTEND_PORT="${RCM_FRONTEND_PORT:-8501}"
echo "============================================"
echo " Regulatory Change Monitor"
echo "============================================"
echo ""
# Check for Python
if ! command -v python3 &>/dev/null; then
echo "ERROR: Python 3 is required but not found."
echo "Install Python from https://www.python.org/downloads/"
exit 1
fi
# Create venv if needed
if [ ! -d ".venv" ]; then
echo "Creating virtual environment..."
python3 -m venv .venv
fi
# Activate venv
source .venv/bin/activate
# Install dependencies if needed
if ! python -c "import fastapi" 2>/dev/null; then
echo "Installing dependencies (first run only)..."
pip install -e . --quiet
fi
echo ""
echo "Starting services..."
echo " API: http://localhost:${API_PORT}/docs"
echo " Frontend: http://localhost:${FRONTEND_PORT}"
echo ""
echo "Press Ctrl+C or use the Shutdown button in the UI to stop."
echo ""
# Track child PIDs
API_PID=""
FRONTEND_PID=""
# Cleanup on exit — handles Ctrl+C, SIGTERM (from API shutdown endpoint),
# and normal script exit.
cleanup() {
echo ""
echo "Shutting down..."
[ -n "$FRONTEND_PID" ] && kill "$FRONTEND_PID" 2>/dev/null || true
[ -n "$API_PID" ] && kill "$API_PID" 2>/dev/null || true
[ -n "$FRONTEND_PID" ] && wait "$FRONTEND_PID" 2>/dev/null || true
[ -n "$API_PID" ] && wait "$API_PID" 2>/dev/null || true
echo "Done."
}
trap cleanup EXIT INT TERM
# Start API in background
uvicorn rcm_app.main:app --host 0.0.0.0 --port "$API_PORT" &
API_PID=$!
# Wait for API to be ready
for i in $(seq 1 15); do
if curl -s "http://localhost:${API_PORT}/api/health" >/dev/null 2>&1; then
break
fi
sleep 1
done
# Start Streamlit
RCM_API_URL="http://localhost:${API_PORT}" streamlit run rcm_frontend/app.py \
--server.port "$FRONTEND_PORT" \
--server.headless true \
--browser.gatherUsageStats false &
FRONTEND_PID=$!
# Open browser
sleep 2
if command -v open &>/dev/null; then
open "http://localhost:${FRONTEND_PORT}"
elif command -v xdg-open &>/dev/null; then
xdg-open "http://localhost:${FRONTEND_PORT}"
fi
# Wait for either process to exit
wait