22 lines
559 B
Bash
Executable File
22 lines
559 B
Bash
Executable File
#!/bin/bash
|
|
|
|
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-nopassword}
|
|
|
|
# slave not configured
|
|
SLAVE_STATUS=$(mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" -e 'SHOW SLAVE STATUS\G')
|
|
if [[ -z "${SLAVE_STATUS}" ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
# extract slave status
|
|
SLAVE_IO=$(echo "${SLAVE_STATUS}" | awk -F: '/Slave_IO_Running/ {gsub(/ /, "", $2); print $2}')
|
|
SLAVE_SQL=$(echo "${SLAVE_STATUS}" | awk -F: '/Slave_SQL_Running/ {gsub(/ /, "", $2); print $2}')
|
|
|
|
# slave ok
|
|
if [[ "${SLAVE_IO}" == "Yes" && "${SLAVE_SQL}" == "Yes" ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
# slave not ok
|
|
exit 1
|
|
|