diff --git a/15.0/entrypoint.sh b/15.0/entrypoint.sh index f802bcb25..1687af2f8 100755 --- a/15.0/entrypoint.sh +++ b/15.0/entrypoint.sh @@ -13,19 +13,31 @@ fi : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} -DB_ARGS=() +ODOO_ARGS=() +DB_ARGS=("-d" "postgres") + function check_config() { param="$1" value="$2" + pg_flag="$3" + 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') fi; - DB_ARGS+=("--${param}") - DB_ARGS+=("${value}") + + ODOO_ARGS+=("--${param}") + ODOO_ARGS+=("${value}") + + # Only add to DB_ARGS if pg_flag is set + if [[ -n "$pg_flag" ]]; then + DB_ARGS+=("${pg_flag}") + DB_ARGS+=("${value}") + fi } -check_config "db_host" "$HOST" -check_config "db_port" "$PORT" -check_config "db_user" "$USER" + +check_config "db_host" "$HOST" "-h" +check_config "db_port" "$PORT" "-p" +check_config "db_user" "$USER" "-U" check_config "db_password" "$PASSWORD" case "$1" in @@ -34,13 +46,13 @@ case "$1" in if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" fi ;; -*) - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" ;; *) exec "$@" diff --git a/15.0/wait-for-psql.py b/15.0/wait-for-psql.py deleted file mode 100755 index a55f44098..000000000 --- a/15.0/wait-for-psql.py +++ /dev/null @@ -1,32 +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_password', required=True) - arg_parser.add_argument('--timeout', type=int, default=5) - - args = arg_parser.parse_args() - - start_time = time.time() - 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='postgres') - error = '' - break - except psycopg2.OperationalError as e: - error = e - else: - conn.close() - time.sleep(1) - - if error: - print("Database connection failure: %s" % error, file=sys.stderr) - sys.exit(1) diff --git a/16.0/entrypoint.sh b/16.0/entrypoint.sh index f802bcb25..1687af2f8 100755 --- a/16.0/entrypoint.sh +++ b/16.0/entrypoint.sh @@ -13,19 +13,31 @@ fi : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} -DB_ARGS=() +ODOO_ARGS=() +DB_ARGS=("-d" "postgres") + function check_config() { param="$1" value="$2" + pg_flag="$3" + 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') fi; - DB_ARGS+=("--${param}") - DB_ARGS+=("${value}") + + ODOO_ARGS+=("--${param}") + ODOO_ARGS+=("${value}") + + # Only add to DB_ARGS if pg_flag is set + if [[ -n "$pg_flag" ]]; then + DB_ARGS+=("${pg_flag}") + DB_ARGS+=("${value}") + fi } -check_config "db_host" "$HOST" -check_config "db_port" "$PORT" -check_config "db_user" "$USER" + +check_config "db_host" "$HOST" "-h" +check_config "db_port" "$PORT" "-p" +check_config "db_user" "$USER" "-U" check_config "db_password" "$PASSWORD" case "$1" in @@ -34,13 +46,13 @@ case "$1" in if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" fi ;; -*) - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" ;; *) exec "$@" diff --git a/16.0/wait-for-psql.py b/16.0/wait-for-psql.py deleted file mode 100755 index a55f44098..000000000 --- a/16.0/wait-for-psql.py +++ /dev/null @@ -1,32 +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_password', required=True) - arg_parser.add_argument('--timeout', type=int, default=5) - - args = arg_parser.parse_args() - - start_time = time.time() - 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='postgres') - error = '' - break - except psycopg2.OperationalError as e: - error = e - else: - conn.close() - time.sleep(1) - - if error: - print("Database connection failure: %s" % error, file=sys.stderr) - sys.exit(1) diff --git a/17.0/entrypoint.sh b/17.0/entrypoint.sh index f802bcb25..1687af2f8 100755 --- a/17.0/entrypoint.sh +++ b/17.0/entrypoint.sh @@ -13,19 +13,31 @@ fi : ${USER:=${DB_ENV_POSTGRES_USER:=${POSTGRES_USER:='odoo'}}} : ${PASSWORD:=${DB_ENV_POSTGRES_PASSWORD:=${POSTGRES_PASSWORD:='odoo'}}} -DB_ARGS=() +ODOO_ARGS=() +DB_ARGS=("-d" "postgres") + function check_config() { param="$1" value="$2" + pg_flag="$3" + 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') fi; - DB_ARGS+=("--${param}") - DB_ARGS+=("${value}") + + ODOO_ARGS+=("--${param}") + ODOO_ARGS+=("${value}") + + # Only add to DB_ARGS if pg_flag is set + if [[ -n "$pg_flag" ]]; then + DB_ARGS+=("${pg_flag}") + DB_ARGS+=("${value}") + fi } -check_config "db_host" "$HOST" -check_config "db_port" "$PORT" -check_config "db_user" "$USER" + +check_config "db_host" "$HOST" "-h" +check_config "db_port" "$PORT" "-p" +check_config "db_user" "$USER" "-U" check_config "db_password" "$PASSWORD" case "$1" in @@ -34,13 +46,13 @@ case "$1" in if [[ "$1" == "scaffold" ]] ; then exec odoo "$@" else - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" fi ;; -*) - wait-for-psql.py ${DB_ARGS[@]} --timeout=30 - exec odoo "$@" "${DB_ARGS[@]}" + pg_isready ${DB_ARGS[@]} --timeout=30 + exec odoo "$@" "${ODOO_ARGS[@]}" ;; *) exec "$@" diff --git a/17.0/wait-for-psql.py b/17.0/wait-for-psql.py deleted file mode 100755 index a55f44098..000000000 --- a/17.0/wait-for-psql.py +++ /dev/null @@ -1,32 +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_password', required=True) - arg_parser.add_argument('--timeout', type=int, default=5) - - args = arg_parser.parse_args() - - start_time = time.time() - 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='postgres') - error = '' - break - except psycopg2.OperationalError as e: - error = e - else: - conn.close() - time.sleep(1) - - if error: - print("Database connection failure: %s" % error, file=sys.stderr) - sys.exit(1)