This post is the fifth of a series that started here.
From the previous posts of this series, we now have nearly everything setup, only a few pieces are missing. One of the missing pieces is the Pacemaker script that run on the MySQL instance.
First, this script is optional, Pacemaker will accept a noop bash script but since we have the opportunity to run a script on the MySQL host, let’s take it. At minimum, let’s use mysqladmin to ping the database to see if it is available. If not, the recommended action is to stop the heartbeat service (pacemaker). Stopping Pacemaker will trigger a resource transfer to the monitoring instance which will in turn cause the running MySQL instance to be killed and a new one started. Here is a simple instance script, more complex ones are obviously possible.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/bash MYSQLUSER=monitor MYSQLPASS=apassword #Give time for MySQL to start if it need recovery sleep 120 while [ 1 ] do RES=`/usr/bin/mysqladmin -u $MYSQLUSER -p$MYSQLPASS ping | /bin/grep -ci alive` if [ "$RES" -eq "0" ] then #potential failure, let's recheck before pulling the plug sleep 15 RES=`/usr/bin/mysqladmin -u $MYSQLUSER -p$MYSQLPASS ping | /bin/grep -ci alive` if [ "$RES" -eq "0" ] #twice on error, too bad! /etc/init.d/heartbeat stop fi fi sleep 60 done |