kolla-ansible/docker/mariadb/extend_start.sh
Sidharth Surana 37d44444d7 Make galeradb bootstraping robust
Currently, there are arbitrary wait for mariadb service startup.
However, this leads to nondeterministic results in the current
workflow. This patch tries to make the workflow more deterministic.

Change-Id: I3c6245cce93c7ff0d3d57cb2ae065a1ed1487769
Closes-Bug: #1491782
2016-01-04 09:10:04 -08:00

30 lines
1.1 KiB
Bash

#!/bin/bash
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 ${DB_PID_FILE} ]; do
if [[ ${TIMEOUT} -gt 0 ]]; then
let TIMEOUT-=1
sleep 1
else
exit 1
fi
done
sudo -E kolla_security_reset
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
}
sudo chown mysql: /var/lib/mysql
# This catches all cases of the BOOTSTRAP variable being set, including empty
if [[ "${!KOLLA_BOOTSTRAP[@]}" ]] && [[ ! -e /var/lib/mysql/cluster.exists ]]; then
ARGS="--wsrep-new-cluster"
mysql_install_db
bootstrap_db
touch /var/lib/mysql/cluster.exists
fi