File size: 1,718 Bytes
902e19c 782e41b 902e19c 782e41b 902e19c 782e41b 902e19c 782e41b 902e19c 782e41b 902e19c 782e41b 902e19c 782e41b 902e19c 86b5216 b17aebc 86b5216 | 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 | #!/bin/bash
# --- 1. Configure & Start PostgreSQL ---
echo "Starting PostgreSQL..."
service postgresql start
# Wait loop for Postgres to be ready
until pg_isready -h localhost; do
echo "Waiting for Postgres..."
sleep 1
done
# Setup 'playground' user/db with no password requirement (Trust Auth)
# We overwrite pg_hba.conf to trust local connections completely
PG_CONF=$(find /etc/postgresql -name "pg_hba.conf")
# Allow IPv4 localhost
echo "host all all 127.0.0.1/32 trust" > $PG_CONF
# Allow IPv6 localhost (Fixes the ::1 connection error)
echo "host all all ::1/128 trust" >> $PG_CONF
# Allow Local Unix Socket
echo "local all all trust" >> $PG_CONF
# Restart to apply changes
service postgresql restart
# Create user/db if they don't exist
su - postgres -c "psql -c \"CREATE USER playground SUPERUSER;\""
su - postgres -c "psql -c \"CREATE DATABASE playground OWNER playground;\""
# --- 2. Configure & Start MySQL (MariaDB) ---
echo "Starting MySQL..."
service mariadb start
# Create 'playground' user with full access
mysql -e "CREATE DATABASE IF NOT EXISTS playground;"
mysql -e "CREATE USER IF NOT EXISTS 'playground'@'localhost';"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'playground'@'localhost';"
mysql -e "FLUSH PRIVILEGES;"
# --- 3. Start Gunicorn Server (High Concurrency) ---
echo "Starting Gunicorn..."
# -w 4: Use 4 worker processes (Good for the 2 vCPU free tier)
# --threads 4: Allow each worker to handle 4 requests at once (Good for I/O tasks like SQL)
# Total Concurrency: 16 simultaneous requests
exec gunicorn -w 4 --threads 4 -b 0.0.0.0:7860 app:app |