diff options
author | root <root@vps-18a7a2b7.vps.ovh.ca> | 2024-02-15 09:48:48 -0500 |
---|---|---|
committer | root <root@vps-18a7a2b7.vps.ovh.ca> | 2024-02-15 09:48:48 -0500 |
commit | 34edc84dab09b9e28a63dc1e73197acf50a4611e (patch) | |
tree | e43d0770f7da38f0fc74e14136ee6cdff9e5e086 | |
parent | 53eb3cc4479c7904b8abf4f5c6df666052ea5963 (diff) |
clean up the devnulls etc
-rwxr-xr-x | src/mariadb-push-replica.sh | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/src/mariadb-push-replica.sh b/src/mariadb-push-replica.sh index 535ef61..140fb2e 100755 --- a/src/mariadb-push-replica.sh +++ b/src/mariadb-push-replica.sh | |||
@@ -42,18 +42,38 @@ else | |||
42 | fi | 42 | fi |
43 | replication_user=replication | 43 | replication_user=replication |
44 | 44 | ||
45 | run_primary() | 45 | without_tty_input() |
46 | { | ||
47 | if [ -t 0 ] | ||
48 | then | ||
49 | "$@" < /dev/null | ||
50 | else | ||
51 | "$@" | ||
52 | fi | ||
53 | } | ||
54 | |||
55 | run_() | ||
46 | { | 56 | { |
57 | case "$1" in | ||
58 | primary_host | replica_host ) ;; | ||
59 | *_host ) return 54 ;; # lol wut | ||
60 | * ) return 53 ;; | ||
61 | esac | ||
47 | (set -x | 62 | (set -x |
48 | : primary : $1 $2 ${3:+ ...}) | 63 | : ${1%_host} : $2 $3 ${4:+ ...}) |
49 | BASH_RPC_REMOTE_DEST=$primary_host remote_run_function "$@" | 64 | BASH_RPC_REMOTE_DEST=${!1} \ |
65 | without_tty_input \ | ||
66 | remote_run_function "${@:2}" | ||
67 | } | ||
68 | |||
69 | run_primary() | ||
70 | { | ||
71 | run_ primary_host "$@" | ||
50 | } | 72 | } |
51 | 73 | ||
52 | run_replica() | 74 | run_replica() |
53 | { | 75 | { |
54 | (set -x | 76 | run_ replica_host "$@" |
55 | : replica : $1 $2 ${3:+ ...}) | ||
56 | BASH_RPC_REMOTE_DEST=$replica_host remote_run_function "$@" | ||
57 | } | 77 | } |
58 | 78 | ||
59 | show_hostnames() | 79 | show_hostnames() |
@@ -137,7 +157,8 @@ create_replication_user() | |||
137 | create or replace | 157 | create or replace |
138 | user | 158 | user |
139 | '$2'@'$1' | 159 | '$2'@'$1' |
140 | identified by | 160 | identified |
161 | by | ||
141 | '$3' | 162 | '$3' |
142 | ; | 163 | ; |
143 | grant replication slave | 164 | grant replication slave |
@@ -213,9 +234,9 @@ mariadb_enable_semi_sync() | |||
213 | set -e | 234 | set -e |
214 | [ "$1" = off ] || set -- on | 235 | [ "$1" = off ] || set -- on |
215 | mariadb -v --skip-reconnect -t <<. | 236 | mariadb -v --skip-reconnect -t <<. |
216 | stop slave io_thread; | 237 | stop slave io_thread ; |
217 | set global rpl_semi_sync_master_enabled = $1; | 238 | set global rpl_semi_sync_master_enabled = $1 ; |
218 | set global rpl_semi_sync_slave_enabled = $1; | 239 | set global rpl_semi_sync_slave_enabled = $1 ; |
219 | . | 240 | . |
220 | mariadb_show_vars_like 'rpl_%' | 241 | mariadb_show_vars_like 'rpl_%' |
221 | } | 242 | } |
@@ -228,7 +249,9 @@ select | |||
228 | @@hostname | 249 | @@hostname |
229 | , @@server_id | 250 | , @@server_id |
230 | ; | 251 | ; |
231 | use information_schema; | 252 | use |
253 | information_schema | ||
254 | ; | ||
232 | select | 255 | select |
233 | variable_name | 256 | variable_name |
234 | , variable_value | 257 | , variable_value |
@@ -243,11 +266,12 @@ where | |||
243 | mariadb_list_databases() | 266 | mariadb_list_databases() |
244 | { | 267 | { |
245 | show_all_databases >&2 | 268 | show_all_databases >&2 |
246 | mariadb --skip-reconnect -Bsss "$@" <<. | 269 | mariadb --skip-reconnect -B -s <<. |
247 | select | 270 | select |
248 | schema_name | 271 | schema_name |
249 | from | 272 | from |
250 | information_schema.schemata; | 273 | information_schema.schemata |
274 | ; | ||
251 | . | 275 | . |
252 | } | 276 | } |
253 | 277 | ||
@@ -319,15 +343,13 @@ mariadb_scan_databases() | |||
319 | set -- "$(mktemp)" | 343 | set -- "$(mktemp)" |
320 | declare -g -a primary_dbs | 344 | declare -g -a primary_dbs |
321 | save_array primary_dbs from lines <( | 345 | save_array primary_dbs from lines <( |
322 | run_primary mariadb_list_databases \ | 346 | run_primary mariadb_list_databases 2>"$1" | |
323 | </dev/null 2>"$1" | | ||
324 | sort -u | 347 | sort -u |
325 | ) | 348 | ) |
326 | 349 | ||
327 | declare -g -a replica_dbs | 350 | declare -g -a replica_dbs |
328 | save_array replica_dbs from lines <( | 351 | save_array replica_dbs from lines <( |
329 | run_replica mariadb_list_databases \ | 352 | run_replica mariadb_list_databases 2>>"$1" | |
330 | </dev/null 2>>"$1" | | ||
331 | sort -u | 353 | sort -u |
332 | ) | 354 | ) |
333 | 355 | ||
@@ -414,11 +436,8 @@ main() | |||
414 | run_replica \ | 436 | run_replica \ |
415 | show_all_databases | 437 | show_all_databases |
416 | fi | 438 | fi |
417 | if gtid=$(\ | 439 | if gtid=$(run_primary mariadb_get_primary_gtid) && |
418 | run_primary \ | 440 | [ "$gtid" ] |
419 | mariadb_get_primary_gtid \ | ||
420 | </dev/null) && | ||
421 | [ "$gtid" ] | ||
422 | then | 441 | then |
423 | run_replica \ | 442 | run_replica \ |
424 | mariadb_wait_on_gtid "$gtid" | 443 | mariadb_wait_on_gtid "$gtid" |
@@ -427,7 +446,7 @@ main() | |||
427 | 446 | ||
428 | mariadb_get_primary_gtid() | 447 | mariadb_get_primary_gtid() |
429 | { | 448 | { |
430 | mariadb --skip-reconnect -sssB <<. | 449 | mariadb --skip-reconnect -B -s <<. |
431 | select | 450 | select |
432 | @@gtid_binlog_pos; | 451 | @@gtid_binlog_pos; |
433 | . | 452 | . |
@@ -443,9 +462,7 @@ select | |||
443 | , '$gtid' as 'primary gtid' | 462 | , '$gtid' as 'primary gtid' |
444 | ; | 463 | ; |
445 | stop slave ; | 464 | stop slave ; |
446 | stop slave io_thread ; | ||
447 | start slave ; | 465 | start slave ; |
448 | start slave io_thread ; | ||
449 | . | 466 | . |
450 | mariadb -t -v <<. | 467 | mariadb -t -v <<. |
451 | select | 468 | select |