From a21dcec85d191dd6c25fc1e739c25f5383f8c980 Mon Sep 17 00:00:00 2001 From: coolbry95 Date: Fri, 2 Jul 2021 23:24:16 -0400 Subject: [PATCH 1/4] wait for database connection Signed-off-by: coolbry95 --- awx/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/awx/__init__.py b/awx/__init__.py index 35322396b3..9573c3529a 100644 --- a/awx/__init__.py +++ b/awx/__init__.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals import os +import time import sys import warnings @@ -35,6 +36,7 @@ else: from django.db.models import indexes from django.db.backends.utils import names_digest from django.db import connection + from django.db.utils import OperationalError if HAS_DJANGO is True: @@ -152,6 +154,19 @@ def manage(): # enforce the postgres version is equal to 12. if not, then terminate program with exit code of 1 if not MODE == 'development': + # wait for connection to the database + sys.stdout.write("Wainting for connection to database\n") + connected = False + while not connected: + try: + connection.ensure_connection() + connected = True + except OperationalError: + sys.stdout.write("No connection available\n") + time.sleep(1) + + sys.stdout.write("Connection established\n") + if (connection.pg_version // 10000) < 12: sys.stderr.write("Postgres version 12 is required\n") sys.exit(1) From 041e22f609bc5757b5c34338aa079bf06d44512f Mon Sep 17 00:00:00 2001 From: coolbry95 Date: Tue, 13 Jul 2021 08:10:11 -0400 Subject: [PATCH 2/4] wait for migrations in awx-web container --- awx/__init__.py | 15 --------------- .../ansible/roles/dockerfile/files/launch_awx.sh | 2 ++ .../roles/dockerfile/files/launch_awx_task.sh | 2 +- .../roles/dockerfile/files/wait-for-migrations | 11 +++++++++-- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/awx/__init__.py b/awx/__init__.py index 9573c3529a..35322396b3 100644 --- a/awx/__init__.py +++ b/awx/__init__.py @@ -3,7 +3,6 @@ from __future__ import absolute_import, unicode_literals import os -import time import sys import warnings @@ -36,7 +35,6 @@ else: from django.db.models import indexes from django.db.backends.utils import names_digest from django.db import connection - from django.db.utils import OperationalError if HAS_DJANGO is True: @@ -154,19 +152,6 @@ def manage(): # enforce the postgres version is equal to 12. if not, then terminate program with exit code of 1 if not MODE == 'development': - # wait for connection to the database - sys.stdout.write("Wainting for connection to database\n") - connected = False - while not connected: - try: - connection.ensure_connection() - connected = True - except OperationalError: - sys.stdout.write("No connection available\n") - time.sleep(1) - - sys.stdout.write("Connection established\n") - if (connection.pg_version // 10000) < 12: sys.stderr.write("Postgres version 12 is required\n") sys.exit(1) diff --git a/tools/ansible/roles/dockerfile/files/launch_awx.sh b/tools/ansible/roles/dockerfile/files/launch_awx.sh index cd9f573533..ce90142cb4 100755 --- a/tools/ansible/roles/dockerfile/files/launch_awx.sh +++ b/tools/ansible/roles/dockerfile/files/launch_awx.sh @@ -13,6 +13,8 @@ if [ -n "${AWX_KUBE_DEVEL}" ]; then export SDB_NOTIFY_HOST=$MY_POD_IP fi +wait-for-migrations || exit 1 + awx-manage collectstatic --noinput --clear supervisord -c /etc/supervisord.conf diff --git a/tools/ansible/roles/dockerfile/files/launch_awx_task.sh b/tools/ansible/roles/dockerfile/files/launch_awx_task.sh index 7d5ac3265c..2e0d1a9b10 100755 --- a/tools/ansible/roles/dockerfile/files/launch_awx_task.sh +++ b/tools/ansible/roles/dockerfile/files/launch_awx_task.sh @@ -13,6 +13,6 @@ if [ -n "${AWX_KUBE_DEVEL}" ]; then export SDB_NOTIFY_HOST=$MY_POD_IP fi -wait-for-migrations +wait-for-migrations || exit 1 supervisord -c /etc/supervisord_task.conf diff --git a/tools/ansible/roles/dockerfile/files/wait-for-migrations b/tools/ansible/roles/dockerfile/files/wait-for-migrations index aec55fbf46..8557720591 100755 --- a/tools/ansible/roles/dockerfile/files/wait-for-migrations +++ b/tools/ansible/roles/dockerfile/files/wait-for-migrations @@ -22,13 +22,20 @@ wait_for() { local rc=1 local attempt=1 local next_sleep="${MIN_SLEEP}" + local check=1 while true; do log_message "Attempt ${attempt} of ${ATTEMPTS}" timeout "${TIMEOUT}" \ - /bin/bash -c "! awx-manage showmigrations | grep '\[ \]'" &>/dev/null \ - && return || rc=$? + /bin/bash -c "awx-manage check" &>/dev/null + check=$? + + if [ $check -eq 0 ]; then + timeout "${TIMEOUT}" \ + /bin/bash -c "! awx-manage showmigrations | grep '\[ \]'" &>/dev/null \ + && return || rc=$? + fi (( ++attempt > ATTEMPTS )) && break From ca14cbefaf79acc6c7ccdb63e8e9fb6282696cce Mon Sep 17 00:00:00 2001 From: Sarabraj Singh Date: Tue, 15 Jun 2021 13:46:58 +0000 Subject: [PATCH 3/4] Merge pull request #10425 from sarabrajsingh/bugfix/preflight-check-postgres-version-4940 introduced a pre-flight check for postgres 12 From 0aca4d658af70fd718b3aac8fbb654c18d540aa3 Mon Sep 17 00:00:00 2001 From: Shane McDonald Date: Thu, 22 Jul 2021 13:54:31 -0400 Subject: [PATCH 4/4] Bash nitpick --- tools/ansible/roles/dockerfile/files/launch_awx.sh | 4 +++- tools/ansible/roles/dockerfile/files/launch_awx_task.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/ansible/roles/dockerfile/files/launch_awx.sh b/tools/ansible/roles/dockerfile/files/launch_awx.sh index ce90142cb4..ac5a204d65 100755 --- a/tools/ansible/roles/dockerfile/files/launch_awx.sh +++ b/tools/ansible/roles/dockerfile/files/launch_awx.sh @@ -13,7 +13,9 @@ if [ -n "${AWX_KUBE_DEVEL}" ]; then export SDB_NOTIFY_HOST=$MY_POD_IP fi -wait-for-migrations || exit 1 +set -e + +wait-for-migrations awx-manage collectstatic --noinput --clear diff --git a/tools/ansible/roles/dockerfile/files/launch_awx_task.sh b/tools/ansible/roles/dockerfile/files/launch_awx_task.sh index 2e0d1a9b10..ae1a87a6b0 100755 --- a/tools/ansible/roles/dockerfile/files/launch_awx_task.sh +++ b/tools/ansible/roles/dockerfile/files/launch_awx_task.sh @@ -13,6 +13,8 @@ if [ -n "${AWX_KUBE_DEVEL}" ]; then export SDB_NOTIFY_HOST=$MY_POD_IP fi -wait-for-migrations || exit 1 +set -e + +wait-for-migrations supervisord -c /etc/supervisord_task.conf