-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
141 lines (115 loc) · 3.41 KB
/
start.sh
File metadata and controls
141 lines (115 loc) · 3.41 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
#!/bin/bash
# Clinical ChatBot Startup Script
# This script helps you start both backend and frontend servers
set -e
echo "=========================================="
echo " Clinical ChatBot Startup"
echo "=========================================="
echo ""
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if .env files exist
check_env_files() {
echo -e "${BLUE}Checking configuration files...${NC}"
if [ ! -f "backend/.env" ]; then
echo -e "${YELLOW}Warning: backend/.env not found!${NC}"
echo "Creating from .env.example..."
cp backend/.env.example backend/.env
echo -e "${RED}Please edit backend/.env with your API keys before continuing!${NC}"
exit 1
fi
if [ ! -f "frontend/.env.local" ]; then
echo -e "${YELLOW}Warning: frontend/.env.local not found!${NC}"
echo "Creating from .env.local.example..."
cp frontend/.env.local.example frontend/.env.local
fi
echo -e "${GREEN}✓ Configuration files found${NC}"
echo ""
}
# Start backend
start_backend() {
echo -e "${BLUE}Starting Backend Server...${NC}"
cd backend
# Check if virtual environment exists
if [ ! -d "venv" ]; then
echo "Creating virtual environment..."
python -m venv venv
fi
# Activate virtual environment
source venv/bin/activate
# Install dependencies if needed
if [ ! -f "venv/.installed" ]; then
echo "Installing backend dependencies..."
pip install -r requirements.txt
touch venv/.installed
fi
# Start server in background
echo "Starting FastAPI server on http://localhost:8000"
python -m app.main &
BACKEND_PID=$!
echo $BACKEND_PID > .backend.pid
cd ..
echo -e "${GREEN}✓ Backend started (PID: $BACKEND_PID)${NC}"
echo ""
}
# Start frontend
start_frontend() {
echo -e "${BLUE}Starting Frontend Server...${NC}"
cd frontend
# Install dependencies if needed
if [ ! -d "node_modules" ]; then
echo "Installing frontend dependencies..."
npm install
fi
# Start server in background
echo "Starting Next.js server on http://localhost:3000"
npm run dev &
FRONTEND_PID=$!
echo $FRONTEND_PID > .frontend.pid
cd ..
echo -e "${GREEN}✓ Frontend started (PID: $FRONTEND_PID)${NC}"
echo ""
}
# Wait and show status
show_status() {
echo ""
echo "=========================================="
echo -e "${GREEN}Clinical ChatBot is running!${NC}"
echo "=========================================="
echo ""
echo "Backend: http://localhost:8000"
echo "Frontend: http://localhost:3000"
echo "API Docs: http://localhost:8000/api/docs"
echo ""
echo "Press Ctrl+C to stop all servers"
echo ""
}
# Cleanup function
cleanup() {
echo ""
echo -e "${YELLOW}Shutting down servers...${NC}"
if [ -f "backend/.backend.pid" ]; then
kill $(cat backend/.backend.pid) 2>/dev/null || true
rm backend/.backend.pid
fi
if [ -f "frontend/.frontend.pid" ]; then
kill $(cat frontend/.frontend.pid) 2>/dev/null || true
rm frontend/.frontend.pid
fi
echo -e "${GREEN}✓ Servers stopped${NC}"
exit 0
}
# Set trap for cleanup
trap cleanup INT TERM
# Main execution
check_env_files
start_backend
sleep 3 # Wait for backend to start
start_frontend
show_status
# Keep script running
wait