From 8eccc240f99028642962fd0fabe1b764e302c6b2 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 e5ddc9521..53e86df48 100755 --- a/Dockerfiles/server-pgsql/alpine/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/alpine/docker-entrypoint.sh @@ -87,16 +87,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 e5ddc9521..53e86df48 100755 --- a/Dockerfiles/server-pgsql/centos/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/centos/docker-entrypoint.sh @@ -87,16 +87,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 e5ddc9521..53e86df48 100755 --- a/Dockerfiles/server-pgsql/ol/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/ol/docker-entrypoint.sh @@ -87,16 +87,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 ffb308ea8..0a6404960 100755 --- a/Dockerfiles/server-pgsql/rhel/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/rhel/docker-entrypoint.sh @@ -87,16 +87,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 44b02067a..c1fbc536b 100755 --- a/Dockerfiles/server-pgsql/ubuntu/docker-entrypoint.sh +++ b/Dockerfiles/server-pgsql/ubuntu/docker-entrypoint.sh @@ -87,16 +87,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 b7113ab5e..16a58483f 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 2debf7f83..067668da0 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 2debf7f83..067668da0 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 972a6e964..651f2da46 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 14e30e2d9..d2522d255 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 83d922a81..2589f3fc5 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 83d922a81..2589f3fc5 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 83d922a81..2589f3fc5 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 c5448021e..a49a169b8 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 89e598707..c04ec5db3 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 e8201261f..c0ac854ac 100644 --- a/compose_zabbix_components.yaml +++ b/compose_zabbix_components.yaml @@ -64,7 +64,7 @@ services: extends: service: server # volumes: -# - dbsocket:/var/run/mysqld/ +# - mysql_socket:/var/run/mysqld/ env_file: - ${ENV_VARS_DIRECTORY}/.env_db_mysql secrets: @@ -88,6 +88,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: @@ -177,7 +178,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 @@ -255,7 +256,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: @@ -275,6 +276,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: @@ -341,7 +343,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: @@ -365,6 +367,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 a82bdf8be..f2af63f4d 100644 --- a/docker-compose_v3_alpine_mysql_latest.yaml +++ b/docker-compose_v3_alpine_mysql_latest.yaml @@ -134,7 +134,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 369abc67f..28ed7f1b6 100644 --- a/docker-compose_v3_alpine_mysql_local.yaml +++ b/docker-compose_v3_alpine_mysql_local.yaml @@ -234,7 +234,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 5eb428089..01fd6c61d 100644 --- a/docker-compose_v3_alpine_pgsql_latest.yaml +++ b/docker-compose_v3_alpine_pgsql_latest.yaml @@ -148,7 +148,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 6ea20bb18..38fbe269a 100644 --- a/docker-compose_v3_alpine_pgsql_local.yaml +++ b/docker-compose_v3_alpine_pgsql_local.yaml @@ -262,7 +262,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 c758736e0..a431a841d 100644 --- a/docker-compose_v3_centos_mysql_latest.yaml +++ b/docker-compose_v3_centos_mysql_latest.yaml @@ -134,7 +134,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 88acdbd1c..7a68a0136 100644 --- a/docker-compose_v3_centos_mysql_local.yaml +++ b/docker-compose_v3_centos_mysql_local.yaml @@ -235,7 +235,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 4f7d5558a..9079ff419 100644 --- a/docker-compose_v3_centos_pgsql_latest.yaml +++ b/docker-compose_v3_centos_pgsql_latest.yaml @@ -148,7 +148,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 85fbdc0ce..db3d4b21b 100644 --- a/docker-compose_v3_centos_pgsql_local.yaml +++ b/docker-compose_v3_centos_pgsql_local.yaml @@ -262,7 +262,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 cdd44716d..cd5e6e345 100644 --- a/docker-compose_v3_ol_mysql_latest.yaml +++ b/docker-compose_v3_ol_mysql_latest.yaml @@ -134,7 +134,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 acfa90816..4ca8aa2ec 100644 --- a/docker-compose_v3_ol_mysql_local.yaml +++ b/docker-compose_v3_ol_mysql_local.yaml @@ -235,7 +235,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 acd7d19c8..60e8aee18 100644 --- a/docker-compose_v3_ol_pgsql_latest.yaml +++ b/docker-compose_v3_ol_pgsql_latest.yaml @@ -148,7 +148,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 0ebaaffa8..f2c80f038 100644 --- a/docker-compose_v3_ol_pgsql_local.yaml +++ b/docker-compose_v3_ol_pgsql_local.yaml @@ -262,7 +262,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 eff036a77..34df67ce2 100644 --- a/docker-compose_v3_ubuntu_mysql_latest.yaml +++ b/docker-compose_v3_ubuntu_mysql_latest.yaml @@ -122,7 +122,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 d2cd08d50..6a89260b3 100644 --- a/docker-compose_v3_ubuntu_mysql_local.yaml +++ b/docker-compose_v3_ubuntu_mysql_local.yaml @@ -223,7 +223,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 e1fca332c..f0e5bc508 100644 --- a/docker-compose_v3_ubuntu_pgsql_latest.yaml +++ b/docker-compose_v3_ubuntu_pgsql_latest.yaml @@ -136,7 +136,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 c85f22285..8044c8d4b 100644 --- a/docker-compose_v3_ubuntu_pgsql_local.yaml +++ b/docker-compose_v3_ubuntu_pgsql_local.yaml @@ -250,7 +250,8 @@ networks: volumes: snmptraps: -# dbsocket: +# mysql_socket: +# pgsql_socket: secrets: MYSQL_USER: