summaryrefslogtreecommitdiff
path: root/scripts/wsrep_sst_common.sh
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2022-01-04 10:30:45 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2022-01-04 10:30:45 +0200
commitdaf4fa5238a67fcf47075721d86d4348adab687b (patch)
treefff85b8f2e11607c93d806e787475ad82f5055f6 /scripts/wsrep_sst_common.sh
parent756568f26c6a23c537f4d93ff00f485c6291c92e (diff)
parent7dfaded9625e832fade4ef1678bcb21c445dad2b (diff)
downloadmariadb-git-st-10.8-merge.tar.gz
Merge 10.7 into 10.8st-10.8-merge
Diffstat (limited to 'scripts/wsrep_sst_common.sh')
-rw-r--r--scripts/wsrep_sst_common.sh264
1 files changed, 175 insertions, 89 deletions
diff --git a/scripts/wsrep_sst_common.sh b/scripts/wsrep_sst_common.sh
index f043b56da90..983f44768aa 100644
--- a/scripts/wsrep_sst_common.sh
+++ b/scripts/wsrep_sst_common.sh
@@ -17,7 +17,10 @@
# This is a common command line parser to be sourced by other SST scripts
-set -u
+set -ue
+
+# Setting the path for some utilities on CentOS
+export PATH="$PATH:/usr/sbin:/usr/bin:/sbin:/bin"
WSREP_SST_OPT_BYPASS=0
WSREP_SST_OPT_BINLOG=""
@@ -384,10 +387,8 @@ case "$1" in
skip_mysqld_arg=1
;;
'--innodb-force-recovery')
- if [ -n "$value" ]; then
- if [ "$value" -ne 0 ]; then
- INNODB_FORCE_RECOVERY="$value"
- fi
+ if [ -n "$value" -a "$value" != "0" ]; then
+ INNODB_FORCE_RECOVERY="$value"
fi
skip_mysqld_arg=1
;;
@@ -584,7 +585,8 @@ get_binlog()
if [ -n "$WSREP_SST_OPT_ADDR_PORT" ]; then
if [ -n "$WSREP_SST_OPT_PORT" ]; then
if [ "$WSREP_SST_OPT_PORT" != "$WSREP_SST_OPT_ADDR_PORT" ]; then
- echo "WSREP_SST: [ERROR] port in --port=$WSREP_SST_OPT_PORT differs from port in --address=$WSREP_SST_OPT_ADDR" >&2
+ echo "WSREP_SST: [ERROR] port in --port=$WSREP_SST_OPT_PORT" \
+ "differs from port in --address=$WSREP_SST_OPT_ADDR" >&2
exit 2
fi
else
@@ -616,8 +618,19 @@ fi
readonly WSREP_SST_OPT_ADDR
readonly WSREP_SST_OPT_ADDR_PORT
-# try to use my_print_defaults, mysql and mysqldump that come with the sources
-# (for MTR suite)
+commandex()
+{
+ if [ -n "$BASH_VERSION" ]; then
+ command -v "$1" || :
+ elif [ -x "$1" ]; then
+ echo "$1"
+ else
+ which "$1" || :
+ fi
+}
+
+# try to use my_print_defaults, mysql and mysqldump that come
+# with the sources (for MTR suite):
script_binary=$(dirname "$0")
SCRIPTS_DIR=$(cd "$script_binary"; pwd -P)
EXTRA_DIR="$SCRIPTS_DIR/../extra"
@@ -626,13 +639,13 @@ CLIENT_DIR="$SCRIPTS_DIR/../client"
if [ -x "$CLIENT_DIR/mariadb" ]; then
MYSQL_CLIENT="$CLIENT_DIR/mariadb"
else
- MYSQL_CLIENT="$(command -v mariadb)"
+ MYSQL_CLIENT=$(commandex 'mariadb')
fi
if [ -x "$CLIENT_DIR/mariadb-dump" ]; then
MYSQLDUMP="$CLIENT_DIR/mariadb-dump"
else
- MYSQLDUMP="$(command -v mariadb-dump)"
+ MYSQLDUMP=$(commandex 'mariadb-dump')
fi
wsrep_log()
@@ -663,7 +676,7 @@ if [ -x "$SCRIPTS_DIR/my_print_defaults" ]; then
elif [ -x "$EXTRA_DIR/my_print_defaults" ]; then
MY_PRINT_DEFAULTS="$EXTRA_DIR/my_print_defaults"
else
- MY_PRINT_DEFAULTS="$(command -v my_print_defaults)"
+ MY_PRINT_DEFAULTS=$(commandex 'my_print_defaults')
if [ -z "$MY_PRINT_DEFAULTS" ]; then
wsrep_log_error "my_print_defaults not found in path"
exit 2
@@ -673,16 +686,16 @@ fi
readonly MY_PRINT_DEFAULTS
wsrep_defaults="$WSREP_SST_OPT_DEFAULTS"
-wsrep_defaults="$wsrep_defaults${wsrep_defaults:+ }$WSREP_SST_OPT_EXTRA_DEFAULTS"
-wsrep_defaults="$wsrep_defaults${wsrep_defaults:+ }$WSREP_SST_OPT_SUFFIX_DEFAULT"
+wsrep_defaults="$wsrep_defaults${WSREP_SST_OPT_EXTRA_DEFAULTS:+ }$WSREP_SST_OPT_EXTRA_DEFAULTS"
+wsrep_defaults="$wsrep_defaults${WSREP_SST_OPT_SUFFIX_DEFAULT:+ }$WSREP_SST_OPT_SUFFIX_DEFAULT"
-readonly WSREP_SST_OPT_CONF="$wsrep_defaults"
+readonly WSREP_SST_OPT_CONF="${wsrep_defaults:+ }$wsrep_defaults"
wsrep_defaults="$WSREP_SST_OPT_DEFAULT"
-wsrep_defaults="$wsrep_defaults${wsrep_defaults:+ }$WSREP_SST_OPT_EXTRA_DEFAULT"
-wsrep_defaults="$wsrep_defaults${wsrep_defaults:+ }$WSREP_SST_OPT_SUFFIX_DEFAULT"
+wsrep_defaults="$wsrep_defaults${WSREP_SST_OPT_EXTRA_DEFAULT:+ }$WSREP_SST_OPT_EXTRA_DEFAULT"
+wsrep_defaults="$wsrep_defaults${WSREP_SST_OPT_SUFFIX_DEFAULT:+ }$WSREP_SST_OPT_SUFFIX_DEFAULT"
-readonly WSREP_SST_OPT_CONF_UNQUOTED="$wsrep_defaults"
+readonly WSREP_SST_OPT_CONF_UNQUOTED="${wsrep_defaults:+ }$wsrep_defaults"
#
# User can specify mariabackup specific settings that will be used during sst
@@ -819,8 +832,7 @@ if wsrep_auth_not_set; then
fi
# Splitting WSREP_SST_OPT_AUTH as "user:password" pair:
-if ! wsrep_auth_not_set
-then
+if ! wsrep_auth_not_set; then
# Extract username as shortest prefix up to first ':' character:
WSREP_SST_OPT_AUTH_USER="${WSREP_SST_OPT_AUTH%%:*}"
if [ -z "$WSREP_SST_OPT_USER" ]; then
@@ -848,8 +860,7 @@ readonly WSREP_SST_OPT_USER
readonly WSREP_SST_OPT_PSWD
readonly WSREP_SST_OPT_AUTH
-if [ -n "$WSREP_SST_OPT_REMOTE_AUTH" ]
-then
+if [ -n "$WSREP_SST_OPT_REMOTE_AUTH" ]; then
# Split auth string at the last ':'
readonly WSREP_SST_OPT_REMOTE_USER="${WSREP_SST_OPT_REMOTE_AUTH%%:*}"
readonly WSREP_SST_OPT_REMOTE_PSWD="${WSREP_SST_OPT_REMOTE_AUTH#*:}"
@@ -860,8 +871,7 @@ fi
readonly WSREP_SST_OPT_REMOTE_AUTH
-if [ -n "$WSREP_SST_OPT_DATA" ]
-then
+if [ -n "$WSREP_SST_OPT_DATA" ]; then
SST_PROGRESS_FILE="$WSREP_SST_OPT_DATA/sst_in_progress"
else
SST_PROGRESS_FILE=""
@@ -869,14 +879,15 @@ fi
wsrep_cleanup_progress_file()
{
- [ -n "$SST_PROGRESS_FILE" -a \
- -f "$SST_PROGRESS_FILE" ] && rm -f "$SST_PROGRESS_FILE" 2>/dev/null || true
+ if [ -n "$SST_PROGRESS_FILE" -a -f "$SST_PROGRESS_FILE" ]; then
+ rm -f "$SST_PROGRESS_FILE" 2>/dev/null || :
+ fi
}
wsrep_check_program()
{
local prog="$1"
- local cmd=$(command -v "$prog")
+ local cmd=$(commandex "$prog")
if [ -z "$cmd" ]; then
echo "'$prog' not found in PATH"
return 2 # no such file or directory
@@ -886,21 +897,18 @@ wsrep_check_program()
wsrep_check_programs()
{
local ret=0
-
- while [ $# -gt 0 ]
- do
+ while [ $# -gt 0 ]; do
wsrep_check_program "$1" || ret=$?
shift
done
-
return $ret
}
wsrep_check_datadir()
{
- if [ -z "$WSREP_SST_OPT_DATA" ]
- then
- wsrep_log_error "The '--datadir' parameter must be passed to the SST script"
+ if [ -z "$WSREP_SST_OPT_DATA" ]; then
+ wsrep_log_error \
+ "The '--datadir' parameter must be passed to the SST script"
exit 2
fi
}
@@ -912,10 +920,10 @@ get_openssl()
return
fi
# Let's look for openssl:
- OPENSSL_BINARY="$(command -v openssl)"
+ OPENSSL_BINARY=$(commandex 'openssl')
if [ -z "$OPENSSL_BINARY" ]; then
OPENSSL_BINARY='/usr/bin/openssl'
- if [ -z "$OPENSSL_BINARY" ]; then
+ if [ ! -x "$OPENSSL_BINARY" ]; then
OPENSSL_BINARY=""
fi
fi
@@ -928,13 +936,12 @@ get_openssl()
wsrep_gen_secret()
{
get_openssl
- if [ -n "$OPENSSL_BINARY" ]
- then
+ if [ -n "$OPENSSL_BINARY" ]; then
echo $("$OPENSSL_BINARY" rand -hex 16)
else
printf "%04x%04x%04x%04x%04x%04x%04x%04x" \
- $RANDOM $RANDOM $RANDOM $RANDOM \
- $RANDOM $RANDOM $RANDOM $RANDOM
+ $RANDOM $RANDOM $RANDOM $RANDOM \
+ $RANDOM $RANDOM $RANDOM $RANDOM
fi
}
@@ -968,14 +975,14 @@ is_local_ip()
fi
# Now let's check if the given address is assigned to
# one of the network cards:
- local ip_util="$(command -v ip)"
+ local ip_util=$(commandex 'ip')
if [ -n "$ip_util" ]; then
# ip address show ouput format is " inet[6] <address>/<mask>":
"$ip_util" address show \
| grep -E "^[[:space:]]*inet.? [^[:space:]]+/" -o \
| grep -F " $1/" >/dev/null && return 0
else
- local ifconfig_util="$(command -v ifconfig)"
+ local ifconfig_util=$(commandex 'ifconfig')
if [ -n "$ifconfig_util" ]; then
# ifconfig output format is " inet[6] <address> ...":
"$ifconfig_util" \
@@ -992,15 +999,15 @@ check_sockets_utils()
sockstat_available=0
ss_available=0
- [ -n "$(command -v lsof)" ] && lsof_available=1
- [ -n "$(command -v sockstat)" ] && sockstat_available=1
- [ -n "$(command -v ss)" ] && ss_available=1
+ [ -n "$(commandex lsof)" ] && lsof_available=1
+ [ -n "$(commandex sockstat)" ] && sockstat_available=1
+ [ -n "$(commandex ss)" ] && ss_available=1
if [ $lsof_available -eq 0 -a \
$sockstat_available -eq 0 -a \
$ss_available -eq 0 ]
then
- wsrep_log_error "Neither lsof, nor sockstat or ss tool was found in " \
+ wsrep_log_error "Neither lsof, nor sockstat or ss tool was found in" \
"the PATH. Make sure you have it installed."
exit 2 # ENOENT
fi
@@ -1018,11 +1025,11 @@ check_sockets_utils()
#
check_port()
{
- local pid="$1"
+ local pid="${1:-0}"
local port="$2"
local utils="$3"
- [ -z "$pid" ] || [ $pid -eq 0 ] && pid='[0-9]+'
+ [ $pid -le 0 ] && pid='[0-9]+'
local rc=1
@@ -1060,14 +1067,20 @@ check_for_dhparams()
if [ ! -r "$ssl_dhparams" ]; then
get_openssl
if [ -n "$OPENSSL_BINARY" ]; then
- wsrep_log_info "Could not find dhparams file, creating $ssl_dhparams"
- if ! "$OPENSSL_BINARY" dhparam -out "$ssl_dhparams" 2048 >/dev/null 2>&1
- then
+ wsrep_log_info \
+ "Could not find dhparams file, creating $ssl_dhparams"
+ local bug=0
+ local errmsg
+ errmsg=$("$OPENSSL_BINARY" \
+ dhparam -out "$ssl_dhparams" 2048 2>&1) || bug=1
+ if [ $bug -ne 0 ]; then
+ wsrep_log_info "run: \"$OPENSSL_BINARY\" dhparam -out \"$ssl_dhparams\" 2048"
+ wsrep_log_info "output: $errmsg"
wsrep_log_error "******** ERROR *****************************************"
wsrep_log_error "* Could not create the dhparams.pem file with OpenSSL. *"
wsrep_log_error "********************************************************"
ssl_dhparams=""
- fi
+ fi
else
# Rollback: if openssl is not installed, then use
# the default parameters:
@@ -1085,26 +1098,48 @@ check_for_dhparams()
#
verify_ca_matches_cert()
{
- local ca="$1"
- local cert="$2"
- local path=${3:-0}
+ local cert="$1"
+ local ca="$2"
+ local cap="$3"
+
+ local readable=1; [ ! -r "$cert" ] && readable=0
+ [ -n "$ca" -a ! -r "$ca" ] && readable=0
+ [ -n "$cap" -a ! -r "$cap" ] && readable=0
+
+ if [ $readable -eq 0 ]; then
+ wsrep_log_error \
+ "Both PEM file and CA file (or path) must be readable"
+ exit 22
+ fi
# If the openssl utility is not installed, then
# we will not do this certificate check:
get_openssl
if [ -z "$OPENSSL_BINARY" ]; then
+ wsrep_log_info "openssl utility not found"
return
fi
- local not_match=0
+ local readable=1; [ ! -r "$cert" ] && readable=0
+ [ -n "$ca" ] && [ ! -r "$ca" ] && readable=0
+ [ -n "$cap" ] && [ ! -r "$cap" ] && readable=0
- if [ $path -eq 0 ]; then
- "$OPENSSL_BINARY" verify -verbose -CAfile "$ca" "$cert" >/dev/null 2>&1 || not_match=1
- else
- "$OPENSSL_BINARY" verify -verbose -CApath "$ca" "$cert" >/dev/null 2>&1 || not_match=1
+ if [ readable -eq 0 ]; then
+ wsrep_log_error \
+ "Both PEM file and CA file (or path) must be readable"
+ exit 22
fi
+ local not_match=0
+ local errmsg
+ errmsg=$("$OPENSSL_BINARY" verify -verbose \
+ ${ca:+ -CAfile} ${ca:+ "$ca"} \
+ ${cap:+ -CApath} ${cap:+ "$cap"} \
+ "$cert" 2>&1) || not_match=1
+
if [ $not_match -eq 1 ]; then
+ wsrep_log_info "run: \"$OPENSSL_BINARY\" verify -verbose${ca:+ -CAfile \"$ca\"}${cap:+ -CApath \"$cap\"} \"$cert\""
+ wsrep_log_info "output: $errmsg"
wsrep_log_error "******** FATAL ERROR ********************************************"
wsrep_log_error "* The certifcate and CA (certificate authority) do not match. *"
wsrep_log_error "* It does not appear that the certificate was issued by the CA. *"
@@ -1124,12 +1159,19 @@ verify_ca_matches_cert()
#
verify_cert_matches_key()
{
- local cert_path="$1"
- local key_path="$2"
+ local cert="$1"
+ local key="$2"
+
+ if [ ! -r "$key" -o ! -r "$cert" ]; then
+ wsrep_log_error "Both the certificate file and the key file" \
+ "must be readable"
+ exit 22
+ fi
# If the diff utility is not installed, then
# we will not do this certificate check:
- if [ -z "$(command -v diff)" ]; then
+ if [ -z "$(commandex diff)" ]; then
+ wsrep_log_info "diff utility not found"
return
fi
@@ -1137,18 +1179,19 @@ verify_cert_matches_key()
# we will not do this certificate check:
get_openssl
if [ -z "$OPENSSL_BINARY" ]; then
+ wsrep_log_info "openssl utility not found"
return
fi
# Generate the public key from the cert and the key.
# They should match (otherwise we can't create an SSL connection).
- if ! diff <("$OPENSSL_BINARY" x509 -in "$cert_path" -pubkey -noout 2>/dev/null) \
- <("$OPENSSL_BINARY" pkey -in "$key_path" -pubout 2>/dev/null) >/dev/null 2>&1
+ if ! diff <("$OPENSSL_BINARY" x509 -in "$cert" -pubkey -noout 2>/dev/null) \
+ <("$OPENSSL_BINARY" pkey -in "$key" -pubout 2>/dev/null) >/dev/null 2>&1
then
- wsrep_log_error "******************* FATAL ERROR ****************"
- wsrep_log_error "* The certifcate and private key do not match. *"
- wsrep_log_error "* Please check your certificate and key files. *"
- wsrep_log_error "************************************************"
+ wsrep_log_error "******************* FATAL ERROR *****************"
+ wsrep_log_error "* The certificate and private key do not match. *"
+ wsrep_log_error "* Please check your certificate and key files. *"
+ wsrep_log_error "*************************************************"
exit 22
fi
}
@@ -1225,18 +1268,18 @@ check_pid()
{
local pid_file="$1"
if [ -r "$pid_file" ]; then
- local pid=$(cat "$pid_file" 2>/dev/null)
+ local pid=$(cat "$pid_file" 2>/dev/null || :)
if [ -n "$pid" ]; then
- if [ $pid -ne 0 ]; then
- if ps -p "$pid" >/dev/null 2>&1; then
+ if [ $pid -gt 0 ]; then
+ if ps -p $pid >/dev/null 2>&1; then
CHECK_PID=$pid
return 0
fi
fi
fi
local remove=${2:-0}
- if [ $remove -eq 1 ]; then
- rm -f "$pid_file"
+ if [ $remove -ne 0 ]; then
+ rm -f "$pid_file" || :
fi
fi
CHECK_PID=0
@@ -1261,25 +1304,25 @@ cleanup_pid()
local pid_file="${2:-}"
local config="${3:-}"
- if [ $pid -ne 0 ]; then
+ if [ $pid -gt 0 ]; then
if ps -p $pid >/dev/null 2>&1; then
if kill $pid >/dev/null 2>&1; then
sleep 0.5
local round=0
local force=0
while ps -p $pid >/dev/null 2>&1; do
- sleep 1
- round=$(( round+1 ))
- if [ $round -eq 16 ]; then
- if [ $force -eq 0 ]; then
- round=8
- force=1
- kill -9 $pid >/dev/null 2>&1
- sleep 0.5
- else
- return 1
- fi
- fi
+ sleep 1
+ round=$(( round+1 ))
+ if [ $round -eq 16 ]; then
+ if [ $force -eq 0 ]; then
+ round=8
+ force=1
+ kill -9 $pid >/dev/null 2>&1 || :
+ sleep 0.5
+ else
+ return 1
+ fi
+ fi
done
elif ps -p $pid >/dev/null 2>&1; then
wsrep_log_warning "Unable to kill PID=$pid ($pid_file)"
@@ -1288,8 +1331,8 @@ cleanup_pid()
fi
fi
- [ -n "$pid_file" ] && [ -f "$pid_file" ] && rm -f "$pid_file"
- [ -n "$config" ] && [ -f "$config" ] && rm -f "$config"
+ [ -n "$pid_file" -a -f "$pid_file" ] && rm -f "$pid_file" || :
+ [ -n "$config" -a -f "$config" ] && rm -f "$config" || :
return 0
}
@@ -1305,9 +1348,52 @@ get_proc()
elif [ "$OS" = 'Darwin' -o "$OS" = 'FreeBSD' ]; then
nproc=$(sysctl -n hw.ncpu)
fi
+ set -e
if [ -z "$nproc" ] || [ $nproc -eq 0 ]; then
nproc=1
fi
- set -e
+ fi
+}
+
+check_server_ssl_config()
+{
+ # backward-compatible behavior:
+ tcert=$(parse_cnf 'sst' 'tca')
+ tcap=$(parse_cnf 'sst' 'tcapath')
+ tpem=$(parse_cnf 'sst' 'tcert')
+ tkey=$(parse_cnf 'sst' 'tkey')
+ # reading new ssl configuration options:
+ local tcert2=$(parse_cnf "$encgroups" 'ssl-ca')
+ local tcap2=$(parse_cnf "$encgroups" 'ssl-capath')
+ local tpem2=$(parse_cnf "$encgroups" 'ssl-cert')
+ local tkey2=$(parse_cnf "$encgroups" 'ssl-key')
+ # if there are no old options, then we take new ones:
+ if [ -z "$tcert" -a -z "$tcap" -a -z "$tpem" -a -z "$tkey" ]; then
+ tcert="$tcert2"
+ tcap="$tcap2"
+ tpem="$tpem2"
+ tkey="$tkey2"
+ # checking for presence of the new-style SSL configuration:
+ elif [ -n "$tcert2" -o -n "$tcap2" -o -n "$tpem2" -o -n "$tkey2" ]; then
+ if [ "$tcert" != "$tcert2" -o \
+ "$tcap" != "$tcap2" -o \
+ "$tpem" != "$tpem2" -o \
+ "$tkey" != "$tkey2" ]
+ then
+ wsrep_log_info \
+ "new ssl configuration options (ssl-ca[path], ssl-cert" \
+ "and ssl-key) are ignored by SST due to presence" \
+ "of the tca[path], tcert and/or tkey in the [sst] section"
+ fi
+ fi
+ if [ -n "$tcert" ]; then
+ tcert=$(trim_string "$tcert")
+ if [ "${tcert%/}" != "$tcert" -o -d "$tcert" ]; then
+ tcap="$tcert"
+ tcert=""
+ fi
+ fi
+ if [ -n "$tcap" ]; then
+ tcap=$(trim_string "$tcap")
fi
}