92 lines
2.3 KiB
Bash
Executable File
92 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Exit immediately if a command exits with a non-zero status.
|
|
set -e
|
|
|
|
# --- Prerequisite check for python3-venv ---
|
|
echo "Checking for Python venv module..."
|
|
if ! python3 -c 'import venv' &> /dev/null; then
|
|
echo "Python 'venv' module is missing. It's required to create a virtual environment for the backend."
|
|
|
|
# Attempt to provide specific installation instructions
|
|
if command -v apt &> /dev/null; then
|
|
PY_VERSION_SHORT=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
|
|
echo "It seems you are on a Debian/Ubuntu-based system. Please install the venv module by running:"
|
|
echo "sudo apt update && sudo apt install python${PY_VERSION_SHORT}-venv"
|
|
else
|
|
echo "Please install the Python 'venv' module for your system."
|
|
fi
|
|
|
|
exit 1
|
|
fi
|
|
echo "Python venv module found."
|
|
|
|
# --- Backend Setup ---
|
|
echo "Setting up backend..."
|
|
cd backend
|
|
|
|
# Create a virtual environment if it doesn't exist
|
|
if [ ! -d ".venv" ]; then
|
|
echo "Creating virtual environment..."
|
|
python3 -m venv .venv
|
|
fi
|
|
|
|
# Activate virtual environment and install dependencies
|
|
source .venv/bin/activate
|
|
pip install -r requirements.txt
|
|
deactivate
|
|
|
|
echo "Backend setup complete."
|
|
cd ..
|
|
|
|
# --- Frontend Setup ---
|
|
echo "Setting up frontend..."
|
|
cd frontend
|
|
npm install
|
|
echo "Frontend setup complete."
|
|
cd ..
|
|
|
|
# --- PM2 Execution ---
|
|
echo "Starting application with pm2..."
|
|
|
|
# Check if pm2 is installed
|
|
if ! command -v pm2 &> /dev/null
|
|
then
|
|
echo "pm2 could not be found. Please install it with 'npm install -g pm2'"
|
|
exit 1
|
|
fi
|
|
|
|
# Create a pm2 config file if it doesn't exist
|
|
if [ ! -f "pm2.config.js" ]; then
|
|
echo "Creating pm2.config.js..."
|
|
cat > pm2.config.js << EOL
|
|
module.exports = {
|
|
apps : [{
|
|
name: "frontend",
|
|
cwd: "./frontend",
|
|
script: "npm",
|
|
args: "start",
|
|
env: {
|
|
"PORT": 3000
|
|
}
|
|
}, {
|
|
name: "backend",
|
|
cwd: "./backend",
|
|
script: "./.venv/bin/uvicorn",
|
|
args: "app.main:app --host 0.0.0.0 --port 8000",
|
|
interpreter: "none",
|
|
env: {
|
|
"PYTHONPATH": "."
|
|
}
|
|
}]
|
|
};
|
|
EOL
|
|
fi
|
|
|
|
# Start processes with pm2
|
|
pm2 start pm2.config.js
|
|
|
|
echo "Application started with pm2."
|
|
echo "Use 'pm2 list' to see the status of the applications."
|
|
echo "Use 'pm2 logs' to see the logs."
|
|
echo "Use 'pm2 stop all' to stop the applications."
|