OCF_RESKEY_database_default="cluster" : ${OCF_RESKEY_database=${OCF_RESKEY_database_default}} 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 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"; send_mail "NCD" "MySQL ((SHOW DATABASES)) monitor succeeded, this means that the cluster database was not configured: $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="email@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 } mysql_status() { if [ ! -e $OCF_RESKEY_pid ]; then 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 fi pid=`cat $OCF_RESKEY_pid`; if [ -d /proc -a -d /proc/1 ]; then [ "u$pid" != "u" -a -d /proc/$pid ] else kill -0 $pid >/dev/null 2>&1 fi if [ $? -eq 0 ]; then # 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"; 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"; return $OCF_ERR_INSTALLED; else return $exc; fi else ocf_log info "MySQL monitor succeeded"; return $OCF_SUCCESS; fi else 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 fi }