From 37d44444d7bc1804976fc4477c4022ee6cc06e44 Mon Sep 17 00:00:00 2001 From: Sidharth Surana Date: Tue, 8 Dec 2015 02:23:58 -0800 Subject: 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 --- docker/mariadb/extend_start.sh | 16 +++++++---- docker/mariadb/security_reset.expect | 53 ++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 13 deletions(-) (limited to 'docker') diff --git a/docker/mariadb/extend_start.sh b/docker/mariadb/extend_start.sh index 2ff24b73b..dcbdac2ed 100644 --- a/docker/mariadb/extend_start.sh +++ b/docker/mariadb/extend_start.sh @@ -2,11 +2,17 @@ function bootstrap_db { mysqld_safe --wsrep-new-cluster & - - # Waiting for deamon - sleep 10 + # 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 @@ -17,7 +23,7 @@ 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" - touch /var/lib/mysql/cluster.exists mysql_install_db bootstrap_db + touch /var/lib/mysql/cluster.exists fi diff --git a/docker/mariadb/security_reset.expect b/docker/mariadb/security_reset.expect index 7c720136f..af71463fb 100644 --- a/docker/mariadb/security_reset.expect +++ b/docker/mariadb/security_reset.expect @@ -2,20 +2,57 @@ set timeout 10 spawn mysql_secure_installation -expect "Enter current password for root (enter for none):" +expect { + timeout { send_user "\nFailed to get 'Enter current password for root (enter for none):' prompt\n"; exit 1 } + eof { send_user "\nFailed to get 'Enter current password for root (enter for none):' prompt\n"; exit 1 } + "Enter current password for root (enter for none):" +} send "\r" -expect "Set root password?" +expect { + timeout { send_user "\nFailed to get 'Set root password?' prompt\n"; exit 1 } + eof { send_user "\nFailed to get 'Set root password?' prompt\n"; exit 1 } + "Set root password?" +} send "y\r" -expect "New password:" +expect { + timeout { send_user "\nFailed to get 'New password:' prompt\n"; exit 1 } + eof { send_user "\nFailed to get 'New password:' prompt\n"; exit 1 } + "New password:" +} send "$env(DB_ROOT_PASSWORD)\r" -expect "Re-enter new password:" + +expect { + timeout { send_user "\nFailed to get 'Re-enter new password:' prompt\n"; exit 1 } + eof { send_user "\nFailed to get 'Re-enter new password:' prompt\n"; exit 1 } + "Re-enter new password:" +} send "$env(DB_ROOT_PASSWORD)\r" -expect "Remove anonymous users?" + +expect { + timeout { send_user "\nFailed to get 'Remove anonymous users?' prompt\n"; exit 1 } + eof { send_user "\nFailed to get 'Remove anonymous users?' prompt\n"; exit 1 } + "Remove anonymous users?" +} send "y\r" -expect "Disallow root login remotely?" + +expect { + timeout { send_user "\nFailed to get 'Disallow root login remotely?' prompt\n"; exit 1 } + eof { send_user "\nFailed to get 'Disallow root login remotely?' prompt\n"; exit 1 } + "Disallow root login remotely?" +} send "n\r" -expect "Remove test database and access to it?" + +expect { + timeout { send_user "\nFailed to get 'Remove test database and access to it?' prompt\n"; exit 1 } + eof { send_user "\nFailed to get 'Remove test database and access to it?' prompt\n"; exit 1 } + "Remove test database and access to it?" +} send "y\r" -expect "Reload privilege tables now?" + +expect { + timeout { send_user "\nFailed to get 'Reload privilege tables now?' prompt\n"; exit 1 } + eof { send_user "\nFailed to get 'Reload privilege tables now?' prompt\n"; exit 1 } + "Reload privilege tables now?" +} send "y\r" expect eof -- cgit v1.2.3