fuel-ccp-mariadb/docker/mariadb/bootstrap.sh
Sergey Reshetnyak aac31945ee Adding service definition for mariadb
Change-Id: I912222004584ce9cd5f60a45455ac287214a1d52
2016-06-27 14:31:06 +03:00

35 lines
1.1 KiB
Bash

#!/bin/bash -e
function bootstrap_db {
mysqld_safe --wsrep-new-cluster &
# Wait for the mariadb server to be "Ready" before starting the security reset with a max timeout
TIMEOUT=${DB_MAX_TIMEOUT:-60}
while [[ ! -f /var/lib/mysql/mariadb.pid ]]; do
if [[ ${TIMEOUT} -gt 0 ]]; then
let TIMEOUT-=1
sleep 1
else
exit 1
fi
done
echo "mysql_security_reset"
sudo -E mysql_security_reset ${DB_ROOT_PASSWORD}
mysql -u root --password="${DB_ROOT_PASSWORD}" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '${DB_ROOT_PASSWORD}' WITH GRANT OPTION;"
mysql -u root --password="${DB_ROOT_PASSWORD}" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${DB_ROOT_PASSWORD}' WITH GRANT OPTION;"
mysqladmin -uroot -p"${DB_ROOT_PASSWORD}" shutdown
wait $(jobs -p)
}
DB_ROOT_PASSWORD="$1"
DB_MAX_TIMEOUT="$2"
# Only update permissions if permissions need to be updated
if [[ $(stat -c %U:%G /var/lib/mysql) != "mysql:mysql" ]]; then
sudo chown mysql: /var/lib/mysql
fi
# Bootstrap
mysql_install_db
bootstrap_db
touch /tmp/mariadb_ok