#!/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