diff --git a/.env.default b/.env.default index f7e528d7..f7971a12 100644 --- a/.env.default +++ b/.env.default @@ -36,10 +36,15 @@ APP_APIKEY= ## MySQL ############## -MYSQL_USER=root (default) +# The mysql user (default) +MYSQL_USER=root + +# Location of the persistent data directory (default) +MYSQL_VOLUME=/var/lib/mysql ## S6 ############## + S6_BEHAVIOUR_IF_STAGE2_FAILS=2 S6_SERVICES_GRACETIME=10000 S6_KILL_FINISH_MAXTIME=10000 @@ -53,6 +58,7 @@ COMPOSER_HOME=/tmp ############## # https://xdebug.org/docs/all_settings + XDEBUG_ENABLE=0 XDEBUG_MODE=develop XDEBUG_TRIGGER=1 diff --git a/config/s6/cont-init.d/101-env.sh b/config/s6/cont-init.d/101-env.sh index eb5788d7..41b5a27a 100644 --- a/config/s6/cont-init.d/101-env.sh +++ b/config/s6/cont-init.d/101-env.sh @@ -2,4 +2,8 @@ # Set environment defaults MYSQL_USER=${MYSQL_USER:=root} -printf "%s" $MYSQL_USER > /var/run/s6/container_environment/MYSQL_USER \ No newline at end of file +printf "%s" $MYSQL_USER > /var/run/s6/container_environment/MYSQL_USER + +# Set environment defaults +MYSQL_VOLUME=${MYSQL_VOLUME:=/var/lib/mysql} +printf "%s" $MYSQL_VOLUME > /var/run/s6/container_environment/MYSQL_VOLUME \ No newline at end of file diff --git a/config/s6/cont-init.d/110-mysql.sh b/config/s6/cont-init.d/110-mysql.sh index c2905ce7..421c9b96 100644 --- a/config/s6/cont-init.d/110-mysql.sh +++ b/config/s6/cont-init.d/110-mysql.sh @@ -5,29 +5,38 @@ file="${0##*/}" -MYSQL_DATA_DIR=$APP_VOLUME/mysql MYSQL_PID_FILE=/var/run/mysqld/mysqld.pid +MYSQL_RUN_DIR=/var/run/mysqld + +# Make sure run dir exists +if [[ ! -d $MYSQL_RUN_DIR ]]; then + mkdir -p $MYSQL_RUN_DIR +fi + # Remove stale MySQL PID file left behind when docker stops container if [[ -f $MYSQL_PID_FILE ]]; then rm -f $MYSQL_PID_FILE fi +# Ensure that /var/run/mysqld (used for socket and lock files) is writable +chown -R mysql:mysql $MYSQL_RUN_DIR +chmod 1777 $MYSQL_RUN_DIR + + # Initialize MySQL data directory (if needed) # See https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html -if [[ ! -d $MYSQL_DATA_DIR ]]; then +#if [[ ! -d $MYSQL_VOLUME ]]; then - echo "[cont-init.d] ${file}: An empty or uninitialized MySQL volume is detected in ${MYSQL_DATA_DIR}" - echo "[cont-init.d] ${file}: Installing MySQL in ${MYSQL_DATA_DIR} ..." - mkdir $MYSQL_DATA_DIR - chown --reference=/var/lib/mysql $MYSQL_DATA_DIR - chmod --reference=/var/lib/mysql $MYSQL_DATA_DIR - cp -Rpf /var/lib/mysql/* $MYSQL_DATA_DIR + echo "[cont-init.d] ${file}: Installing MySQL in ${MYSQL_VOLUME} ..." + mkdir -p $MYSQL_VOLUME -fi + /usr/bin/mysqld_safe --initialize-insecure --datadir=${MYSQL_VOLUME} + +#fi # Grant or revoke passwordless remote access -/usr/bin/mysqld_safe --datadir=$MYSQL_DATA_DIR -D +/usr/bin/mysqld_safe --datadir=$MYSQL_VOLUME -D echo "[cont-init.d] ${file}: Granting local access of MySQL database from localhost for ${MYSQL_USER}" /usr/bin/mysql -e " diff --git a/config/s6/services.d/mysql/run b/config/s6/services.d/mysql/run index daff8714..170efa8d 100644 --- a/config/s6/services.d/mysql/run +++ b/config/s6/services.d/mysql/run @@ -31,5 +31,5 @@ trap -x term { mysqladmin shutdown } } -importas -D /mnt/www APP_VOLUME APP_VOLUME -exec /usr/bin/mysqld_safe --datadir=${APP_VOLUME}/mysql \ No newline at end of file +importas -D /var/lib/mysql MYSQL_VOLUME MYSQL_VOLUME +exec /usr/bin/mysqld_safe --datadir=${MYSQL_VOLUME} \ No newline at end of file