Skip to content

Add $AFTER_FIRST_TIME_SQL parameter #8

merged 1 commit into from Oct 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf/my.cnf
@@ -11,7 +11,7 @@
# this is only for the mysqld standalone daemon
[mysqld]
skip-character-set-client-handshake
datadir=/var/lib/mysqlmounted
datadir=${MYSQL_DATADIR}
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
#default-character-set=utf8
8 changes: 8 additions & 0 deletions container_files/bin/fix-all-permissions.sh
@@ -0,0 +1,8 @@
#!/bin/bash

echo "Fixing Permissions"
chown -R mysql:mysql $MYSQL_DATADIR
/opt/bin/fix-permissions.sh $MYSQL_DATADIR
/opt/bin/fix-permissions.sh /var/log/mariadb/
/opt/bin/fix-permissions.sh /var/run/
echo "Done Fixing Permissions"
32 changes: 13 additions & 19 deletions container_files/bin/start.sh
@@ -16,7 +16,8 @@ if [ -e "/tmp/firsttimerunning" ]; then
fi

echo "Setting DataDir: $MYSQL_DATADIR" >> $log

sed -e "s=\${MYSQL_DATADIR}=$MYSQL_DATADIR=" < /etc/my.cnf > /etc/my.cnf

if [[ $CREATE_NEW_DATABASE == 1 || ($CREATE_NEW_DATABASE == if_needed && ( ! -d $MYSQL_DATADIR || -z $(ls -A $MYSQL_DATADIR) ) ) ]]; then

echo "Installing MariaDB" >> $log
@@ -26,15 +27,15 @@ if [ -e "/tmp/firsttimerunning" ]; then
echo >&2 ' Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?' >> $log
exit 1
fi

echo 'Running mysql_install_db ...' >> $log
mysql_install_db --defaults-file=/etc/my.cnf --datadir="$MYSQL_DATADIR" >> $log
echo 'Finished mysql_install_db' >> $log

# These statements _must_ be on individual lines, and _must_ end with
# semicolons (no line breaks or comments are permitted).
# TODO proper SQL escaping on ALL the things D:

tempSqlFile='/tmp/mysql-first-time.sql'
echo "DELETE FROM mysql.user ;" > $tempSqlFile
echo "CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;" >> $tempSqlFile
@@ -43,7 +44,6 @@ if [ -e "/tmp/firsttimerunning" ]; then
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;" >> $tempSqlFile
echo "DROP DATABASE IF EXISTS test ;" >> $tempSqlFile


if [ "$MYSQL_DATABASE" != "" ]; then
echo "flush privileges;" >> "$tempSqlFile"
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" >> "$tempSqlFile"
@@ -54,29 +54,23 @@ if [ -e "/tmp/firsttimerunning" ]; then
echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'$MYSQL_DATABASE.%_i2network' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$tempSqlFile"
echo "GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'$MYSQL_DATABASE.%_i2network' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> "$tempSqlFile"
fi

echo 'FLUSH PRIVILEGES ;' >> "$tempSqlFile"
# [jvf] mysqld_safe unknown option '--character-set-server=utf8' [FIXME]
#echo "character-set-server = utf8" >> /etc/my.cnf
#echo "collation-server = utf8_unicode_ci" >> /etc/my.cnf
#echo "" >> /etc/my.cnf

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

if [ -e "$AFTER_FIRST_TIME_SQL" ]; then
cat $AFTER_FIRST_TIME_SQL >> $tempSqlFile
fi

/opt/bin/fix-all-permissions.sh >> $log
rm -f /tmp/firsttimerunning
/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
/opt/bin/fix-all-permissions.sh >> $log
rm -f /tmp/firsttimerunning
/usr/bin/mysqld_safe --datadir="$MYSQL_DATADIR"
fi