Migrate to pg_isready

This commit is contained in:
Josh Santos 2024-03-31 21:02:18 -04:00
parent 3f7c82d4fe
commit 6d3a90c7db
No known key found for this signature in database
GPG Key ID: F40E8260EF912E41
6 changed files with 54 additions and 138 deletions

View File

@ -14,22 +14,30 @@ fi
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}}
ODOO_ARGS=()
DB_ARGS=() DB_ARGS=()
function check_config() { function check_config() {
param="$1" param="$1"
value="$2" value="$2"
pg_flag="$3"
if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then
value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g') value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g')
fi; fi;
DB_ARGS+=("--${param}")
ODOO_ARGS+=("--${param}")
ODOO_ARGS+=("${value}")
DB_ARGS+=("${pg_flag}")
DB_ARGS+=("${value}") DB_ARGS+=("${value}")
} }
check_config "db_name" "$NAME" check_config "db_name" "$NAME" "-d"
check_config "db_host" "$HOST" check_config "db_host" "$HOST" "-h"
check_config "db_port" "$PORT" check_config "db_port" "$PORT" "-p"
check_config "db_user" "$USER" check_config "db_user" "$USER" "-U"
check_config "db_password" "$PASSWORD" # check_config "db_password" "$PASSWORD"
case "$1" in case "$1" in
-- | odoo) -- | odoo)
@ -37,13 +45,13 @@ case "$1" in
if [[ "$1" == "scaffold" ]] ; then if [[ "$1" == "scaffold" ]] ; then
exec odoo "$@" exec odoo "$@"
else else
wait-for-psql.py ${DB_ARGS[@]} --timeout=30 pg_isready ${DB_ARGS[@]} --timeout=30
exec odoo "$@" "${DB_ARGS[@]}" exec odoo "$@" "${ODOO_ARGS[@]}"
fi fi
;; ;;
-*) -*)
wait-for-psql.py ${DB_ARGS[@]} --timeout=30 pg_isready ${DB_ARGS[@]} --timeout=30
exec odoo "$@" "${DB_ARGS[@]}" exec odoo "$@" "${ODOO_ARGS[@]}"
;; ;;
*) *)
exec "$@" exec "$@"

View File

@ -1,36 +0,0 @@
#!/usr/bin/env python3
import argparse
import psycopg2
import sys
import time
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--db_host', required=True)
arg_parser.add_argument('--db_port', required=True)
arg_parser.add_argument('--db_user', required=True)
arg_parser.add_argument('--db_name', required=True)
arg_parser.add_argument('--db_password', required=True)
arg_parser.add_argument('--timeout', type=int, default=5)
args = arg_parser.parse_args()
conn = None
start_time = time.time()
error = ''
while (time.time() - start_time) < args.timeout:
try:
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
error = ''
conn.close()
break
except psycopg2.OperationalError as e:
error = e
time.sleep(1)
if error:
print("Database connection failure: %s" % error, file=sys.stderr)
sys.exit(1)

View File

@ -14,22 +14,30 @@ fi
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}}
ODOO_ARGS=()
DB_ARGS=() DB_ARGS=()
function check_config() { function check_config() {
param="$1" param="$1"
value="$2" value="$2"
pg_flag="$3"
if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then
value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g') value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g')
fi; fi;
DB_ARGS+=("--${param}")
ODOO_ARGS+=("--${param}")
ODOO_ARGS+=("${value}")
DB_ARGS+=("${pg_flag}")
DB_ARGS+=("${value}") DB_ARGS+=("${value}")
} }
check_config "db_name" "$NAME" check_config "db_name" "$NAME" "-d"
check_config "db_host" "$HOST" check_config "db_host" "$HOST" "-h"
check_config "db_port" "$PORT" check_config "db_port" "$PORT" "-p"
check_config "db_user" "$USER" check_config "db_user" "$USER" "-U"
check_config "db_password" "$PASSWORD" # check_config "db_password" "$PASSWORD"
case "$1" in case "$1" in
-- | odoo) -- | odoo)
@ -37,13 +45,13 @@ case "$1" in
if [[ "$1" == "scaffold" ]] ; then if [[ "$1" == "scaffold" ]] ; then
exec odoo "$@" exec odoo "$@"
else else
wait-for-psql.py ${DB_ARGS[@]} --timeout=30 pg_isready ${DB_ARGS[@]} --timeout=30
exec odoo "$@" "${DB_ARGS[@]}" exec odoo "$@" "${ODOO_ARGS[@]}"
fi fi
;; ;;
-*) -*)
wait-for-psql.py ${DB_ARGS[@]} --timeout=30 pg_isready ${DB_ARGS[@]} --timeout=30
exec odoo "$@" "${DB_ARGS[@]}" exec odoo "$@" "${ODOO_ARGS[@]}"
;; ;;
*) *)
exec "$@" exec "$@"

View File

@ -1,36 +0,0 @@
#!/usr/bin/env python3
import argparse
import psycopg2
import sys
import time
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--db_host', required=True)
arg_parser.add_argument('--db_port', required=True)
arg_parser.add_argument('--db_user', required=True)
arg_parser.add_argument('--db_name', required=True)
arg_parser.add_argument('--db_password', required=True)
arg_parser.add_argument('--timeout', type=int, default=5)
args = arg_parser.parse_args()
conn = None
start_time = time.time()
error = ''
while (time.time() - start_time) < args.timeout:
try:
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
error = ''
conn.close()
break
except psycopg2.OperationalError as e:
error = e
time.sleep(1)
if error:
print("Database connection failure: %s" % error, file=sys.stderr)
sys.exit(1)

View File

@ -14,22 +14,30 @@ fi
: ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}}
: ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}}
ODOO_ARGS=()
DB_ARGS=() DB_ARGS=()
function check_config() { function check_config() {
param="$1" param="$1"
value="$2" value="$2"
pg_flag="$3"
if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then if grep -q -E "^\s*\b${param}\b\s*=" "$ODOO_RC" ; then
value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g') value=$(grep -E "^\s*\b${param}\b\s*=" "$ODOO_RC" |cut -d " " -f3|sed 's/["\n\r]//g')
fi; fi;
DB_ARGS+=("--${param}")
ODOO_ARGS+=("--${param}")
ODOO_ARGS+=("${value}")
DB_ARGS+=("${pg_flag}")
DB_ARGS+=("${value}") DB_ARGS+=("${value}")
} }
check_config "db_name" "$NAME" check_config "db_name" "$NAME" "-d"
check_config "db_host" "$HOST" check_config "db_host" "$HOST" "-h"
check_config "db_port" "$PORT" check_config "db_port" "$PORT" "-p"
check_config "db_user" "$USER" check_config "db_user" "$USER" "-U"
check_config "db_password" "$PASSWORD" # check_config "db_password" "$PASSWORD"
case "$1" in case "$1" in
-- | odoo) -- | odoo)
@ -37,13 +45,13 @@ case "$1" in
if [[ "$1" == "scaffold" ]] ; then if [[ "$1" == "scaffold" ]] ; then
exec odoo "$@" exec odoo "$@"
else else
wait-for-psql.py ${DB_ARGS[@]} --timeout=30 pg_isready ${DB_ARGS[@]} --timeout=30
exec odoo "$@" "${DB_ARGS[@]}" exec odoo "$@" "${ODOO_ARGS[@]}"
fi fi
;; ;;
-*) -*)
wait-for-psql.py ${DB_ARGS[@]} --timeout=30 pg_isready ${DB_ARGS[@]} --timeout=30
exec odoo "$@" "${DB_ARGS[@]}" exec odoo "$@" "${ODOO_ARGS[@]}"
;; ;;
*) *)
exec "$@" exec "$@"

View File

@ -1,36 +0,0 @@
#!/usr/bin/env python3
import argparse
import psycopg2
import sys
import time
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--db_host', required=True)
arg_parser.add_argument('--db_port', required=True)
arg_parser.add_argument('--db_user', required=True)
arg_parser.add_argument('--db_name', required=True)
arg_parser.add_argument('--db_password', required=True)
arg_parser.add_argument('--timeout', type=int, default=5)
args = arg_parser.parse_args()
conn = None
start_time = time.time()
error = ''
while (time.time() - start_time) < args.timeout:
try:
conn = psycopg2.connect(user=args.db_user, host=args.db_host, port=args.db_port, password=args.db_password, dbname=args.db_name)
error = ''
conn.close()
break
except psycopg2.OperationalError as e:
error = e
time.sleep(1)
if error:
print("Database connection failure: %s" % error, file=sys.stderr)
sys.exit(1)