-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·126 lines (101 loc) · 2.94 KB
/
start.sh
File metadata and controls
executable file
·126 lines (101 loc) · 2.94 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
#!/bin/bash
# Course Management System Startup Script
echo "🚀 Starting Course Management System..."
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check if port is in use
port_in_use() {
lsof -i :$1 >/dev/null 2>&1
}
# Check if Python is installed
if ! command_exists python3 && ! command_exists python; then
echo "❌ Python is not installed. Please install Python 3.8+ and try again."
exit 1
fi
# Check if Node.js is installed
if ! command_exists node; then
echo "❌ Node.js is not installed. Please install Node.js 18+ and try again."
exit 1
fi
# Check if npm is installed
if ! command_exists npm; then
echo "❌ npm is not installed. Please install npm and try again."
exit 1
fi
echo "✅ Dependencies check passed!"
# Create virtual environment for backend if it doesn't exist
if [ ! -d "backend/venv" ]; then
echo "📦 Creating Python virtual environment..."
cd backend
python3 -m venv venv
cd ..
fi
# Install backend dependencies
echo "📦 Installing backend dependencies..."
cd backend
source venv/bin/activate
pip install -r requirements.txt
# Check for environment file
if [ ! -f ".env" ]; then
echo "⚠️ Creating .env file from example..."
cp .env.example .env
fi
echo "🗄️ Creating database tables..."
python -c "from app.database import create_tables; create_tables()"
cd ..
# Install frontend dependencies
echo "📦 Installing frontend dependencies..."
cd frontend
if [ ! -d "node_modules" ]; then
npm install
fi
# Check for environment file
if [ ! -f ".env.local" ]; then
echo "⚠️ Creating .env.local file from example..."
cp .env.local.example .env.local
fi
cd ..
# Kill existing processes on ports if they exist
if port_in_use 8000; then
echo "🔄 Stopping existing backend server..."
pkill -f "uvicorn.*8000" || true
fi
if port_in_use 3000; then
echo "🔄 Stopping existing frontend server..."
pkill -f "next.*3000" || true
fi
echo "🚀 Starting backend server on http://localhost:8000..."
cd backend
source venv/bin/activate
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 &
BACKEND_PID=$!
cd ../frontend
echo "🚀 Starting frontend server on http://localhost:3000..."
npm run dev &
FRONTEND_PID=$!
# Wait a moment for servers to start
sleep 3
echo ""
echo "🎉 Course Management System is starting up!"
echo ""
echo "📚 Frontend: http://localhost:3000"
echo "🔧 Backend API: http://localhost:8000"
echo "📖 API Documentation: http://localhost:8000/docs"
echo ""
echo "Press Ctrl+C to stop all servers"
# Function to cleanup on exit
cleanup() {
echo ""
echo "🛑 Shutting down servers..."
kill $BACKEND_PID 2>/dev/null || true
kill $FRONTEND_PID 2>/dev/null || true
pkill -f "uvicorn.*8000" 2>/dev/null || true
pkill -f "next.*3000" 2>/dev/null || true
echo "✅ Servers stopped"
exit 0
}
trap cleanup SIGINT
# Wait for both processes
wait