From 637acf8489502f641f1df3e27858de1910201ca4 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Wed, 26 Sep 2018 19:12:38 +0200 Subject: [PATCH] Add "if_needed" value for CREATE_NEW_DATABASE This value means that the database is created only if MYSQL_DATADIR does not exist or is empty. --- container_files/bin/start.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/container_files/bin/start.sh b/container_files/bin/start.sh index 9d86e91..5c4530e 100755 --- a/container_files/bin/start.sh +++ b/container_files/bin/start.sh @@ -17,7 +17,7 @@ if [ -e "/tmp/firsttimerunning" ]; then echo "Setting DataDir: $MYSQL_DATADIR" >> $log - if [ "$CREATE_NEW_DATABASE" == "1" ]; then + if [[ $CREATE_NEW_DATABASE == 1 || ($CREATE_NEW_DATABASE == if_needed && ( ! -d $MYSQL_DATADIR || -z $(ls -A $MYSQL_DATADIR) ) ) ]]; then echo "Installing MariaDB" >> $log @@ -71,6 +71,12 @@ if [ -e "/tmp/firsttimerunning" ]; then /usr/bin/mysqld_safe --init-file="$tempSqlFile" --datadir="$MYSQL_DATADIR" else echo "Not Creating a MariaDB - Using Existing from DataDir: $MYSQL_DATADIR" >> $log + echo "Fixing Permissions" >> $log + chown -R mysql:mysql $MYSQL_DATADIR + /opt/bin/fix-permissions.sh $MYSQL_DATADIR >> $log + /opt/bin/fix-permissions.sh /var/log/mariadb/ >> $log + /opt/bin/fix-permissions.sh /var/run/ >> $log + echo "Done Fixing Permissions" >> $log rm -f /tmp/firsttimerunning /usr/bin/mysqld_safe --datadir="$MYSQL_DATADIR" fi