#!/bin/bash # # This is an entrypoint that runs the MySQL server in the 'slave' mode. # export_vars=$(cgroup-limits); export $export_vars source ${CONTAINER_SCRIPTS_PATH}/common.sh set -eu # Just run normal server if the data directory is already initialized if [ -d "${MYSQL_DATADIR}/mysql" ]; then exec /usr/bin/run-mysqld "$@" fi export MYSQL_RUNNING_AS_SLAVE=1 [ -f ${CONTAINER_SCRIPTS_PATH}/validate_replication_variables.sh ] && source ${CONTAINER_SCRIPTS_PATH}/validate_replication_variables.sh # Generate the unique 'server-id' for this master export MYSQL_SERVER_ID=$(server_id) log_info "The 'slave' server-id is ${MYSQL_SERVER_ID}" # Process the MySQL configuration files envsubst < ${CONTAINER_SCRIPTS_PATH}/my-base.cnf.template > /etc/my.cnf.d/base.cnf envsubst < ${CONTAINER_SCRIPTS_PATH}/my-paas.cnf.template > /etc/my.cnf.d/paas.cnf envsubst < ${CONTAINER_SCRIPTS_PATH}/my-slave.cnf.template > /etc/my.cnf.d/slave.cnf envsubst < ${CONTAINER_SCRIPTS_PATH}/my-repl-gtid.cnf.template > /etc/my.cnf.d/repl-gtid.cnf envsubst < ${CONTAINER_SCRIPTS_PATH}/my-tuning.cnf.template > /etc/my.cnf.d/tuning.cnf # Initialize MySQL database and wait for the MySQL master to accept # connections. initialize_database "$@" wait_for_mysql_master # Get binlog file and position from master STATUS_INFO=$(mysql --host "$MYSQL_MASTER_SERVICE_NAME" "-u${MYSQL_MASTER_USER}" "-p${MYSQL_MASTER_PASSWORD}" replication -e 'SELECT gtid from replication limit 1\G') GTID_VALUE=$(echo "$STATUS_INFO" | grep 'gtid:' | head -n 1 | sed -e 's/^\s*gtid: //') # checking STATUS_INFO here because empty GTID_VALUE is valid value if [ -z "${STATUS_INFO}" ] ; then echo "Could not read GTID value from master" exit 1 fi mysql $mysql_flags <&1