feat: add run script to start frontend and backend with pm2
This commit is contained in:
parent
e01d57c217
commit
2f7cd70d36
73
scripts/run.sh
Executable file
73
scripts/run.sh
Executable file
@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# --- 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."
|
||||||
Loading…
Reference in New Issue
Block a user