-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
83 lines (63 loc) · 2.44 KB
/
start.sh
File metadata and controls
83 lines (63 loc) · 2.44 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
#!/bin/bash
# Define cleanup function to kill background processes on exit
cleanup() {
echo "Stopping services..."
# Gracefully kill all background jobs spawned by this script
kill $(jobs -p) 2>/dev/null
# Forcefully kill any lingering Node (Vite) or Python (Django) processes in WSL
pkill -9 -f "vite" 2>/dev/null
pkill -9 -f "node" 2>/dev/null
pkill -9 -f "manage.py" 2>/dev/null
# Kill Windows host Node processes (crucial for WSL interoperability)
taskkill.exe /F /IM node.exe 2>/dev/null
# Shut down any running Docker containers for this project to free up ports
if [ -d "docker" ]; then
(cd docker && docker-compose down 2>/dev/null)
fi
# Aggressively clear the exact ports just to be absolutely sure
for port in 8000 5173 5174 5175 5176 5177 5178 5179 5180; do
lsof -ti:$port | xargs kill -9 2>/dev/null
done
echo "All processes and ports have been successfully freed."
exit
}
# Catch Ctrl+C (SIGINT) and execute the cleanup function
trap cleanup SIGINT
echo "Starting Django API..."
# Navigate to the api directory where the backend pyproject.toml is located
cd api || exit
# Check if poetry command is available in the system
if ! command -v poetry &> /dev/null; then
echo "Error: poetry is not installed or not in PATH."
echo "Please install it from: https://python-poetry.org/docs/"
exit 1
fi
# Install Python dependencies automatically
echo "Checking and installing backend dependencies..."
poetry install
# Navigate to src where manage.py is located
cd src || exit
# Run database migrations to ensure the DB is up to date
echo "Running database migrations..."
poetry run python manage.py migrate
# Start backend in the background and save its Process ID
poetry run python manage.py runserver &
BACKEND_PID=$!
# Go back to the root directory
cd ../..
echo "Starting Vite Web App..."
cd web || exit
# Install npm dependencies automatically if node_modules folder is missing
if [ ! -d "node_modules" ]; then
echo "Missing node_modules. Installing frontend dependencies..."
npm install
fi
# Start frontend in the background and save its Process ID
npm run dev &
FRONTEND_PID=$!
cd ..
echo "====================================================="
echo "🚀 Both services are running! Press Ctrl+C to stop."
echo "====================================================="
# Wait for background processes to finish (keeps the script running)
wait