12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #!/bin/sh
-
- if [ ! -d /run/mysqld ]; then
- echo "/run/mysqld not found so creating one"
- mkdir -p /run/mysqld
- fi
- 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 'MySQL 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 'MySQL init process failed.'
- exit 1
- fi
-
- rm /tmp/dbinit.sql
- fi
-
- 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 'MySQL init process in progress...'
- sleep 5
- done
-
- mysql_upgrade
-
- if ! kill -s TERM "$pid" || ! wait "$pid"; then
- echo >&2 'MySQL upgrade process failed.'
- exit 1
- fi
|