Improve percona cluster initialization

* Switch from /etc/init.d/mysql bootstrap-pxc to
  /etc/init.d/mysql restart-bootstrap when bootstrapping
  a new cluster. This ensures that, even when Percona starts
  at boot, that new config is loaded and the cluster is
  bootstrapped.

* If percona fails to bootstrap or restart, ensure we do not
  touch the initialized file, allowing os-refresh-config to
  try again on the next iteration.

Co-Authored-By: Gregory Haynes <greg@greghaynes.net>
Change-Id: Ia720e40329a1d39db2e25fc917fbf5b5ea85dedc
This commit is contained in:
Kiall Mac Innes 2014-05-09 13:54:37 +01:00
parent 0c154b6438
commit 60eba01502
1 changed files with 18 additions and 7 deletions

View File

@ -12,10 +12,10 @@ if [ ! -e ${MYSQL_INITIALIZED} ]; then
# Needed to setup initial tables. This command is idempotent.
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mnt/state/var/lib/mysql --no-defaults --pid-file=$pid_path --wsrep-new-cluster
# We install this init script so we can trust this path exists
/etc/init.d/mysql bootstrap-pxc
touch ${MYSQL_INITIALIZED}
# We install this init script so we can trust this path exists.
# Use of restart-bootstrap vs bootstrap-pxc ensures that, even if
# MySQL is running, the bootstrap will succeed.
/etc/init.d/mysql restart-bootstrap
elif [ $? -eq 1 ]; then
if grep -qE '^wsrep_cluster_address[[:space:]]*=[[:space:]]*gcomm://[[:space:]]*$' /etc/mysql/conf.d/cluster.cnf; then
echo "We are configured as joiner and have no nodes configured for the cluster. Refusing to proceed until cluster nodes are known."
@ -23,12 +23,23 @@ if [ ! -e ${MYSQL_INITIALIZED} ]; then
fi
os-svc-restart -n mysql
touch ${MYSQL_INITIALIZED}
else
echo "We are neither cluster initializer or joiner. Refusing to bootstrap mysql cluster until role is known."
exit 1
fi
# Ensure we actually have a working database, the Percona init script does not
# always exit with a non zero code upon failure.
if [ ! -S /var/run/mysqld/mysqld.sock ]; then
echo "MySQL Socket missing, is percona running correctly?"
exit 1
fi
# Finally, perform a MySQL "ping". This will succeed even when MySQL returns
# an "Access Denied" packet, avoiding the need to provide valid credentials.
/usr/local/mysql/bin/mysqladmin ping
touch ${MYSQL_INITIALIZED}
else
# For single node setups we can re-bootstrap if were not currently running
# We need to ensure we are bootstrap host to prevent our regex succeeding
@ -36,7 +47,7 @@ else
LOCAL_IP=$(os-apply-config --key local-ipv4 --type netaddress --key-default '')
if os-is-bootstrap-host && grep -Eq "^wsrep_cluster_address=gcomm://$LOCAL_IP,?\$" /etc/mysql/conf.d/cluster.cnf; then
if ! /etc/init.d/mysql status; then
/etc/init.d/mysql bootstrap-pxc
/etc/init.d/mysql restart-bootstrap
fi
fi
fi