#!/bin/sh if [ ! -d /run/mysqld ]; then echo "/run/mysqld not found so creating one" mkdir -p /run/mysqld fi echo "ensuring /run/mysqld permissions" chown mysql:mysql /run/mysqld if [ /etc/my.cnf.d/mariadb-server.cnf ]; then echo "Deleting dumb configuration file in newer mariadb alpine package" rm /etc/my.cnf.d/mariadb-server.cnf fi if [ ! -d $DATADIR ]; then echo "initializing db because $DATADIR is missing" echo "creating $DATADIR and ensuring permissions" mkdir -p $DATADIR chown mysql:mysql $DATADIR echo "installing db" su-exec mysql:mysql mysql_install_db --force --datadir=$DATADIR echo "pushing initialization data into server" su-exec mysql:mysql mysqld --bind-address=127.0.0.1 --datadir=$DATADIR & pid="$!" for i in {30..0}; do if echo 'SELECT 1' | mysql &> /dev/null; then break fi echo 'MariaDB init process in progress...' sleep 5 done envsubst "`printf '${%s} ' $(sh -c "env|cut -d'=' -f1")`" < /etc/templates/dbinit.sql > /tmp/dbinit.sql cat /tmp/dbinit.sql | mysql if ! kill -s TERM "$pid" || ! wait "$pid"; then echo >&2 'MariaDB init process failed.' exit 1 fi rm /tmp/dbinit.sql fi