#!/bin/bash set -e # Ensure /run/mysqld exists and is writable if [ ! -d /run/mysqld ]; then mkdir -p /run/mysqld chown mysql:mysql /run/mysqld || true fi # Start MariaDB directly (better for containers) mysqld_safe --datadir=/data/storage & MYSQL_PID=$! # Wait for MariaDB to be ready (with timeout) for i in {1..30}; do if mysqladmin ping --silent; then echo 'MariaDB started.' break fi echo 'Waiting for MariaDB to start...' sleep 1 done # Trap signals for graceful shutdown trap "echo 'Stopping MariaDB...'; kill $MYSQL_PID; wait $MYSQL_PID" SIGTERM SIGINT # Start the Python app (foreground) exec uvicorn app:app --host 0.0.0.0 --port 7860