You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setup 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. if [ ! -d /run/mysqld ]; then
  3. echo "/run/mysqld not found so creating one"
  4. mkdir -p /run/mysqld
  5. fi
  6. echo "ensuring /run/mysqld permissions"
  7. chown mysql:mysql /run/mysqld
  8. if [ /etc/my.cnf.d/mariadb-server.cnf ]; then
  9. echo "Deleting dumb configuration file in newer mariadb alpine package"
  10. rm /etc/my.cnf.d/mariadb-server.cnf
  11. fi
  12. if [ ! -d $DATADIR ]; then
  13. echo "initializing db because $DATADIR is missing"
  14. echo "creating $DATADIR and ensuring permissions"
  15. mkdir -p $DATADIR
  16. chown mysql:mysql $DATADIR
  17. echo "installing db"
  18. su-exec mysql:mysql mysql_install_db --force --datadir=$DATADIR
  19. echo "pushing initialization data into server"
  20. su-exec mysql:mysql mysqld --bind-address=127.0.0.1 --datadir=$DATADIR &
  21. pid="$!"
  22. for i in {30..0}; do
  23. if echo 'SELECT 1' | mysql &> /dev/null; then
  24. break
  25. fi
  26. echo 'MariaDB init process in progress...'
  27. sleep 5
  28. done
  29. envsubst "`printf '${%s} ' $(sh -c "env|cut -d'=' -f1")`" < /etc/templates/dbinit.sql > /tmp/dbinit.sql
  30. cat /tmp/dbinit.sql | mysql
  31. if ! kill -s TERM "$pid" || ! wait "$pid"; then
  32. echo >&2 'MariaDB init process failed.'
  33. exit 1
  34. fi
  35. rm /tmp/dbinit.sql
  36. fi