flush_host_cache.sh, flush_query_cache.sh: support parallel installations.

This commit is contained in:
2023-08-09 09:15:49 +02:00
parent 8876617d4c
commit 30ca2c1a72
2 changed files with 311 additions and 69 deletions

View File

@@ -3,6 +3,8 @@
working_dir="$(dirname $(realpath $0))"
conf_file="${working_dir}/conf/mysql_credetials.conf"
tmp_log_file="$(mktemp)"
#LOGGING=true
LOGGING=false
@@ -11,6 +13,27 @@ LOGGING=false
# --- Some functions
# -------------
clean_up() {
# Perform program exit housekeeping
rm -f $tmp_log_file
blank_line
exit $1
}
echononl(){
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
fi
}
fatal(){
echo ""
if $terminal ; then
@@ -34,6 +57,65 @@ fatal(){
clean_up 1
}
error(){
echo ""
if $terminal ; then
echo -e " [ \033[31m\033[1mError\033[m ]: $*"
else
echo " [ Error ]: $*"
fi
echo ""
}
warn (){
if $terminal ; then
echo ""
echo -e " [ \033[33m\033[1mWarning\033[m ]: $*"
echo ""
else
echo " [ Warning ]: $*"
fi
}
info (){
if $terminal ; then
echo ""
echo -e " [ \033[32m\033[1mInfo\033[m ]: $*"
echo ""
else
echo " [ Info ]: $*"
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[80G[ \033[32mok\033[m ]"
fi
}
echo_failed(){
if $terminal ; then
echo -e "\033[80G[ \033[1;31mfailed\033[m ]"
fi
}
echo_skipped() {
if $terminal ; then
echo -e "\033[80G[ \033[37mskipped\033[m ]"
fi
}
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
blank_line() {
if $terminal ; then
echo ""
fi
}
detect_mysql_version () {
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
@@ -87,16 +169,23 @@ fi
#-----------------------------
#---------------------------------------
blank_line
echononl " Loading configuration settings from $(basename ${conf_file}).."
if [[ -f "$conf_file" ]]; then
source "$conf_file"
source "$conf_file" > $tmp_log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $tmp_log_file)"
fi
else
echo_skipped
if $terminal ;then
warn "No Configuration File found. Loading defaults.."
fi
fi
#[[ -z "$mysql_credential_args" ]] && mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf"
if $LOGGING ;then
echo -e "\n[ `date` ] Going to flush host cache.."
fi
if [[ -z "$mysql_credential_args" ]]; then
@@ -135,14 +224,30 @@ if [[ -z "$mysql_credential_args" ]]; then
fi
# Flush host cache
#
$mysqladmin $mysql_credential_args flush-hosts
[[ $? -gt 0 ]] && echo -e "\t[ Error ]: Flushing host cache failed !!"
if $LOGGING ;then
echo -e "\n[ `date` ] End flushing host cache"
if [[ ${#mysql_credential_args_arr[@]} -eq 0 ]]; then
mysql_credential_args_arr[0]="default:$mysql_credential_args"
fi
exit 0
blank_line
declare -i index_arr=0
while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
IFS=':' read -a _val_arr <<< "${mysql_credential_args_arr[$index_arr]}"
mysql_version="${_val_arr[0]}"
mysql_credential_args="${_val_arr[1]}"
echononl " [ ${mysql_version} ]: Flush host cache.."
$mysqladmin $mysql_credential_args flush-hosts
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $tmp_log_file)"
fi
(( index_arr++ ))
done
clean_up 0