message: only bring mysql up once when initdb.d and generated username/pw/db.
diff: @@ -9,8 +9,6 @@ if [ ! -d "/run/mysqld" ]; then
  chown -R mysql:mysql /run/mysqld
  fi
  -find /var/lib/mysql
  -
  if [ -d /var/lib/mysql/mysql ]; then
  echo "[i] MySQL directory already present, skipping creation"
  else
  @@ -18,6 +16,21 @@ else
  mysql_install_db --skip-name-resolve
  + echo "starting mysql for initdb.d import."
  + /usr/bin/mysqld &
  + pid="$!"
  + echo "pid is $pid"
  +
  +for i in {30..0}; do
  + if echo 'SELECT 1' | mysql &> /dev/null; then
  + break
  + fi
  + echo 'MySQL init process in progress...'
  + sleep 1
  + done
  +
  +
  +
  if [ "$MARIADB_ROOT_PASSWORD" = "" ]; then
  MARIADB_ROOT_PASSWORD=`pwgen 16 1`
  echo "[i] MySQL root Password: $MARIADB_ROOT_PASSWORD"
  @@ -34,8 +47,7 @@ else
  cat << EOF > $tfile
  USE mysql;
  -
  -UPDATE user SET PASSWORD=PASSWORD("$MARIADB_ROOT_PASSWORD") WHERE user="root";
  + UPDATE mysql.user SET PASSWORD=PASSWORD("$MARIADB_ROOT_PASSWORD") WHERE user="root";
  FLUSH PRIVILEGES;
  EOF
  @@ -47,45 +59,34 @@ EOF
  echo "[i] Creating user: $MARIADB_USER with password $MARIADB_PASSWORD"
  echo "GRANT ALL ON \`$MARIADB_DATABASE\`.* to '$MARIADB_USER'@'%' IDENTIFIED BY '$MARIADB_PASSWORD';" >> $tfile
  fi
  - echo "FLUSH PRIVILEGES;" >> $tfile
  fi
  - /usr/bin/mysqld --bootstrap --verbose=0 < $tfile
  - rm -v -f $tfile
  - echo "[client]" >> /var/lib/mysql/.my.cnf
  - echo "user=root" >> /var/lib/mysql/.my.cnf
  - echo "password=$MARIADB_ROOT_PASSWORD" >> /var/lib/mysql/.my.cnf
  -
  -echo "starting mysql for initdb.d import."
  -/usr/bin/mysqld &
  -pid="$!"
  -echo "pid is $pid"
  -
  -for i in {30..0}; do
  - if echo 'SELECT 1' | mysql -u root -p${MARIADB_ROOT_PASSWORD} &> /dev/null; then
  - break
  - fi
  - echo 'MySQL init process in progress...'
  - sleep 1
  - done
  + cat $tfile
  + cat $tfile | mysql -v -u root
  + rm -v -f $tfile
  for f in `ls /docker-entrypoint-initdb.d/*`; do
  -
  case "$f" in
  *.sh) echo "$0: running $f"; . "$f" ;;
  - *.sql) echo "$0: running $f"; cat $f | mysql -u root -p${MARIADB_ROOT_PASSWORD} ; echo ;;
  + *.sql) echo "$0: running $f"; cat $f| tee | mysql -u root -p${MARIADB_ROOT_PASSWORD}; echo ;;
  *) echo "$0: ignoring $f" ;;
  esac
  echo
  done
  + echo "[client]" >> /var/lib/mysql/.my.cnf
  + echo "database=mysql" >> /var/lib/mysql/.my.cnf
  + echo "user=root" >> /var/lib/mysql/.my.cnf
  + echo "password=$MARIADB_ROOT_PASSWORD" >> /var/lib/mysql/.my.cnf
  +
  if ! kill -s TERM "$pid" || ! wait "$pid"; then
  echo >&2 'MySQL init process failed.'
  exit 1
  fi
  +
  fi
  echo "done, now starting daemon"
  