rewrite to use mariadb instead of mysql

This commit is contained in:
2026-04-15 11:14:41 +02:00
parent aa17849014
commit f5ac2a26f1
+26 -26
View File
@@ -29,15 +29,15 @@ print_help() {
echo "" echo ""
echo "Options:" echo "Options:"
echo " u)" echo " u)"
echo " MySQL user." echo " MariaDB user."
echo " p)" echo " p)"
echo " MySQL password." echo " MariaDB password."
echo " H)" echo " H)"
echo " MySQL host." echo " MariaDB host."
echo " P)" echo " P)"
echo " MySQL port." echo " MariaDB port."
echo " m)" echo " m)"
echo " MySQL extra my.cnf configuration file." echo " MariaDB extra my.cnf configuration file."
echo " w)" echo " w)"
echo " Sets minimum number of nodes in the cluster when WARNING is raised. (default is same as critical)." echo " Sets minimum number of nodes in the cluster when WARNING is raised. (default is same as critical)."
echo " c)" echo " c)"
@@ -67,7 +67,7 @@ check_executable() {
fi fi
} }
check_executable mysql check_executable mariadb
check_executable bc check_executable bc
while getopts “hvu:p:H:P:w:c:f:m:s:0” OPTION; do while getopts “hvu:p:H:P:w:c:f:m:s:0” OPTION; do
@@ -81,19 +81,19 @@ while getopts “hvu:p:H:P:w:c:f:m:s:0” OPTION; do
exit $ST_UK exit $ST_UK
;; ;;
u) u)
mysqluser=$OPTARG mariadbuser=$OPTARG
;; ;;
p) p)
password=$OPTARG password=$OPTARG
;; ;;
H) H)
mysqlhost=$OPTARG mariadbhost=$OPTARG
;; ;;
P) P)
port=$OPTARG port=$OPTARG
;; ;;
m) m)
myconfig=$OPTARG mariadbconfig=$OPTARG
;; ;;
w) w)
warn=$OPTARG warn=$OPTARG
@@ -128,49 +128,49 @@ create_param() {
fi fi
} }
param_mysqlhost=$(create_param -h "$mysqlhost") param_mariadbhost=$(create_param -h "$mariadbhost")
param_port=$(create_param -P "$port") param_port=$(create_param -P "$port")
param_mysqluser=$(create_param -u "$mysqluser") param_mariadbuser=$(create_param -u "$mariadbuser")
param_password=$(create_param -p "$password") param_password=$(create_param -p "$password")
param_configfile=$(create_param --defaults-extra-file= "$myconfig") param_configfile=$(create_param --defaults-extra-file= "$mariadbconfig")
export MYSQL_PWD=$password export MARIADB_PWD=$password
param_mysql="$param_mysqlhost $param_port $param_mysqluser $param_configfile" param_mariadb="$param_mariadbhost $param_port $param_mariadbuser $param_configfile"
# #
# verify the database connection # verify the database connection
# #
mysql $param_mysql -B -N -e '\s;' >/dev/null 2>&1 || { mariadb $param_mariadb -B -N -e '\s;' >/dev/null 2>&1 || {
echo "CRITICAL: mysql connection check failed" echo "CRITICAL: mariadb connection check failed"
exit $ST_CR exit $ST_CR
} }
# #
# retrieve the mysql status # retrieve the mariadb status
# #
rMysqlStatus=$(mysql $param_mysql -B -N -e "show status like 'wsrep_%';") rMariadbStatus=$(mariadb $param_mariadb -B -N -e "show status like 'wsrep_%';")
# #
# verify that the node is part of a cluster # verify that the node is part of a cluster
# #
rClusterStateUuid=$(echo "$rMysqlStatus" | awk '/wsrep_cluster_state_uuid/ {print $2}') rClusterStateUuid=$(echo "$rMariadbStatus" | awk '/wsrep_cluster_state_uuid/ {print $2}')
if [ -z "$rClusterStateUuid" ]; then if [ -z "$rClusterStateUuid" ]; then
echo "CRITICAL: node is not part of a cluster" echo "CRITICAL: node is not part of a cluster"
exit $ST_CR exit $ST_CR
fi fi
rClusterSize=$(echo "$rMysqlStatus" | awk '/wsrep_cluster_size/ {print $2}') rClusterSize=$(echo "$rMariadbStatus" | awk '/wsrep_cluster_size/ {print $2}')
rClusterStatus=$(echo "$rMysqlStatus" | awk '/wsrep_cluster_status/ {print $2}') # Primary rClusterStatus=$(echo "$rMariadbStatus" | awk '/wsrep_cluster_status/ {print $2}') # Primary
rFlowControl=$(echo "$rMysqlStatus" | awk '/wsrep_flow_control_paused\t/ {print $2}') # < 0.1 rFlowControl=$(echo "$rMariadbStatus" | awk '/wsrep_flow_control_paused\t/ {print $2}') # < 0.1
rFlowControl=$(printf "%.14f" $rFlowControl) # issue #4 rFlowControl=$(printf "%.14f" $rFlowControl) # issue #4
rReady=$(echo "$rMysqlStatus" | awk '/wsrep_ready/ {print $2}') # ON rReady=$(echo "$rMariadbStatus" | awk '/wsrep_ready/ {print $2}') # ON
rConnected=$(echo "$rMysqlStatus" | awk '/wsrep_connected/ {print $2}') # ON rConnected=$(echo "$rMariadbStatus" | awk '/wsrep_connected/ {print $2}') # ON
rLocalStateComment=$(echo "$rMysqlStatus" | awk '/wsrep_local_state_comment/ {print $2}') # Synced rLocalStateComment=$(echo "$rMariadbStatus" | awk '/wsrep_local_state_comment/ {print $2}') # Synced
rIncommingAddresses=$(echo "$rMysqlStatus" | awk '/wsrep_incoming_addresses/ {print $2}') rIncommingAddresses=$(echo "$rMariadbStatus" | awk '/wsrep_incoming_addresses/ {print $2}')
if [ -z "$rFlowControl" ]; then if [ -z "$rFlowControl" ]; then
echo "UNKNOWN: wsrep_flow_control_paused is empty" echo "UNKNOWN: wsrep_flow_control_paused is empty"