Hi,

I've had some issues with the ocf:heartbeat:mysql RA, mainly because things that normally shouldn't have happened, did happen, such as someone deleted the database the RA was monitoring, or started MySQL with a different PID, like I said, things that should happen, but did, so therefore I created a workaround for those specific cases, and added email notifications to the RA. Not sure how many people will run into the same issues but thought I'd share my work, maybe it'll be useful to someone.

Attached is a diff between my changes and the default RA that comes with resource-agents-1.0.3-2.el5.x86_64.rpm.

Regards,

Dan

--
Dan FRINCU
Systems Engineer
CCNA, RHCE
Streamwide Romania

76d75
< OCF_RESKEY_database_default="cluster"
99,100d97
< : ${OCF_RESKEY_database=${OCF_RESKEY_database_default}}
< 
289,356d277
< db_check() {
< 	db_up=`echo "USE $OCF_RESKEY_database;" | mysql --user=$OCF_RESKEY_test_user --password=$OCF_RESKEY_test_passwd --socket=$OCF_RESKEY_socket -O connect_timeout=1 2>&1`
<     rc=$?
<     if [ ! $rc -eq 0 ]; then
< 		ocf_log err "MySQL ((USE $OCF_RESKEY_database)) monitor failed:";
< 		if [ ! -z "$db_up" ]; then 
< 			ocf_log err $db_up; 
< 		fi
< 		# but maybe someone forgot to add the cluster test database?
< 		all_db=`echo "SHOW DATABASES;" | mysql --user=$OCF_RESKEY_test_user --password=$OCF_RESKEY_test_passwd --socket=$OCF_RESKEY_socket -O connect_timeout=1 2>&1`
< 		ex=$?
< 		if [ ! $ex -eq 0 ]; then
< 			ocf_log err "MySQL ((SHOW DATABASES)) monitor failed:";
< 			if [ ! -z "$all_db" ]; then
< 				ocf_log err $all_db;
< 			fi
< 			send_mail "DBD" "MySQL ((SHOW DATABASES)) monitor failed: $all_db";
< 			return $OCF_ERR_GENERIC;
< 		else
< 			ocf_log info "MySQL ((SHOW DATABASES)) monitor succeeded, this means that the cluster database was not configured properly, e.g. it's missing";
< 			send_mail "NCD" "MySQL ((SHOW DATABASES)) monitor succeeded, this means that the cluster database was not configured properly, e.g. it's missing: 
< $all_db";
< 			return $OCF_ERR_INSTALLED;
< 		fi
<    else
< 	ocf_log info "MySQL monitor succeeded";
< 	return $OCF_SUCCESS;
<     fi
< }
< 
< send_mail() {
< email=`crm configure show | awk -F'"' '/email/ {print $2}'`
< if [ -z $email ]; then
< 	email="m...@domain.tld"
< fi
< 
< case "$1" in
<   NCP) echo "$2" | $MAILCMD -s "MySQL monitor PID not configured properly on `uname -n`" "$email" ;;
<   NCT) echo "$2" | $MAILCMD -s "MySQL monitor database table not configured properly on `uname -n`" "$email"	;;
<   NCD) echo "$2" | $MAILCMD -s "MySQL monitor database not configured properly on `uname -n`" "$email" ;;
<   DBD) echo "$2" | $MAILCMD -s "MySQL monitor failed on `uname -n`" "$email"	;;
<  *)	echo ""	;;
< esac
< }
< 
< double_check() {
< 	ip_addr="`netstat -tupan | awk '/:3306/ && /mysql/ {sub(/:[[:digit:]]+/, "");count++;line[count]=$4;print line[1];exit}'`"
< 	if [ -z "$ip_addr" ]; then
< 		ocf_log debug "MySQL not running on any network socket"
< 		return $OCF_NOT_RUNNING;
< 	else
< 		return $OCF_SUCCESS;
< 	fi
< }
< 
< pid_check() {
< 	pidcheck=`pgrep -fl mysql | awk '$2 ~ /mysql/ {sub(/--pid-file=/, ""); print $7}'`
< 	if [ -z "$pidcheck" ]; then
< 		return $OCF_NOT_RUNNING;
< 	else 
< 		if [ "$pidcheck" != "$OCF_RESKEY_pid" ]; then
< 			ocf_log err "MySQL is running with --pid-file=$pidcheck which is different from the PID file used to call this RA ($OCF_RESKEY_pid)";
< 			send_mail "NCP" "MySQL is running with --pid-file=$pidcheck which is different from the PID file used to call this RA ($OCF_RESKEY_pid)";
< 			return $OCF_ERR_INSTALLED;
< 		fi
< 	fi
< }
< 
359,366c280,281
< 		ocf_log debug "MySQL PID not found, MySQL could be down, or it's PID could be defined somewhere else, begin double-check"
< 		double_check
< 		rc=$?
< 		if [ $OCF_CHECK_LEVEL = 0 -o $rc != 0 ]; then
< 			return $rc
< 		else
< 			pid_check
< 		fi
---
> 		ocf_log debug "MySQL is not running"
> 		return $OCF_NOT_RUNNING;
377,397c292
<     	# Do a detailed status check
<     	buf=`echo "SELECT * FROM $OCF_RESKEY_test_table" | mysql --user=$OCF_RESKEY_test_user --password=$OCF_RESKEY_test_passwd --socket=$OCF_RESKEY_socket -O connect_timeout=1 2>&1`
<     	rcx=$?
<     	if [ ! $rcx -eq 0 ]; then
< 			ocf_log err "MySQL $test_table monitor failed:";
< 			if [ ! -z "$buf" ]; then 
< 				ocf_log err $buf; 
< 			fi
< 			db_check
< 			exc=$?
< 			if [ "$exc" -eq "$OCF_SUCCESS" ]; then
< 				ocf_log info "MySQL ((SELECT * FROM $OCF_RESKEY_test_table)) monitor failed, but ((USE $OCF_RESKEY_database)) succeeded, this means that the cluster database table was not configured according to the standalone cluster installation procedure";
< 				send_mail "NCT" "MySQL ((SELECT * FROM $OCF_RESKEY_test_table)) monitor failed, but ((USE $OCF_RESKEY_database)) succeeded, this means that the cluster database table was not configured according to the standalone cluster installation procedure";
< 				return $OCF_ERR_INSTALLED;
< 			else
< 				return $exc;
< 			fi
<     	else
< 			ocf_log info "MySQL monitor succeeded";
< 			return $OCF_SUCCESS;
<     	fi
---
> 		return $OCF_SUCCESS;
399,407c294,296
< 		double_check
< 		rca=$?
< 		if [ $OCF_CHECK_LEVEL = 0 -o $rca != 0 ]; then
< 			ocf_log debug "MySQL not running: removing old PID file"
< 			rm -f $OCF_RESKEY_pid
< 			return $rca;
< 		else
< 			pid_check
< 		fi
---
> 		ocf_log debug "MySQL not running: removing old PID file"
> 		rm -f $OCF_RESKEY_pid
> 		return $OCF_NOT_RUNNING;
_______________________________________________
Pacemaker mailing list: Pacemaker@oss.clusterlabs.org
http://oss.clusterlabs.org/mailman/listinfo/pacemaker

Project Home: http://www.clusterlabs.org
Getting started: http://www.clusterlabs.org/doc/Cluster_from_Scratch.pdf
Bugs: http://developerbugs.linux-foundation.org/enter_bug.cgi?product=Pacemaker

Reply via email to