From 8706a35705e13bdab2a318c615ebdb9c4d1b0195 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Mon, 22 May 2023 14:16:14 +0200 Subject: [PATCH] mysql: improve shell syntax for mysql_skip script --- CHANGELOG.md | 5 ++++- mysql/files/mysql_skip.sh | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1397fdbb..6673906a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,15 +12,18 @@ The **patch** part changes is incremented if multiple releases happen the same m ## [Unreleased] ### Added + * userlogrotate: rotate also php.log. * nagios-nrpe: add a NRPE check-local command with completion. ### Changed * elasticsearch: improve networking configuration -* evolinux-users: remove Stretch references in tasks that also apply to next Debian versions. +* evolinux-users: remove Stretch references in tasks that also apply to next Debian versions +* mysql: improve shell syntax for mysql_skip script ### Fixed + * packweb-apache,nagios-nrpe: add missing task and config for PHP 8.2 container * potsfix: add missing `localhost.$mydomain` to mydestination diff --git a/mysql/files/mysql_skip.sh b/mysql/files/mysql_skip.sh index 95bc28f7..ca72a9fc 100644 --- a/mysql/files/mysql_skip.sh +++ b/mysql/files/mysql_skip.sh @@ -18,29 +18,28 @@ log_file="/var/log/mysql_skip.log" mysql_skip_error() { error="$1" - error="$(date --iso-8601=seconds) Skiping: $error" - printf "Skipping: $error\n" - mysql $mysql_opt -e 'SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;' + mysql ${mysql_opt} -e 'SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;' - [ -n "$log_file" ] && echo "$error" >>"$log_file" + printf 'Skipping: %s\n' "$error" + [ -n "$log_file" ] && printf '%s Skipping: %s\n' "$(date --iso-8601=seconds)" "$error" >>"$log_file" } while true; do - slave_status="$(mysql $mysql_opt -e 'SHOW SLAVE STATUS\G')" - seconds_behind_master=$(echo "$slave_status" |grep 'Seconds_Behind_Master: ' |awk -F ' ' '{print $2}') - last_SQL_error="$(echo "$slave_status" |grep 'Last_SQL_Error: ' |sed 's/^.\+Last_SQL_Error: //')" + slave_status="$(mysql ${mysql_opt} -e 'SHOW SLAVE STATUS\G')" + seconds_behind_master=$(echo "${slave_status}" |grep 'Seconds_Behind_Master: ' |awk -F ' ' '{print $2}') + last_SQL_error="$(echo "${slave_status}" |grep 'Last_SQL_Error: ' |sed 's/^.\+Last_SQL_Error: //')" - if [ "$seconds_behind_master" = "0" ]; then + if [ "${seconds_behind_master}" = "0" ]; then #printf 'Replication is up to date!\n' - if [ "$exit_when_uptodate" = "true" ]; then + if [ "${exit_when_uptodate}" = "true" ]; then exit 0 fi elif [ -z "$last_SQL_error" ]; then - sleep $sleep_interval + sleep ${sleep_interval} elif echo "$last_SQL_error" |grep -q -f $error_messages; then - mysql_skip_error "$last_SQL_error" + mysql_skip_error "${last_SQL_error}" fi sleep 1