diff options
Diffstat (limited to 'modules/apps/mariadb/slave-watchdog.nix')
-rw-r--r-- | modules/apps/mariadb/slave-watchdog.nix | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/modules/apps/mariadb/slave-watchdog.nix b/modules/apps/mariadb/slave-watchdog.nix index 8d1147e..74cf7ef 100644 --- a/modules/apps/mariadb/slave-watchdog.nix +++ b/modules/apps/mariadb/slave-watchdog.nix @@ -1,4 +1,4 @@ -{ changeMaster, importDump }: '' +{ cfg, changeMaster, importDump }: '' set -euo pipefail ch="$1" @@ -6,11 +6,11 @@ status=$(mktemp) trap 'rm -f "$status"' EXIT slave_status () { - if ! mysql -e ';'; then + if ! ${cfg.package}/bin/mysql -e ';'; then echo unknown; return fi - if mysql -e "SHOW SLAVE '$1' STATUS\\G" | sed 's,^ *,,' > "$status"; then + if ${cfg.package}/bin/mysql -e "SHOW SLAVE '$1' STATUS\\G" | sed 's,^ *,,' > "$status"; then if grep -oE '\bMaster_Server_Id:\s*[1-9][0-9]*' "$status" >&2; then io_errno=$(awk '/Last_IO_Errno:/ {print $2}' "$status") sql_errno=$(awk '/Last_SQL_Errno:/ {print $2}' "$status") @@ -53,44 +53,44 @@ while true; do sleep 1m continue fi - mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2 - ${changeMaster} "$ch" | mysql - if ${importDump} "$ch" | mysql; then - mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2 + ${changeMaster} "$ch" | ${cfg.package}/bin/mysql + if ${importDump} "$ch" | ${cfg.package}/bin/mysql; then + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 exit else echo 'Import failed. Starting over' >&2 - mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2 + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2 exit 1 fi ;; io_error:*) echo "status: $st" >&2 - mysql -v -N -e "CALL mysql.stopSlave('$ch')" >&2 - ${changeMaster} "$ch" | mysql - mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.stopSlave('$ch')" >&2 + ${changeMaster} "$ch" | ${cfg.package}/bin/mysql + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 exit 1 ;; sql_error:1205) # Lock wait timeout exceeded echo "status: $st" >&2 - mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 exit 1 ;; sql_error:*) (( ++sql_errors )) echo "status: $st (count: $sql_errors)" >&2 if [ "$sql_errors" -le 1 ]; then - mysql -v -N -e "CALL mysql.pauseSlave('$ch')" >&2 + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.pauseSlave('$ch')" >&2 sleep 1s - mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 elif [ "$sql_errors" -le 2 ]; then - mysql -v -N -e "CALL mysql.stopSlave('$ch')" >&2 + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.stopSlave('$ch')" >&2 # this *unlikely* *may* change replication option (ignore tables, etc.) - ${changeMaster} "$ch" | mysql - mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 + ${changeMaster} "$ch" | ${cfg.package}/bin/mysql + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.startSlave('$ch')" >&2 else echo '!!! Resetting slave !!!' >&2 - mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2 + ${cfg.package}/bin/mysql -v -N -e "CALL mysql.resetSlave('$ch')" >&2 exit 1 fi sleep 2m |