From 1dc64b551c52237558369225631df1c66b807a60 Mon Sep 17 00:00:00 2001 From: Christian Adams Date: Tue, 29 Aug 2023 11:05:11 -0400 Subject: [PATCH] Add keepalive to migrate data script (#1538) Signed-off-by: Christian M. Adams --- roles/installer/tasks/migrate_data.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/roles/installer/tasks/migrate_data.yml b/roles/installer/tasks/migrate_data.yml index 576afc07..7f999a09 100644 --- a/roles/installer/tasks/migrate_data.yml +++ b/roles/installer/tasks/migrate_data.yml @@ -59,14 +59,29 @@ namespace: "{{ ansible_operator_meta.namespace }}" pod: "{{ postgres_pod_name }}" command: | - bash -c """ + bash -c " + function end_keepalive { + rc=$? + rm -f \"$1\" + kill $(cat /proc/$2/task/$2/children 2>/dev/null) 2>/dev/null || true + wait $2 || true + exit $rc + } + keepalive_file=\"$(mktemp)\" + while [[ -f \"$keepalive_file\" ]]; do + echo 'Migrating data from old database...' + sleep 60 + done & + keepalive_pid=$! + trap 'end_keepalive \"$keepalive_file\" \"$keepalive_pid\"' EXIT SIGINT SIGTERM + echo keepalive_pid: $keepalive_pid set -e -o pipefail PGPASSWORD='{{ awx_old_postgres_pass }}' {{ pgdump }} | PGPASSWORD='{{ awx_postgres_pass }}' {{ pg_restore }} + set +e +o pipefail echo 'Successful' - """ + " no_log: "{{ no_log }}" register: data_migration - failed_when: "'Successful' not in data_migration.stdout" - name: Set flag signifying that this instance has been migrated set_fact: