From 4840ebfe8087cbeabcb3b832fe5e6f43db92a06b Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 24 Dec 2024 01:38:49 +0900 Subject: [PATCH] Added support for PostgreSQL database socket volume --- .../server-pgsql/alpine/docker-entrypoint.sh | 44 +++++++++++++------ .../server-pgsql/centos/docker-entrypoint.sh | 44 +++++++++++++------ .../server-pgsql/ol/docker-entrypoint.sh | 44 +++++++++++++------ .../server-pgsql/rhel/docker-entrypoint.sh | 44 +++++++++++++------ .../server-pgsql/ubuntu/docker-entrypoint.sh | 44 +++++++++++++------ .../alpine/docker-entrypoint.sh | 18 ++++++-- .../centos/docker-entrypoint.sh | 18 ++++++-- .../web-apache-pgsql/ol/docker-entrypoint.sh | 18 ++++++-- .../ubuntu/docker-entrypoint.sh | 18 ++++++-- .../alpine/docker-entrypoint.sh | 18 ++++++-- .../centos/docker-entrypoint.sh | 18 ++++++-- .../web-nginx-pgsql/ol/docker-entrypoint.sh | 18 ++++++-- .../web-nginx-pgsql/rhel/docker-entrypoint.sh | 18 ++++++-- .../ubuntu/docker-entrypoint.sh | 18 ++++++-- compose_databases.yaml | 3 +- compose_zabbix_components.yaml | 11 +++-- docker-compose_v3_alpine_mysql_latest.yaml | 2 +- docker-compose_v3_alpine_mysql_local.yaml | 2 +- docker-compose_v3_alpine_pgsql_latest.yaml | 3 +- docker-compose_v3_alpine_pgsql_local.yaml | 3 +- docker-compose_v3_centos_mysql_latest.yaml | 2 +- docker-compose_v3_centos_mysql_local.yaml | 2 +- docker-compose_v3_centos_pgsql_latest.yaml | 3 +- docker-compose_v3_centos_pgsql_local.yaml | 3 +- docker-compose_v3_ol_mysql_latest.yaml | 2 +- docker-compose_v3_ol_mysql_local.yaml | 2 +- docker-compose_v3_ol_pgsql_latest.yaml | 3 +- docker-compose_v3_ol_pgsql_local.yaml | 3 +- docker-compose_v3_ubuntu_mysql_latest.yaml | 2 +- docker-compose_v3_ubuntu_mysql_local.yaml | 2 +- docker-compose_v3_ubuntu_pgsql_latest.yaml | 3 +- docker-compose_v3_ubuntu_pgsql_local.yaml | 3 +- 32 files changed, 318 insertions(+), 118 deletions(-) diff --git a/Dockerfiles/server-pgsql/alpine/docker-entrypoint.sh b/Dockerfiles/server-pgsql/alpine/docker-entrypoint.sh index 98b7dbf22..9ee5c51a5 100755 --- a/Dockerfiles/server-pgsql/alpine/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/alpine/docker-entrypoint.sh @@ -83,16 +83,20 @@ update_config_var() { echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." fi - # Remove configuration parameter definition in case of unset parameter value + # Remove configuration parameter definition in case of unset or empty parameter value if [ -z "$var_value" ]; then sed -i -e "/^$var_name=/d" "$config_path" echo "removed" return fi - # Remove value from configuration parameter in case of double quoted parameter value - if [ "$var_value" == '""' ]; then - sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi echo "undefined" return fi @@ -154,12 +158,12 @@ file_process_from_env() { # Check prerequisites for PostgreSQL database check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} - : ${DB_SERVER_PORT:="5432"} - DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} @@ -171,12 +175,24 @@ check_variables_postgresql() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect_postgresql() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" - echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" if [ "${DEBUG_MODE,,}" == "true" ]; then @@ -206,8 +222,8 @@ check_db_connect_postgresql() { while true : do - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT @@ -244,7 +260,7 @@ psql_query() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - result=$(psql --no-align --quiet --tuples-only --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); unset PGPASSWORD @@ -284,7 +300,7 @@ exec_sql_file() { fi $command $sql_script | psql --quiet \ - --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + $psql_connect_args \ --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 unset PGPASSWORD @@ -318,7 +334,7 @@ create_db_database_postgresql() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - createdb --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" --username "${DB_SERVER_ROOT_USER}" \ + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" unset PGPASSWORD diff --git a/Dockerfiles/server-pgsql/centos/docker-entrypoint.sh b/Dockerfiles/server-pgsql/centos/docker-entrypoint.sh index 98b7dbf22..9ee5c51a5 100755 --- a/Dockerfiles/server-pgsql/centos/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/centos/docker-entrypoint.sh @@ -83,16 +83,20 @@ update_config_var() { echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." fi - # Remove configuration parameter definition in case of unset parameter value + # Remove configuration parameter definition in case of unset or empty parameter value if [ -z "$var_value" ]; then sed -i -e "/^$var_name=/d" "$config_path" echo "removed" return fi - # Remove value from configuration parameter in case of double quoted parameter value - if [ "$var_value" == '""' ]; then - sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi echo "undefined" return fi @@ -154,12 +158,12 @@ file_process_from_env() { # Check prerequisites for PostgreSQL database check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} - : ${DB_SERVER_PORT:="5432"} - DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} @@ -171,12 +175,24 @@ check_variables_postgresql() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect_postgresql() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" - echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" if [ "${DEBUG_MODE,,}" == "true" ]; then @@ -206,8 +222,8 @@ check_db_connect_postgresql() { while true : do - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT @@ -244,7 +260,7 @@ psql_query() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - result=$(psql --no-align --quiet --tuples-only --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); unset PGPASSWORD @@ -284,7 +300,7 @@ exec_sql_file() { fi $command $sql_script | psql --quiet \ - --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + $psql_connect_args \ --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 unset PGPASSWORD @@ -318,7 +334,7 @@ create_db_database_postgresql() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - createdb --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" --username "${DB_SERVER_ROOT_USER}" \ + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" unset PGPASSWORD diff --git a/Dockerfiles/server-pgsql/ol/docker-entrypoint.sh b/Dockerfiles/server-pgsql/ol/docker-entrypoint.sh index 98b7dbf22..9ee5c51a5 100755 --- a/Dockerfiles/server-pgsql/ol/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/ol/docker-entrypoint.sh @@ -83,16 +83,20 @@ update_config_var() { echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." fi - # Remove configuration parameter definition in case of unset parameter value + # Remove configuration parameter definition in case of unset or empty parameter value if [ -z "$var_value" ]; then sed -i -e "/^$var_name=/d" "$config_path" echo "removed" return fi - # Remove value from configuration parameter in case of double quoted parameter value - if [ "$var_value" == '""' ]; then - sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi echo "undefined" return fi @@ -154,12 +158,12 @@ file_process_from_env() { # Check prerequisites for PostgreSQL database check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} - : ${DB_SERVER_PORT:="5432"} - DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} @@ -171,12 +175,24 @@ check_variables_postgresql() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect_postgresql() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" - echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" if [ "${DEBUG_MODE,,}" == "true" ]; then @@ -206,8 +222,8 @@ check_db_connect_postgresql() { while true : do - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT @@ -244,7 +260,7 @@ psql_query() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - result=$(psql --no-align --quiet --tuples-only --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); unset PGPASSWORD @@ -284,7 +300,7 @@ exec_sql_file() { fi $command $sql_script | psql --quiet \ - --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + $psql_connect_args \ --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 unset PGPASSWORD @@ -318,7 +334,7 @@ create_db_database_postgresql() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - createdb --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" --username "${DB_SERVER_ROOT_USER}" \ + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" unset PGPASSWORD diff --git a/Dockerfiles/server-pgsql/rhel/docker-entrypoint.sh b/Dockerfiles/server-pgsql/rhel/docker-entrypoint.sh index 98b7dbf22..9ee5c51a5 100755 --- a/Dockerfiles/server-pgsql/rhel/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/rhel/docker-entrypoint.sh @@ -83,16 +83,20 @@ update_config_var() { echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." fi - # Remove configuration parameter definition in case of unset parameter value + # Remove configuration parameter definition in case of unset or empty parameter value if [ -z "$var_value" ]; then sed -i -e "/^$var_name=/d" "$config_path" echo "removed" return fi - # Remove value from configuration parameter in case of double quoted parameter value - if [ "$var_value" == '""' ]; then - sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi echo "undefined" return fi @@ -154,12 +158,12 @@ file_process_from_env() { # Check prerequisites for PostgreSQL database check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} - : ${DB_SERVER_PORT:="5432"} - DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} @@ -171,12 +175,24 @@ check_variables_postgresql() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect_postgresql() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" - echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" if [ "${DEBUG_MODE,,}" == "true" ]; then @@ -206,8 +222,8 @@ check_db_connect_postgresql() { while true : do - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT @@ -244,7 +260,7 @@ psql_query() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - result=$(psql --no-align --quiet --tuples-only --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); unset PGPASSWORD @@ -284,7 +300,7 @@ exec_sql_file() { fi $command $sql_script | psql --quiet \ - --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + $psql_connect_args \ --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 unset PGPASSWORD @@ -318,7 +334,7 @@ create_db_database_postgresql() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - createdb --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" --username "${DB_SERVER_ROOT_USER}" \ + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" unset PGPASSWORD diff --git a/Dockerfiles/server-pgsql/ubuntu/docker-entrypoint.sh b/Dockerfiles/server-pgsql/ubuntu/docker-entrypoint.sh index c8fc71688..8038b9f6e 100755 --- a/Dockerfiles/server-pgsql/ubuntu/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/ubuntu/docker-entrypoint.sh @@ -83,16 +83,20 @@ update_config_var() { echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..." fi - # Remove configuration parameter definition in case of unset parameter value + # Remove configuration parameter definition in case of unset or empty parameter value if [ -z "$var_value" ]; then sed -i -e "/^$var_name=/d" "$config_path" echo "removed" return fi - # Remove value from configuration parameter in case of double quoted parameter value - if [ "$var_value" == '""' ]; then - sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + # Remove value from configuration parameter in case of set to double quoted parameter value + if [[ "$var_value" == '""' ]]; then + if [ "$(grep -E "^$var_name=" $config_path)" ]; then + sed -i -e "/^$var_name=/s/=.*/=/" "$config_path" + else + sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=/" "$config_path" + fi echo "undefined" return fi @@ -154,12 +158,12 @@ file_process_from_env() { # Check prerequisites for PostgreSQL database check_variables_postgresql() { + : ${DB_SERVER_HOST="postgres-server"} + : ${DB_SERVER_PORT:="5432"} + file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} - : ${DB_SERVER_PORT:="5432"} - DB_SERVER_ROOT_USER=${POSTGRES_USER:-"postgres"} DB_SERVER_ROOT_PASS=${POSTGRES_PASSWORD:-""} @@ -171,12 +175,24 @@ check_variables_postgresql() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + DB_SERVER_HOST='""' + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect_postgresql() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" - echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + if [[ "$DB_SERVER_HOST" != '""' ]]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" if [ "${DEBUG_MODE,,}" == "true" ]; then @@ -206,8 +222,8 @@ check_db_connect_postgresql() { while true : do - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break - psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --quiet 1>/dev/null 2>&1 && break + psql $psql_connect_args --username ${DB_SERVER_ROOT_USER} --list --dbname ${DB_SERVER_DBNAME} --quiet 1>/dev/null 2>&1 && break echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT @@ -244,7 +260,7 @@ psql_query() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - result=$(psql --no-align --quiet --tuples-only --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + result=$(psql --no-align --quiet --tuples-only $psql_connect_args \ --username "${DB_SERVER_ROOT_USER}" --command "$query" --dbname "$db" 2>/dev/null); unset PGPASSWORD @@ -284,7 +300,7 @@ exec_sql_file() { fi $command $sql_script | psql --quiet \ - --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" \ + $psql_connect_args \ --username "${DB_SERVER_ZBX_USER}" --dbname "${DB_SERVER_DBNAME}" 1>/dev/null || exit 1 unset PGPASSWORD @@ -318,7 +334,7 @@ create_db_database_postgresql() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - createdb --host "${DB_SERVER_HOST}" --port "${DB_SERVER_PORT}" --username "${DB_SERVER_ROOT_USER}" \ + createdb $psql_connect_args --username "${DB_SERVER_ROOT_USER}" \ --owner "${DB_SERVER_ZBX_USER}" --lc-ctype "en_US.utf8" --lc-collate "en_US.utf8" "${DB_SERVER_DBNAME}" unset PGPASSWORD diff --git a/Dockerfiles/web-apache-pgsql/alpine/docker-entrypoint.sh b/Dockerfiles/web-apache-pgsql/alpine/docker-entrypoint.sh index 8cf4118d4..65a4465f1 100755 --- a/Dockerfiles/web-apache-pgsql/alpine/docker-entrypoint.sh +++ b/Dockerfiles/web-apache-pgsql/alpine/docker-entrypoint.sh @@ -62,7 +62,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -73,11 +73,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -106,7 +118,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/Dockerfiles/web-apache-pgsql/centos/docker-entrypoint.sh b/Dockerfiles/web-apache-pgsql/centos/docker-entrypoint.sh index 139d7f130..5a41b6cfe 100755 --- a/Dockerfiles/web-apache-pgsql/centos/docker-entrypoint.sh +++ b/Dockerfiles/web-apache-pgsql/centos/docker-entrypoint.sh @@ -62,7 +62,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -73,11 +73,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -106,7 +118,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/Dockerfiles/web-apache-pgsql/ol/docker-entrypoint.sh b/Dockerfiles/web-apache-pgsql/ol/docker-entrypoint.sh index 139d7f130..5a41b6cfe 100755 --- a/Dockerfiles/web-apache-pgsql/ol/docker-entrypoint.sh +++ b/Dockerfiles/web-apache-pgsql/ol/docker-entrypoint.sh @@ -62,7 +62,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -73,11 +73,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -106,7 +118,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/Dockerfiles/web-apache-pgsql/ubuntu/docker-entrypoint.sh b/Dockerfiles/web-apache-pgsql/ubuntu/docker-entrypoint.sh index 02160b802..da1ef5476 100755 --- a/Dockerfiles/web-apache-pgsql/ubuntu/docker-entrypoint.sh +++ b/Dockerfiles/web-apache-pgsql/ubuntu/docker-entrypoint.sh @@ -64,7 +64,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -75,11 +75,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -108,7 +120,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/Dockerfiles/web-nginx-pgsql/alpine/docker-entrypoint.sh b/Dockerfiles/web-nginx-pgsql/alpine/docker-entrypoint.sh index f885a0ed0..b59efb787 100755 --- a/Dockerfiles/web-nginx-pgsql/alpine/docker-entrypoint.sh +++ b/Dockerfiles/web-nginx-pgsql/alpine/docker-entrypoint.sh @@ -65,7 +65,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -76,11 +76,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -109,7 +121,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/Dockerfiles/web-nginx-pgsql/centos/docker-entrypoint.sh b/Dockerfiles/web-nginx-pgsql/centos/docker-entrypoint.sh index 2b29ef2f0..b8b4efe6b 100755 --- a/Dockerfiles/web-nginx-pgsql/centos/docker-entrypoint.sh +++ b/Dockerfiles/web-nginx-pgsql/centos/docker-entrypoint.sh @@ -65,7 +65,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -76,11 +76,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -109,7 +121,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/Dockerfiles/web-nginx-pgsql/ol/docker-entrypoint.sh b/Dockerfiles/web-nginx-pgsql/ol/docker-entrypoint.sh index 2b29ef2f0..b8b4efe6b 100755 --- a/Dockerfiles/web-nginx-pgsql/ol/docker-entrypoint.sh +++ b/Dockerfiles/web-nginx-pgsql/ol/docker-entrypoint.sh @@ -65,7 +65,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -76,11 +76,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -109,7 +121,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/Dockerfiles/web-nginx-pgsql/rhel/docker-entrypoint.sh b/Dockerfiles/web-nginx-pgsql/rhel/docker-entrypoint.sh index 2b29ef2f0..b8b4efe6b 100755 --- a/Dockerfiles/web-nginx-pgsql/rhel/docker-entrypoint.sh +++ b/Dockerfiles/web-nginx-pgsql/rhel/docker-entrypoint.sh @@ -65,7 +65,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -76,11 +76,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -109,7 +121,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/Dockerfiles/web-nginx-pgsql/ubuntu/docker-entrypoint.sh b/Dockerfiles/web-nginx-pgsql/ubuntu/docker-entrypoint.sh index 0be87cf81..8baffe32c 100755 --- a/Dockerfiles/web-nginx-pgsql/ubuntu/docker-entrypoint.sh +++ b/Dockerfiles/web-nginx-pgsql/ubuntu/docker-entrypoint.sh @@ -65,7 +65,7 @@ check_variables() { file_env POSTGRES_USER file_env POSTGRES_PASSWORD - : ${DB_SERVER_HOST:="postgres-server"} + : ${DB_SERVER_HOST="postgres-server"} : ${DB_SERVER_PORT:="5432"} DB_SERVER_ZBX_USER=${POSTGRES_USER:-"zabbix"} @@ -76,11 +76,23 @@ check_variables() { DB_SERVER_DBNAME=${POSTGRES_DB:-"zabbix"} : ${POSTGRES_USE_IMPLICIT_SEARCH_PATH:="false"} + + if [ -n "${DB_SERVER_HOST}" ]; then + psql_connect_args="--host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT}" + else + psql_connect_args="--port ${DB_SERVER_PORT}" + fi } check_db_connect() { echo "********************" - echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + if [ -n "${DB_SERVER_HOST}" ]; then + echo "* DB_SERVER_HOST: ${DB_SERVER_HOST}" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + else + echo "* DB_SERVER_HOST: Using DB socket" + echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" + fi echo "* DB_SERVER_PORT: ${DB_SERVER_PORT}" echo "* DB_SERVER_DBNAME: ${DB_SERVER_DBNAME}" echo "* DB_SERVER_SCHEMA: ${DB_SERVER_SCHEMA}" @@ -109,7 +121,7 @@ check_db_connect() { export PGSSLKEY=${ZBX_DBTLSKEYFILE} fi - while [ ! "$(psql --host ${DB_SERVER_HOST} --port ${DB_SERVER_PORT} --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do + while [ ! "$(psql $psql_connect_args --username ${DB_SERVER_ZBX_USER} --dbname ${DB_SERVER_DBNAME} --list --quiet 2>/dev/null)" ]; do echo "**** PostgreSQL server is not available. Waiting $WAIT_TIMEOUT seconds..." sleep $WAIT_TIMEOUT done diff --git a/compose_databases.yaml b/compose_databases.yaml index 72c98f0f7..8e392bb6b 100644 --- a/compose_databases.yaml +++ b/compose_databases.yaml @@ -18,7 +18,7 @@ services: volumes: - ${DATA_DIRECTORY}/var/lib/mysql:/var/lib/mysql:rw - ${ENV_VARS_DIRECTORY}/mysql_init/init_proxy_db.sql:/docker-entrypoint-initdb.d/mysql_init_proxy.sql:ro -# - dbsocket:/var/run/mysqld/ +# - mysql_socket:/var/run/mysqld/ env_file: - ${ENV_VARS_DIRECTORY}/.env_db_mysql - path: ${ENV_VARS_DIRECTORY}/.env_db_mysql_override @@ -48,6 +48,7 @@ services: - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CA_FILE:/run/secrets/root-ca.pem:ro - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CERT_FILE:/run/secrets/server-cert.pem:ro - ${ENV_VARS_DIRECTORY}/.ZBX_DB_KEY_FILE:/run/secrets/server-key.pem:ro +# - pgsql_socket:/var/run/postgresql/ env_file: - ${ENV_VARS_DIRECTORY}/.env_db_pgsql - path: ${ENV_VARS_DIRECTORY}/.env_db_pgsql_override diff --git a/compose_zabbix_components.yaml b/compose_zabbix_components.yaml index c52b684ea..efc4d0213 100644 --- a/compose_zabbix_components.yaml +++ b/compose_zabbix_components.yaml @@ -114,7 +114,7 @@ services: extends: service: server # volumes: -# - dbsocket:/var/run/mysqld/ +# - mysql_socket:/var/run/mysqld/ env_file: - ${ENV_VARS_DIRECTORY}/.env_db_mysql secrets: @@ -138,6 +138,7 @@ services: # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CA_FILE:/run/secrets/root-ca.pem:ro # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CERT_FILE:/run/secrets/client-cert.pem:ro # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_KEY_FILE:/run/secrets/client-key.pem:ro +# - pgsql_socket:/var/run/postgresql env_file: - ${ENV_VARS_DIRECTORY}/.env_db_pgsql secrets: @@ -257,7 +258,7 @@ services: protocol: tcp app_protocol: zabbix-trapper # volumes: -# - dbsocket:/var/run/mysqld/ +# - mysql_socket:/var/run/mysqld/ env_file: - ${ENV_VARS_DIRECTORY}/.env_db_mysql_proxy - ${ENV_VARS_DIRECTORY}/.env_prx_mysql @@ -335,7 +336,7 @@ services: extends: service: web-apache # volumes: -# - dbsocket:/var/run/mysqld/ +# - mysql_socket:/var/run/mysqld/ env_file: - ${ENV_VARS_DIRECTORY}/.env_db_mysql secrets: @@ -355,6 +356,7 @@ services: # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CA_FILE:/run/secrets/root-ca.pem:ro # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CERT_FILE:/run/secrets/client-cert.pem:ro # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_KEY_FILE:/run/secrets/client-key.pem:ro +# - pgsql_socket:/var/run/postgresql env_file: - ${ENV_VARS_DIRECTORY}/.env_db_pgsql secrets: @@ -421,7 +423,7 @@ services: extends: service: web-nginx # volumes: -# - dbsocket:/var/run/mysqld/ +# - mysql_socket:/var/run/mysqld/ env_file: - ${ENV_VARS_DIRECTORY}/.env_db_mysql secrets: @@ -445,6 +447,7 @@ services: # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CA_FILE:/run/secrets/root-ca.pem:ro # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_CERT_FILE:/run/secrets/client-cert.pem:ro # - ${ENV_VARS_DIRECTORY}/.ZBX_DB_KEY_FILE:/run/secrets/client-key.pem:ro +# - pgsql_socket:/var/run/postgresql env_file: - ${ENV_VARS_DIRECTORY}/.env_db_pgsql secrets: diff --git a/docker-compose_v3_alpine_mysql_latest.yaml b/docker-compose_v3_alpine_mysql_latest.yaml index 2ba3d7ac2..d2c66565a 100644 --- a/docker-compose_v3_alpine_mysql_latest.yaml +++ b/docker-compose_v3_alpine_mysql_latest.yaml @@ -184,7 +184,7 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_alpine_mysql_local.yaml b/docker-compose_v3_alpine_mysql_local.yaml index af5ebbb19..d8cf78c64 100644 --- a/docker-compose_v3_alpine_mysql_local.yaml +++ b/docker-compose_v3_alpine_mysql_local.yaml @@ -260,7 +260,7 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_alpine_pgsql_latest.yaml b/docker-compose_v3_alpine_pgsql_latest.yaml index 786bec9d3..1c99b8689 100644 --- a/docker-compose_v3_alpine_pgsql_latest.yaml +++ b/docker-compose_v3_alpine_pgsql_latest.yaml @@ -198,7 +198,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_alpine_pgsql_local.yaml b/docker-compose_v3_alpine_pgsql_local.yaml index bae26192f..bdfd2161a 100644 --- a/docker-compose_v3_alpine_pgsql_local.yaml +++ b/docker-compose_v3_alpine_pgsql_local.yaml @@ -288,7 +288,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_centos_mysql_latest.yaml b/docker-compose_v3_centos_mysql_latest.yaml index a975b2752..41666838d 100644 --- a/docker-compose_v3_centos_mysql_latest.yaml +++ b/docker-compose_v3_centos_mysql_latest.yaml @@ -184,7 +184,7 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_centos_mysql_local.yaml b/docker-compose_v3_centos_mysql_local.yaml index ec1dc9323..c8c00e666 100644 --- a/docker-compose_v3_centos_mysql_local.yaml +++ b/docker-compose_v3_centos_mysql_local.yaml @@ -261,7 +261,7 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_centos_pgsql_latest.yaml b/docker-compose_v3_centos_pgsql_latest.yaml index c0cd1b466..82cf867bf 100644 --- a/docker-compose_v3_centos_pgsql_latest.yaml +++ b/docker-compose_v3_centos_pgsql_latest.yaml @@ -198,7 +198,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_centos_pgsql_local.yaml b/docker-compose_v3_centos_pgsql_local.yaml index 65de1734d..b9e768a74 100644 --- a/docker-compose_v3_centos_pgsql_local.yaml +++ b/docker-compose_v3_centos_pgsql_local.yaml @@ -288,7 +288,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_ol_mysql_latest.yaml b/docker-compose_v3_ol_mysql_latest.yaml index e182a552c..51a57ecc1 100644 --- a/docker-compose_v3_ol_mysql_latest.yaml +++ b/docker-compose_v3_ol_mysql_latest.yaml @@ -184,7 +184,7 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_ol_mysql_local.yaml b/docker-compose_v3_ol_mysql_local.yaml index 5c08919a8..eee663d34 100644 --- a/docker-compose_v3_ol_mysql_local.yaml +++ b/docker-compose_v3_ol_mysql_local.yaml @@ -259,7 +259,7 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_ol_pgsql_latest.yaml b/docker-compose_v3_ol_pgsql_latest.yaml index 8bb81706c..a8f17c138 100644 --- a/docker-compose_v3_ol_pgsql_latest.yaml +++ b/docker-compose_v3_ol_pgsql_latest.yaml @@ -198,7 +198,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_ol_pgsql_local.yaml b/docker-compose_v3_ol_pgsql_local.yaml index cd996dec3..dffc42bea 100644 --- a/docker-compose_v3_ol_pgsql_local.yaml +++ b/docker-compose_v3_ol_pgsql_local.yaml @@ -288,7 +288,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_ubuntu_mysql_latest.yaml b/docker-compose_v3_ubuntu_mysql_latest.yaml index 6025d5fd4..106277849 100644 --- a/docker-compose_v3_ubuntu_mysql_latest.yaml +++ b/docker-compose_v3_ubuntu_mysql_latest.yaml @@ -168,7 +168,7 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_ubuntu_mysql_local.yaml b/docker-compose_v3_ubuntu_mysql_local.yaml index d6f58527b..4ccd14239 100644 --- a/docker-compose_v3_ubuntu_mysql_local.yaml +++ b/docker-compose_v3_ubuntu_mysql_local.yaml @@ -247,7 +247,7 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_ubuntu_pgsql_latest.yaml b/docker-compose_v3_ubuntu_pgsql_latest.yaml index d889a1f12..23cc28230 100644 --- a/docker-compose_v3_ubuntu_pgsql_latest.yaml +++ b/docker-compose_v3_ubuntu_pgsql_latest.yaml @@ -182,7 +182,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: diff --git a/docker-compose_v3_ubuntu_pgsql_local.yaml b/docker-compose_v3_ubuntu_pgsql_local.yaml index 67f5aea9a..c6af05cff 100644 --- a/docker-compose_v3_ubuntu_pgsql_local.yaml +++ b/docker-compose_v3_ubuntu_pgsql_local.yaml @@ -276,7 +276,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: