2014-08-06 15:39:15 +03:00
|
|
|
#!/bin/sh -eu
|
|
|
|
|
|
|
|
# This is a simple example of wsrep notification script (wsrep_notify_cmd).
|
|
|
|
# It will create 'wsrep' schema and two tables in it: 'membeship' and 'status'
|
|
|
|
# and fill them on every membership or node status change.
|
|
|
|
#
|
2022-10-04 13:15:52 +02:00
|
|
|
# Edit parameters below to specify the address and login to server:
|
|
|
|
#
|
2014-08-06 15:39:15 +03:00
|
|
|
USER=root
|
|
|
|
PSWD=rootpass
|
2022-10-04 13:15:52 +02:00
|
|
|
#
|
|
|
|
# If these parameters are not set, then the values
|
|
|
|
# passed by the server are taken:
|
|
|
|
#
|
2014-08-06 15:39:15 +03:00
|
|
|
HOST=127.0.0.1
|
|
|
|
PORT=3306
|
2022-10-04 13:15:52 +02:00
|
|
|
#
|
|
|
|
# Edit parameters below to specify SSL parameters:
|
|
|
|
#
|
|
|
|
ssl_key=
|
|
|
|
ssl_cert=
|
|
|
|
ssl_ca=
|
|
|
|
ssl_capath=
|
|
|
|
ssl_cipher=
|
|
|
|
ssl_crl=
|
|
|
|
ssl_crlpath=
|
|
|
|
ssl_verify_server_cert=0
|
|
|
|
#
|
|
|
|
# Client executable path:
|
|
|
|
#
|
|
|
|
CLIENT="mysql"
|
2014-08-06 15:39:15 +03:00
|
|
|
|
|
|
|
SCHEMA="wsrep"
|
|
|
|
MEMB_TABLE="$SCHEMA.membership"
|
|
|
|
STATUS_TABLE="$SCHEMA.status"
|
|
|
|
|
|
|
|
BEGIN="
|
|
|
|
SET wsrep_on=0;
|
|
|
|
DROP SCHEMA IF EXISTS $SCHEMA; CREATE SCHEMA $SCHEMA;
|
|
|
|
CREATE TABLE $MEMB_TABLE (
|
|
|
|
idx INT UNIQUE PRIMARY KEY,
|
|
|
|
uuid CHAR(40) UNIQUE, /* node UUID */
|
|
|
|
name VARCHAR(32), /* node name */
|
|
|
|
addr VARCHAR(256) /* node address */
|
|
|
|
) ENGINE=MEMORY;
|
|
|
|
CREATE TABLE $STATUS_TABLE (
|
|
|
|
size INT, /* component size */
|
|
|
|
idx INT, /* this node index */
|
|
|
|
status CHAR(16), /* this node status */
|
|
|
|
uuid CHAR(40), /* cluster UUID */
|
|
|
|
prim BOOLEAN /* if component is primary */
|
|
|
|
) ENGINE=MEMORY;
|
|
|
|
BEGIN;
|
|
|
|
"
|
|
|
|
END="COMMIT;"
|
|
|
|
|
|
|
|
configuration_change()
|
|
|
|
{
|
|
|
|
echo "$BEGIN;"
|
|
|
|
|
|
|
|
local idx=0
|
|
|
|
|
2022-10-04 13:15:52 +02:00
|
|
|
for NODE in $(echo "$MEMBERS" | sed s/,/\ /g)
|
2014-08-06 15:39:15 +03:00
|
|
|
do
|
|
|
|
echo "INSERT INTO $MEMB_TABLE VALUES ( $idx, "
|
|
|
|
# Don't forget to properly quote string values
|
|
|
|
echo "'$NODE'" | sed s/\\//\',\'/g
|
|
|
|
echo ");"
|
|
|
|
idx=$(( $idx + 1 ))
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "INSERT INTO $STATUS_TABLE VALUES($idx, $INDEX, '$STATUS', '$CLUSTER_UUID', $PRIMARY);"
|
|
|
|
|
|
|
|
echo "$END"
|
|
|
|
}
|
|
|
|
|
|
|
|
status_update()
|
|
|
|
{
|
|
|
|
echo "SET wsrep_on=0; BEGIN; UPDATE $STATUS_TABLE SET status='$STATUS'; COMMIT;"
|
|
|
|
}
|
|
|
|
|
2022-10-04 13:15:52 +02:00
|
|
|
trim_string()
|
|
|
|
{
|
|
|
|
if [ -n "${BASH_VERSION:-}" ]; then
|
|
|
|
local pattern="[![:space:]${2:-}]"
|
|
|
|
local x="${1#*$pattern}"
|
|
|
|
local z=${#1}
|
|
|
|
x=${#x}
|
|
|
|
if [ $x -ne $z ]; then
|
|
|
|
local y="${1%$pattern*}"
|
|
|
|
y=${#y}
|
|
|
|
x=$(( z-x-1 ))
|
|
|
|
y=$(( y-x+1 ))
|
|
|
|
printf '%s' "${1:$x:$y}"
|
|
|
|
else
|
|
|
|
printf ''
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
local pattern="[[:space:]${2:-}]"
|
|
|
|
echo "$1" | sed -E "s/^$pattern+|$pattern+\$//g"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-08-06 15:39:15 +03:00
|
|
|
COM=status_update # not a configuration change by default
|
|
|
|
|
2022-10-04 13:15:52 +02:00
|
|
|
STATUS=""
|
|
|
|
CLUSTER_UUID=""
|
|
|
|
PRIMARY="0"
|
|
|
|
INDEX=""
|
|
|
|
MEMBERS=""
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
2014-08-06 15:39:15 +03:00
|
|
|
case $1 in
|
|
|
|
--status)
|
2022-10-04 13:15:52 +02:00
|
|
|
STATUS=$(trim_string "$2")
|
2014-08-06 15:39:15 +03:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--uuid)
|
2022-10-04 13:15:52 +02:00
|
|
|
CLUSTER_UUID=$(trim_string "$2")
|
2014-08-06 15:39:15 +03:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--primary)
|
|
|
|
[ "$2" = "yes" ] && PRIMARY="1" || PRIMARY="0"
|
|
|
|
COM=configuration_change
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--index)
|
2022-10-04 13:15:52 +02:00
|
|
|
INDEX=$(trim_string "$2")
|
2014-08-06 15:39:15 +03:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--members)
|
2022-10-04 13:15:52 +02:00
|
|
|
MEMBERS=$(trim_string "$2")
|
2014-08-06 15:39:15 +03:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2022-10-04 13:15:52 +02:00
|
|
|
USER=$(trim_string "$USER")
|
|
|
|
PSWD=$(trim_string "$PSWD")
|
|
|
|
|
|
|
|
HOST=$(trim_string "$HOST")
|
|
|
|
PORT=$(trim_string "$PORT")
|
|
|
|
|
|
|
|
case "$HOST" in
|
|
|
|
\[*)
|
|
|
|
HOST="${HOST##\[}"
|
|
|
|
HOST=$(trim_string "${HOST%%\]}")
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -z "$HOST" ]; then
|
|
|
|
HOST="${NOTIFY_HOST:-}"
|
|
|
|
fi
|
|
|
|
if [ -z "$PORT" ]; then
|
|
|
|
PORT="${NOTIFY_PORT:-}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ssl_key=$(trim_string "$ssl_key");
|
|
|
|
ssl_cert=$(trim_string "$ssl_cert");
|
|
|
|
ssl_ca=$(trim_string "$ssl_ca");
|
|
|
|
ssl_capath=$(trim_string "$ssl_capath");
|
|
|
|
ssl_cipher=$(trim_string "$ssl_cipher");
|
|
|
|
ssl_crl=$(trim_string "$ssl_crl");
|
|
|
|
ssl_crlpath=$(trim_string "$ssl_crlpath");
|
|
|
|
ssl_verify_server_cert=$(trim_string "$ssl_verify_server_cert");
|
|
|
|
|
|
|
|
SSL_PARAM=""
|
|
|
|
|
|
|
|
if [ -n "$ssl_key" -o -n "$ssl_cert" -o \
|
|
|
|
-n "$ssl_ca" -o -n "$ssl_capath" -o \
|
|
|
|
-n "$ssl_cipher" ]
|
2014-08-06 15:39:15 +03:00
|
|
|
then
|
2022-10-04 13:15:52 +02:00
|
|
|
SSL_PARAM=' --ssl'
|
|
|
|
[ -n "$ssl_key" ] && SSL_PARAM="$SSL_PARAM --ssl-key='$ssl_key'"
|
|
|
|
[ -n "$ssl_cert" ] && SSL_PARAM="$SSL_PARAM --ssl-cert='$ssl_cert'"
|
|
|
|
[ -n "$ssl_ca" ] && SSL_PARAM="$SSL_PARAM --ssl-ca='$ssl_ca'"
|
|
|
|
[ -n "$ssl_capath" ] && SSL_PARAM="$SSL_PARAM --ssl-capath='$ssl_capath'"
|
|
|
|
[ -n "$ssl_cipher" ] && SSL_PARAM="$SSL_PARAM --ssl-cipher='$ssl_cipher'"
|
|
|
|
[ -n "$ssl_crl" ] && SSL_PARAM="$SSL_PARAM --ssl-crl='$ssl_crl'"
|
|
|
|
[ -n "$ssl_crlpath" ] && SSL_PARAM="$SSL_PARAM --ssl-crlpath='$ssl_crlpath'"
|
|
|
|
if [ -n "$ssl_verify_server_cert" ]; then
|
|
|
|
if [ $ssl_verify_server_cert -ne 0 ]; then
|
|
|
|
SSL_PARAM+=' --ssl-verify-server-cert'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Undefined means node is shutting down
|
|
|
|
if [ "$STATUS" != 'Undefined' ]; then
|
|
|
|
"$COM" | eval "$CLIENT" -B "-u'$USER'"${PSWD:+" -p'$PSWD'"}\
|
|
|
|
"-h'$HOST'" "-P$PORT"$SSL_PARAM
|
2014-08-06 15:39:15 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|