I am trying to use mysqlfailover to perform automatic failover for my grid of MySQL databases. Only the Master node in my environment is writable, the rest are read-only. When a fail-over occurs and the next slave becomes the new master I need to make that slave writable.
mysqlfailover has a --exec-before and --exec-after that I want to use but I get an error when mysqlfailover invokes my scripts.
MySQL Failover Option Parameters Passed to External Script
--exec-before master host, master port, candidate host, candidate port
--exec-after new master host, new master port
The fail over is working fine but I get this error:
mysqlfailover --log=/mysqlfailover.txt --interval=5 --ping=3 --failover-mode=auto --master=root:pass@mysql_db1 --slaves=root:pass@mysql_db2 --candidates=root:pass@mysql_db2 --exec-before=/beforeFail.sh --exec-after=/afterFail.sh
2017-04-08 15:43:11 PM ERROR ERROR: /beforeFail.sh Script failed. Result = 1
2017-04-08 15:43:11 PM INFO Stopping slaves.
2017-04-08 15:43:11 PM INFO Performing STOP on all slaves.
2017-04-08 15:43:11 PM INFO Switching slaves to new master.
2017-04-08 15:43:11 PM INFO Disconnecting new master as slave.
2017-04-08 15:43:11 PM INFO Starting slaves.
2017-04-08 15:43:11 PM INFO Performing START on all slaves.
2017-04-08 15:43:11 PM INFO Spawning external script.
2017-04-08 15:43:11 PM ERROR ERROR: /afterFail.sh Script failed. Result = 1
Here are my scripts:
#!/bin/bash
# beforeFail.sh
MASTER_HOST=$1
MASTER_PORT=$2
# Attempt to make it read-only if it's still around
mysql --defaults-file=/mysql-root-pass.cnf -h${MASTER_HOST} --port=${MASTER_PORT} -e "SET GLOBAL read_only = ON"
#!/bin/bash
# afterFail.sh
MASTER_HOST=$1
MASTER_PORT=$2
mysql --defaults-file=/mysql-root-pass.cnf -h${MASTER_HOST} --port=${MASTER_PORT} -e "SET GLOBAL read_only = OFF"