-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_prod.sh
More file actions
executable file
·62 lines (50 loc) · 1.68 KB
/
Copy pathstart_prod.sh
File metadata and controls
executable file
·62 lines (50 loc) · 1.68 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
#!/bin/bash
# Production startup script
# This script:
# 1. Sets up the virtual environment
# 2. Installs dependencies
# 3. Builds TypeScript
# 4. Starts Gunicorn (when run directly, systemd service will use this script)
# Exit on any error
set -e
# Configuration
VENV_DIR="venv"
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="$PROJECT_DIR/logs"
# Ensure we're in the project directory
cd "$PROJECT_DIR"
# Try to pull latest code
echo "Pulling latest code from repository..."
if [ -d .git ]; then
git pull || echo "Warning: Failed to pull latest code. Continuing with existing codebase..."
else
echo "Not a git repository. Continuing with existing codebase..."
fi
# Create and activate virtual environment if it doesn't exist
if [ ! -d "$VENV_DIR" ]; then
echo "Creating virtual environment..."
python3 -m venv "$VENV_DIR"
fi
# Activate virtual environment
source "$VENV_DIR/bin/activate"
# Install or upgrade pip
python3 -m pip install --upgrade pip
# Install Python dependencies
echo "Installing Python dependencies..."
pip install -r requirements.txt
# Install Node.js dependencies and build TypeScript
echo "Installing Node.js dependencies and building TypeScript..."
npm install
npm run build
# Create logs directory if it doesn't exist
mkdir -p "$LOG_DIR"
# Start Gunicorn (this will be used by systemd)
exec /opt/mscopy/venv/bin/gunicorn \
--workers ${GUNICORN_WORKERS:-3} \
--worker-class ${GUNICORN_WORKER_CLASS:-gevent} \
--timeout ${GUNICORN_TIMEOUT:-120} \
--bind ${HOST:-0.0.0.0}:${PORT:-8000} \
--access-logfile "$LOG_DIR/access.log" \
--error-logfile "$LOG_DIR/error.log" \
--log-level ${LOG_LEVEL:-info} \
backend:app