diff --git a/bitnami/postgresql-repmgr/10/debian-10/Dockerfile b/bitnami/postgresql-repmgr/10/debian-10/Dockerfile index d9a7d59facaf..d045662757c3 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/Dockerfile +++ b/bitnami/postgresql-repmgr/10/debian-10/Dockerfile @@ -22,7 +22,7 @@ RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen COPY rootfs / RUN /opt/bitnami/scripts/postgresql-repmgr/postunpack.sh ENV BITNAMI_APP_NAME="postgresql-repmgr" \ - BITNAMI_IMAGE_VERSION="10.13.0-debian-10-r35" \ + BITNAMI_IMAGE_VERSION="10.13.0-debian-10-r36" \ LANG="en_US.UTF-8" \ LANGUAGE="en_US:en" \ NSS_WRAPPER_LIB="/opt/bitnami/common/lib/libnss_wrapper.so" \ diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/anotate_event_processing.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/anotate_event_processing.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/lock_primary.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/lock_primary.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/lock_standby.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/lock_standby.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/unlock_primary.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/unlock_primary.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/unlock_standby.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/includes/unlock_standby.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/primary_register.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/primary_register.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/repmgrd_failover_follow.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/repmgrd_failover_follow.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/standby_follow.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/standby_follow.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/standby_promote.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/execs/standby_promote.sh old mode 100644 new mode 100755 diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/router.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/router.sh old mode 100644 new mode 100755 index 1471149bdb46..2c437d467db4 --- a/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/router.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/rootfs/events/router.sh @@ -11,8 +11,7 @@ set -o pipefail . /opt/bitnami/scripts/librepmgr.sh . /opt/bitnami/scripts/libpostgresql.sh -eval "$(repmgr_env)" -eval "$(postgresql_env)" +. /opt/bitnami/scripts/postgresql-env.sh echo "[REPMGR EVENT] Node id: $1; Event type: $2; Success [1|0]: $3; Time: $4; Details: $5" event_script="$REPMGR_EVENTS_DIR/execs/$2.sh" diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/libpostgresql.sh index cdc9b027a9e5..444b8c52dfeb 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -3,6 +3,7 @@ # Bitnami PostgreSQL library # shellcheck disable=SC1091 +# shellcheck disable=SC1090 # Load Generic Libraries . /opt/bitnami/scripts/libfile.sh @@ -12,23 +13,6 @@ . /opt/bitnami/scripts/libservice.sh . /opt/bitnami/scripts/libvalidations.sh - -######################## -# Overwrite info, debug, warn and error functions (liblog.sh) -######################## -postgresql_info() { - MODULE=postgresql info "${*}" -} -postgresql_debug() { - MODULE=postgresql debug "${*}" -} -postgresql_warn() { - MODULE=postgresql warn "${*}" -} -postgresql_error() { - MODULE=postgresql error "${*}" -} - ######################## # Configure libnss_wrapper so PostgreSQL commands work with a random user. # Globals: @@ -40,7 +24,7 @@ postgresql_error() { ######################### postgresql_enable_nss_wrapper() { if ! getent passwd "$(id -u)" &> /dev/null && [ -e "$NSS_WRAPPER_LIB" ]; then - postgresql_debug "Configuring libnss_wrapper..." + debug "Configuring libnss_wrapper..." export LD_PRELOAD="$NSS_WRAPPER_LIB" # shellcheck disable=SC2155 export NSS_WRAPPER_PASSWD="$(mktemp)" @@ -51,162 +35,6 @@ postgresql_enable_nss_wrapper() { fi } -######################## -# Load global variables used on PostgreSQL configuration. -# Globals: -# POSTGRESQL_* -# Arguments: -# None -# Returns: -# Series of exports to be used as 'eval' arguments -######################### -postgresql_env() { - declare_env_alias() { - local -r alias="${1:?missing environment variable alias}" - local -r original="${2:?missing original environment variable}" - - if printenv "${original}" > /dev/null; then - cat << EOF -export "${alias}"="\${${original}:-}" -EOF - fi - } - - # Alias created for official PostgreSQL image compatibility - [[ -z "${POSTGRESQL_DATABASE:-}" ]] && declare_env_alias POSTGRESQL_DATABASE POSTGRES_DB - [[ -z "${POSTGRESQL_USERNAME:-}" ]] && declare_env_alias POSTGRESQL_USERNAME POSTGRES_USER - [[ -z "${POSTGRESQL_DATA_DIR:-}" ]] && declare_env_alias POSTGRESQL_DATA_DIR PGDATA - - local -r suffixes=( - "PASSWORD" "POSTGRES_PASSWORD" "INITDB_WAL_DIR" "INITDB_ARGS" "CLUSTER_APP_NAME" - "MASTER_HOST" "MASTER_PORT_NUMBER" "NUM_SYNCHRONOUS_REPLICAS" - "PORT_NUMBER" "REPLICATION_MODE" "REPLICATION_PASSWORD" "REPLICATION_USER" "FSYNC" - "SYNCHRONOUS_COMMIT_MODE" "PASSWORD_FILE" "POSTGRES_PASSWORD_FILE" - "REPLICATION_PASSWORD_FILE" "INIT_MAX_TIMEOUT" - ) - for s in "${suffixes[@]}"; do - declare_env_alias "POSTGRESQL_${s}" "POSTGRES_${s}" - done - - # Ensure the image is compatible with Helm chart 3.x.x series - local -r postgresql_data="${POSTGRESQL_DATA_DIR:-${PGDATA:-}}" - if [[ -n "${postgresql_data:-}" ]]; then - if [[ -d "${postgresql_data}/data" ]] || [[ "${postgresql_data}" = "/bitnami/postgresql" ]]; then - postgresql_warn "Data directory is set with a legacy value, adapting POSTGRESQL_DATA_DIR..." - postgresql_warn "POSTGRESQL_DATA_DIR set to \"${postgresql_data}/data\"!!" - cat << EOF -export POSTGRESQL_DATA_DIR="${postgresql_data}/data" -EOF - fi - fi - - cat <<"EOF" -# Paths -export POSTGRESQL_VOLUME_DIR="${POSTGRESQL_VOLUME_DIR:-/bitnami/postgresql}" -export POSTGRESQL_DATA_DIR="${POSTGRESQL_DATA_DIR:-$POSTGRESQL_VOLUME_DIR/data}" -export POSTGRESQL_BASE_DIR="/opt/bitnami/postgresql" -export POSTGRESQL_CONF_DIR="$POSTGRESQL_BASE_DIR/conf" -export POSTGRESQL_MOUNTED_CONF_DIR="/bitnami/postgresql/conf" -export POSTGRESQL_CONF_FILE="$POSTGRESQL_CONF_DIR/postgresql.conf" -export POSTGRESQL_PGHBA_FILE="$POSTGRESQL_CONF_DIR/pg_hba.conf" -export POSTGRESQL_RECOVERY_FILE="$POSTGRESQL_DATA_DIR/recovery.conf" -export POSTGRESQL_LOG_DIR="$POSTGRESQL_BASE_DIR/logs" -export POSTGRESQL_LOG_FILE="$POSTGRESQL_LOG_DIR/postgresql.log" -export POSTGRESQL_TMP_DIR="$POSTGRESQL_BASE_DIR/tmp" -export POSTGRESQL_PID_FILE="$POSTGRESQL_TMP_DIR/postgresql.pid" -export POSTGRESQL_BIN_DIR="$POSTGRESQL_BASE_DIR/bin" -export POSTGRESQL_INITSCRIPTS_DIR=/docker-entrypoint-initdb.d -export POSTGRESQL_PREINITSCRIPTS_DIR=/docker-entrypoint-preinitdb.d -export PATH="$POSTGRESQL_BIN_DIR:$PATH" - -# Users -export POSTGRESQL_DAEMON_USER="postgresql" -export POSTGRESQL_DAEMON_GROUP="postgresql" - -# Version -export POSTGRESQL_VERSION="$(echo "$BITNAMI_IMAGE_VERSION" | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+")" -export POSTGRESQL_MAJOR_VERSION="$(echo "$BITNAMI_IMAGE_VERSION" | grep -oE "^[0-9]+")" - -# Settings -export POSTGRESQL_INIT_MAX_TIMEOUT=${POSTGRESQL_INIT_MAX_TIMEOUT:-60} -export POSTGRESQL_CLUSTER_APP_NAME=${POSTGRESQL_CLUSTER_APP_NAME:-walreceiver} -export POSTGRESQL_DATABASE="${POSTGRESQL_DATABASE:-postgres}" -export POSTGRESQL_INITDB_ARGS="${POSTGRESQL_INITDB_ARGS:-}" -export ALLOW_EMPTY_PASSWORD="${ALLOW_EMPTY_PASSWORD:-no}" -export POSTGRESQL_INITDB_WAL_DIR="${POSTGRESQL_INITDB_WAL_DIR:-}" -export POSTGRESQL_MASTER_HOST="${POSTGRESQL_MASTER_HOST:-}" -export POSTGRESQL_MASTER_PORT_NUMBER="${POSTGRESQL_MASTER_PORT_NUMBER:-5432}" -export POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS="${POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS:-0}" -export POSTGRESQL_PORT_NUMBER="${POSTGRESQL_PORT_NUMBER:-5432}" -export POSTGRESQL_REPLICATION_MODE="${POSTGRESQL_REPLICATION_MODE:-master}" -export POSTGRESQL_REPLICATION_USER="${POSTGRESQL_REPLICATION_USER:-}" -export POSTGRESQL_SYNCHRONOUS_COMMIT_MODE="${POSTGRESQL_SYNCHRONOUS_COMMIT_MODE:-on}" -export POSTGRESQL_FSYNC="${POSTGRESQL_FSYNC:-on}" -export POSTGRESQL_USERNAME="${POSTGRESQL_USERNAME:-postgres}" -export POSTGRESQL_ENABLE_LDAP="${POSTGRESQL_ENABLE_LDAP:-no}" -export POSTGRESQL_LDAP_URL="${POSTGRESQL_LDAP_URL:-}" -export POSTGRESQL_LDAP_PREFIX="${POSTGRESQL_LDAP_PREFIX:-}" -export POSTGRESQL_LDAP_SUFFIX="${POSTGRESQL_LDAP_SUFFIX:-}" -export POSTGRESQL_LDAP_SERVER="${POSTGRESQL_LDAP_SERVER:-}" -export POSTGRESQL_LDAP_PORT="${POSTGRESQL_LDAP_PORT:-}" -export POSTGRESQL_LDAP_SCHEME="${POSTGRESQL_LDAP_SCHEME:-}" -export POSTGRESQL_LDAP_TLS="${POSTGRESQL_LDAP_TLS:-}" -export POSTGRESQL_LDAP_BASE_DN="${POSTGRESQL_LDAP_BASE_DN:-}" -export POSTGRESQL_LDAP_BIND_DN="${POSTGRESQL_LDAP_BIND_DN:-}" -export POSTGRESQL_LDAP_BIND_PASSWORD="${POSTGRESQL_LDAP_BIND_PASSWORD:-}" -export POSTGRESQL_LDAP_SEARCH_ATTR="${POSTGRESQL_LDAP_SEARCH_ATTR:-}" -export POSTGRESQL_LDAP_SEARCH_FILTER="${POSTGRESQL_LDAP_SEARCH_FILTER:-}" - -# Internal -export POSTGRESQL_FIRST_BOOT="yes" -EOF - if [[ -z "${POSTGRESQL_INITSCRIPTS_USERNAME:-}" ]]; then - cat <<"EOF" -export POSTGRESQL_INITSCRIPTS_USERNAME="${POSTGRESQL_USERNAME}" -EOF - else - cat <<"EOF" -export POSTGRESQL_INITSCRIPTS_USERNAME="${POSTGRESQL_INITSCRIPTS_USERNAME}" -EOF - fi - if [[ -f "${POSTGRESQL_PASSWORD_FILE:-}" ]]; then - cat <<"EOF" -export POSTGRESQL_PASSWORD="$(< "${POSTGRESQL_PASSWORD_FILE}")" -EOF - else - cat <<"EOF" -export POSTGRESQL_PASSWORD="${POSTGRESQL_PASSWORD:-}" -EOF - fi - if [[ -f "${POSTGRESQL_REPLICATION_PASSWORD_FILE:-}" ]]; then - cat <<"EOF" -export POSTGRESQL_REPLICATION_PASSWORD="$(< "${POSTGRESQL_REPLICATION_PASSWORD_FILE}")" -EOF - else - cat <<"EOF" -export POSTGRESQL_REPLICATION_PASSWORD="${POSTGRESQL_REPLICATION_PASSWORD:-}" -EOF - fi - if [[ -f "${POSTGRESQL_POSTGRES_PASSWORD_FILE:-}" ]]; then - cat <<"EOF" -export POSTGRESQL_POSTGRES_PASSWORD="$(< "${POSTGRESQL_POSTGRES_PASSWORD_FILE}")" -EOF - else - cat <<"EOF" -export POSTGRESQL_POSTGRES_PASSWORD="${POSTGRESQL_POSTGRES_PASSWORD:-}" -EOF - fi - if [[ -z "${POSTGRESQL_INITSCRIPTS_PASSWORD:-}" ]]; then - cat <<"EOF" -export POSTGRESQL_INITSCRIPTS_PASSWORD="${POSTGRESQL_PASSWORD:-}" -EOF - else - cat <<"EOF" -export POSTGRESQL_INITSCRIPTS_PASSWORD="${POSTGRESQL_INITSCRIPTS_PASSWORD:-}" -EOF - fi -} - ######################## # Validate settings in POSTGRESQL_* environment variables # Globals: @@ -217,17 +45,17 @@ EOF # None ######################### postgresql_validate() { - postgresql_info "Validating settings in POSTGRESQL_* env vars.." + info "Validating settings in POSTGRESQL_* env vars.." local error_code=0 # Auxiliary functions print_validation_error() { - postgresql_error "$1" + error "$1" error_code=1 } empty_password_enabled_warn() { - postgresql_warn "You set the environment variable ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD}. For safety reasons, do not use this flag in a production environment." + warn "You set the environment variable ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD}. For safety reasons, do not use this flag in a production environment." } empty_password_error() { print_validation_error "The $1 environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development." @@ -301,12 +129,12 @@ postgresql_validate() { # None ######################### postgresql_create_config() { - postgresql_info "postgresql.conf file not detected. Generating it..." + info "postgresql.conf file not detected. Generating it..." cp "$POSTGRESQL_BASE_DIR/share/postgresql.conf.sample" "$POSTGRESQL_CONF_FILE" # Update default value for 'include_dir' directive # ref: https://github.com/postgres/postgres/commit/fb9c475597c245562a28d1e916b575ac4ec5c19f#diff-f5544d9b6d218cc9677524b454b41c60 if ! grep include_dir "$POSTGRESQL_CONF_FILE" > /dev/null; then - postgresql_error "include_dir line is not present in $POSTGRESQL_CONF_FILE. This may be due to a changes in a new version of PostgreSQL. Please check" + error "include_dir line is not present in $POSTGRESQL_CONF_FILE. This may be due to a changes in a new version of PostgreSQL. Please check" exit 1 fi local psql_conf @@ -325,7 +153,7 @@ postgresql_create_config() { # None ######################### postgresql_ldap_auth_configuration() { - postgresql_info "Generating LDAP authentication configuration" + info "Generating LDAP authentication configuration" local ldap_configuration="" if [[ -n "$POSTGRESQL_LDAP_URL" ]]; then @@ -363,7 +191,7 @@ EOF # None ######################### postgresql_password_auth_configuration() { - postgresql_info "Generating local authentication configuration" + info "Generating local authentication configuration" cat << EOF > "$POSTGRESQL_PGHBA_FILE" host all all 0.0.0.0/0 trust host all all ::/0 trust @@ -380,7 +208,7 @@ EOF # None ######################### postgresql_create_pghba() { - postgresql_info "pg_hba.conf file not detected. Generating it..." + info "pg_hba.conf file not detected. Generating it..." if is_boolean_yes "$POSTGRESQL_ENABLE_LDAP"; then postgresql_ldap_auth_configuration @@ -401,6 +229,8 @@ postgresql_create_pghba() { postgresql_allow_local_connection() { cat << EOF >> "$POSTGRESQL_PGHBA_FILE" local all all trust +host all all 127.0.0.1/0 trust +host all all ::1/128 trust EOF } @@ -470,7 +300,7 @@ postgresql_set_property() { ######################### postgresql_create_replication_user() { local -r escaped_password="${POSTGRESQL_REPLICATION_PASSWORD//\'/\'\'}" - postgresql_info "Creating replication user $POSTGRESQL_REPLICATION_USER" + info "Creating replication user $POSTGRESQL_REPLICATION_USER" echo "CREATE ROLE \"$POSTGRESQL_REPLICATION_USER\" REPLICATION LOGIN ENCRYPTED PASSWORD '$escaped_password'" | postgresql_execute } @@ -484,7 +314,7 @@ postgresql_create_replication_user() { # None ######################### postgresql_configure_replication_parameters() { - postgresql_info "Configuring replication parameters" + info "Configuring replication parameters" postgresql_set_property "wal_level" "hot_standby" postgresql_set_property "max_wal_size" "400MB" postgresql_set_property "max_wal_senders" "16" @@ -506,7 +336,7 @@ postgresql_configure_replication_parameters() { # None ######################### postgresql_configure_fsync() { - postgresql_info "Configuring fsync" + info "Configuring fsync" postgresql_set_property "fsync" "$POSTGRESQL_FSYNC" } @@ -521,7 +351,7 @@ postgresql_configure_fsync() { ######################### postgresql_alter_postgres_user() { local -r escaped_password="${1//\'/\'\'}" - postgresql_info "Changing password of postgres" + info "Changing password of postgres" echo "ALTER ROLE postgres WITH PASSWORD '$escaped_password';" | postgresql_execute } @@ -536,9 +366,9 @@ postgresql_alter_postgres_user() { ######################### postgresql_create_admin_user() { local -r escaped_password="${POSTGRESQL_PASSWORD//\'/\'\'}" - postgresql_info "Creating user ${POSTGRESQL_USERNAME}" + info "Creating user ${POSTGRESQL_USERNAME}" echo "CREATE ROLE \"${POSTGRESQL_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute - postgresql_info "Granting access to \"${POSTGRESQL_USERNAME}\" to the database \"${POSTGRESQL_DATABASE}\"" + info "Granting access to \"${POSTGRESQL_USERNAME}\" to the database \"${POSTGRESQL_DATABASE}\"" echo "GRANT ALL PRIVILEGES ON DATABASE \"${POSTGRESQL_DATABASE}\" TO \"${POSTGRESQL_USERNAME}\"\;" | postgresql_execute "" "postgres" "$POSTGRESQL_PASSWORD" } @@ -602,7 +432,7 @@ postgresql_clean_from_restart() { for file in "${files[@]}"; do if [[ -f "$file" ]]; then - postgresql_info "Cleaning stale $file file" + info "Cleaning stale $file file" rm "$file" fi done @@ -618,7 +448,7 @@ postgresql_clean_from_restart() { # None ######################### postgresql_initialize() { - postgresql_info "Initializing PostgreSQL database..." + info "Initializing PostgreSQL database..." postgresql_clean_from_restart # This fixes an issue where the trap would kill the entrypoint.sh, if a PID was left over from a previous run @@ -627,36 +457,35 @@ postgresql_initialize() { # User injected custom configuration if [[ -d "$POSTGRESQL_MOUNTED_CONF_DIR" ]] && compgen -G "$POSTGRESQL_MOUNTED_CONF_DIR"/* > /dev/null; then - postgresql_debug "Copying files from $POSTGRESQL_MOUNTED_CONF_DIR to $POSTGRESQL_CONF_DIR" + debug "Copying files from $POSTGRESQL_MOUNTED_CONF_DIR to $POSTGRESQL_CONF_DIR" cp -fr "$POSTGRESQL_MOUNTED_CONF_DIR"/. "$POSTGRESQL_CONF_DIR" fi local create_conf_file=yes local create_pghba_file=yes if postgresql_is_file_external "postgresql.conf"; then - postgresql_info "Custom configuration $POSTGRESQL_CONF_FILE detected" + info "Custom configuration $POSTGRESQL_CONF_FILE detected" create_conf_file=no fi if postgresql_is_file_external "pg_hba.conf"; then - postgresql_info "Custom configuration $POSTGRESQL_PGHBA_FILE detected" + info "Custom configuration $POSTGRESQL_PGHBA_FILE detected" create_pghba_file=no fi - postgresql_debug "Ensuring expected directories/files exist..." + debug "Ensuring expected directories/files exist..." for dir in "$POSTGRESQL_TMP_DIR" "$POSTGRESQL_LOG_DIR" "$POSTGRESQL_DATA_DIR"; do ensure_dir_exists "$dir" am_i_root && chown "$POSTGRESQL_DAEMON_USER:$POSTGRESQL_DAEMON_GROUP" "$dir" done am_i_root && find "$POSTGRESQL_DATA_DIR" -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" -exec chown -R "$POSTGRESQL_DAEMON_USER:$POSTGRESQL_DAEMON_GROUP" {} \; - chmod u+rwx "$POSTGRESQL_DATA_DIR" || postgresql_warn "Lack of permissions on data directory!" - chmod go-rwx "$POSTGRESQL_DATA_DIR" || postgresql_warn "Lack of permissions on data directory!" + chmod u+rwx "$POSTGRESQL_DATA_DIR" || warn "Lack of permissions on data directory!" + chmod go-rwx "$POSTGRESQL_DATA_DIR" || warn "Lack of permissions on data directory!" - is_boolean_yes "$create_conf_file" && postgresql_create_config - is_boolean_yes "$create_pghba_file" && postgresql_create_pghba && postgresql_allow_local_connection + is_boolean_yes "$POSTGRESQL_ALLOW_REMOTE_CONNECTIONS" && is_boolean_yes "$create_pghba_file" && postgresql_create_pghba && postgresql_allow_local_connection if ! is_dir_empty "$POSTGRESQL_DATA_DIR"; then - postgresql_info "Deploying PostgreSQL with persisted data..." + info "Deploying PostgreSQL with persisted data..." export POSTGRESQL_FIRST_BOOT="no" is_boolean_yes "$create_pghba_file" && postgresql_restrict_pghba is_boolean_yes "$create_conf_file" && postgresql_configure_replication_parameters @@ -705,7 +534,7 @@ postgresql_initialize() { ######################### postgresql_custom_pre_init_scripts() { info "Loading custom pre-init scripts..." - if [[ -n $(find "$POSTGRESQL_PREINITSCRIPTS_DIR/" -type f -name "*.sh") ]]; then + if [[ -d "$POSTGRESQL_PREINITSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_PREINITSCRIPTS_DIR/" -type f -name "*.sh") ]]; then info "Loading user's custom files from $POSTGRESQL_PREINITSCRIPTS_DIR ..."; find "$POSTGRESQL_PREINITSCRIPTS_DIR/" -type f -name "*.sh" | sort | while read -r f; do if [[ -x "$f" ]]; then @@ -727,22 +556,22 @@ postgresql_custom_pre_init_scripts() { # None ######################### postgresql_custom_init_scripts() { - postgresql_info "Loading custom scripts..." - if [[ -n $(find "$POSTGRESQL_INITSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] && [[ ! -f "$POSTGRESQL_VOLUME_DIR/.user_scripts_initialized" ]] ; then - postgresql_info "Loading user's custom files from $POSTGRESQL_INITSCRIPTS_DIR ..."; + info "Loading custom scripts..." + if [[ -d "$POSTGRESQL_INITSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_INITSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] && [[ ! -f "$POSTGRESQL_VOLUME_DIR/.user_scripts_initialized" ]] ; then + info "Loading user's custom files from $POSTGRESQL_INITSCRIPTS_DIR ..."; postgresql_start_bg find "$POSTGRESQL_INITSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)" | sort | while read -r f; do case "$f" in *.sh) if [[ -x "$f" ]]; then - postgresql_debug "Executing $f"; "$f" + debug "Executing $f"; "$f" else - postgresql_debug "Sourcing $f"; . "$f" + debug "Sourcing $f"; . "$f" fi ;; - *.sql) postgresql_debug "Executing $f"; postgresql_execute "$POSTGRESQL_DATABASE" "$POSTGRESQL_INITSCRIPTS_USERNAME" "$POSTGRESQL_INITSCRIPTS_PASSWORD" < "$f";; - *.sql.gz) postgresql_debug "Executing $f"; gunzip -c "$f" | postgresql_execute "$POSTGRESQL_DATABASE" "$POSTGRESQL_INITSCRIPTS_USERNAME" "$POSTGRESQL_INITSCRIPTS_PASSWORD";; - *) postgresql_debug "Ignoring $f" ;; + *.sql) debug "Executing $f"; postgresql_execute "$POSTGRESQL_DATABASE" "$POSTGRESQL_INITSCRIPTS_USERNAME" "$POSTGRESQL_INITSCRIPTS_PASSWORD" < "$f";; + *.sql.gz) debug "Executing $f"; gunzip -c "$f" | postgresql_execute "$POSTGRESQL_DATABASE" "$POSTGRESQL_INITSCRIPTS_USERNAME" "$POSTGRESQL_INITSCRIPTS_PASSWORD";; + *) debug "Ignoring $f" ;; esac done touch "$POSTGRESQL_VOLUME_DIR"/.user_scripts_initialized @@ -759,7 +588,7 @@ postgresql_custom_init_scripts() { # None ######################### postgresql_stop() { - postgresql_info "Stopping PostgreSQL..." + info "Stopping PostgreSQL..." stop_service_using_pid "$POSTGRESQL_PID_FILE" } @@ -811,7 +640,7 @@ postgresql_execute() { ######################### postgresql_start_bg() { local -r pg_ctl_flags=("-w" "-D" "$POSTGRESQL_DATA_DIR" "-l" "$POSTGRESQL_LOG_FILE" "-o" "--config-file=$POSTGRESQL_CONF_FILE --external_pid_file=$POSTGRESQL_PID_FILE --hba_file=$POSTGRESQL_PGHBA_FILE") - postgresql_info "Starting PostgreSQL in background..." + info "Starting PostgreSQL in background..." is_postgresql_running && return local pg_ctl_cmd=() if am_i_root; then @@ -829,7 +658,7 @@ postgresql_start_bg() { sleep 1 counter=$((counter - 1 )) if (( counter <= 0 )); then - postgresql_error "PostgreSQL is not ready after $POSTGRESQL_INIT_MAX_TIMEOUT seconds" + error "PostgreSQL is not ready after $POSTGRESQL_INIT_MAX_TIMEOUT seconds" exit 1 fi done @@ -855,6 +684,20 @@ is_postgresql_running() { fi } + +######################## +# Check if PostgreSQL is not running +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# Boolean +######################### +is_postgresql_not_running() { + ! is_postgresql_running +} + ######################## # Initialize master node database by running initdb # Globals: @@ -882,7 +725,7 @@ postgresql_master_init_db() { fi initdb_cmd+=("$POSTGRESQL_BIN_DIR/initdb") if [[ -n "${initdb_args[*]:-}" ]]; then - postgresql_info "Initializing PostgreSQL with ${initdb_args[*]} extra initdb arguments" + info "Initializing PostgreSQL with ${initdb_args[*]} extra initdb arguments" if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then "${initdb_cmd[@]}" -E UTF8 -D "$POSTGRESQL_DATA_DIR" -U "postgres" "${initdb_args[@]}" else @@ -905,7 +748,7 @@ postgresql_master_init_db() { # Boolean ######################### postgresql_slave_init_db() { - postgresql_info "Waiting for replication master to accept connections (${POSTGRESQL_INIT_MAX_TIMEOUT} timeout)..." + info "Waiting for replication master to accept connections (${POSTGRESQL_INIT_MAX_TIMEOUT} timeout)..." local -r check_args=("-U" "$POSTGRESQL_REPLICATION_USER" "-h" "$POSTGRESQL_MASTER_HOST" "-p" "$POSTGRESQL_MASTER_PORT_NUMBER" "-d" "postgres") local check_cmd=() if am_i_root; then @@ -918,12 +761,12 @@ postgresql_slave_init_db() { sleep 1 ready_counter=$(( ready_counter - 1 )) if (( ready_counter <= 0 )); then - postgresql_error "PostgreSQL master is not ready after $POSTGRESQL_INIT_MAX_TIMEOUT seconds" + error "PostgreSQL master is not ready after $POSTGRESQL_INIT_MAX_TIMEOUT seconds" exit 1 fi done - postgresql_info "Replicating the initial database" + info "Replicating the initial database" local -r backup_args=("-D" "$POSTGRESQL_DATA_DIR" "-U" "$POSTGRESQL_REPLICATION_USER" "-h" "$POSTGRESQL_MASTER_HOST" "-p" "$POSTGRESQL_MASTER_PORT_NUMBER" "-X" "stream" "-w" "-v" "-P") local backup_cmd=() if am_i_root; then @@ -932,16 +775,29 @@ postgresql_slave_init_db() { backup_cmd+=("$POSTGRESQL_BIN_DIR"/pg_basebackup) local replication_counter=$POSTGRESQL_INIT_MAX_TIMEOUT while ! PGPASSWORD=$POSTGRESQL_REPLICATION_PASSWORD "${backup_cmd[@]}" "${backup_args[@]}";do - postgresql_debug "Backup command failed. Sleeping and trying again" + debug "Backup command failed. Sleeping and trying again" sleep 1 replication_counter=$(( replication_counter - 1 )) if (( replication_counter <= 0 )); then - postgresql_error "Slave replication failed after trying for $POSTGRESQL_INIT_MAX_TIMEOUT seconds" + error "Slave replication failed after trying for $POSTGRESQL_INIT_MAX_TIMEOUT seconds" exit 1 fi done } +######################## +# Return PostgreSQL major version +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# String +######################### +postgresql_get_major_version() { + psql --version | grep -oE "[0-9]+\.[0-9]+" | grep -oE "^[0-9]+" +} + ######################## # Create recovery.conf in slave node # Globals: @@ -952,8 +808,9 @@ postgresql_slave_init_db() { # Boolean ######################### postgresql_configure_recovery() { - postgresql_info "Setting up streaming replication slave..." - if (( POSTGRESQL_MAJOR_VERSION >= 12 )); then + info "Setting up streaming replication slave..." + local -r psql_major_version="$(postgresql_get_major_version)" + if (( psql_major_version >= 12 )); then postgresql_set_property "primary_conninfo" "host=${POSTGRESQL_MASTER_HOST} port=${POSTGRESQL_MASTER_PORT_NUMBER} user=${POSTGRESQL_REPLICATION_USER} password=${POSTGRESQL_REPLICATION_PASSWORD} application_name=${POSTGRESQL_CLUSTER_APP_NAME}" "$POSTGRESQL_CONF_FILE" postgresql_set_property "promote_trigger_file" "/tmp/postgresql.trigger.${POSTGRESQL_MASTER_PORT_NUMBER}" "$POSTGRESQL_CONF_FILE" touch "$POSTGRESQL_DATA_DIR"/standby.signal diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/librepmgr.sh index 7c6da3854b2e..c398db008d78 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -12,95 +12,6 @@ . /opt/bitnami/scripts/libvalidations.sh . /opt/bitnami/scripts/libnet.sh -######################## -# Overwrite info, debug, warn and error functions (liblog.sh) -######################## -repmgr_info() { - MODULE=repmgr info "${*}" -} -repmgr_debug() { - MODULE=repmgr debug "${*}" -} -repmgr_warn() { - MODULE=repmgr warn "${*}" -} -repmgr_error() { - MODULE=repmgr error "${*}" -} - -######################## -# Loads global variables used on repmgr configuration. -# Globals: -# REPMGR_* -# Arguments: -# None -# Returns: -# Series of exports to be used as 'eval' arguments -######################### -repmgr_env() { - cat <<"EOF" -# Paths -export REPMGR_BASE_DIR="/opt/bitnami/repmgr" -export REPMGR_CONF_DIR="${REPMGR_BASE_DIR}/conf" -export REPMGR_MOUNTED_CONF_DIR="${REPMGR_MOUNTED_CONF_DIR:-/bitnami/repmgr/conf}" -export REPMGR_TMP_DIR="${REPMGR_BASE_DIR}/tmp" -export REPMGR_EVENTS_DIR="${REPMGR_BASE_DIR}/events" -export REPMGR_PRIMARY_ROLE_LOCK_FILE_NAME="${REPMGR_TMP_DIR}/master.lock" -export REPMGR_STANDBY_ROLE_LOCK_FILE_NAME="${REPMGR_TMP_DIR}/standby.lock" -export REPMGR_BIN_DIR="${REPMGR_BASE_DIR}/bin" -export REPMGR_CONF_FILE="${REPMGR_CONF_DIR}/repmgr.conf" -export REPMGR_PID_FILE="${REPMGR_TMP_DIR}/repmgr.pid" -export PATH="${REPMGR_BIN_DIR}:$PATH" - -# Settings -export REPMGR_NODE_ID="${REPMGR_NODE_ID:-}" -export REPMGR_NODE_NAME="${REPMGR_NODE_NAME:-$(hostname)}" -export REPMGR_NODE_NETWORK_NAME="${REPMGR_NODE_NETWORK_NAME:-}" -export REPMGR_NODE_PRIORITY="${REPMGR_NODE_PRIORITY:-100}" - -export REPMGR_PORT_NUMBER="${REPMGR_PORT_NUMBER:-5432}" -export REPMGR_LOG_LEVEL="${REPMGR_LOG_LEVEL:-NOTICE}" - -export REPMGR_START_OPTIONS="${REPMGR_START_OPTIONS:-}" -export REPMGR_CONNECT_TIMEOUT="${REPMGR_CONNECT_TIMEOUT:-5}" -export REPMGR_RECONNECT_ATTEMPTS="${REPMGR_RECONNECT_ATTEMPTS:-3}" -export REPMGR_RECONNECT_INTERVAL="${REPMGR_RECONNECT_INTERVAL:-5}" - -export REPMGR_PARTNER_NODES="${REPMGR_PARTNER_NODES:-}" -export REPMGR_PRIMARY_HOST="${REPMGR_PRIMARY_HOST:-}" -export REPMGR_PRIMARY_PORT="${REPMGR_PRIMARY_PORT:-5432}" - -export REPMGR_USE_REPLICATION_SLOTS="${REPMGR_USE_REPLICATION_SLOTS:-1}" -export REPMGR_STANDBY_ROLE_LOCK_FILE_NAME="${REPMGR_TMP_DIR}/standby.lock" -export REPMGR_MASTER_RESPONSE_TIMEOUT="${REPMGR_MASTER_RESPONSE_TIMEOUT:-20}" -export REPMGR_DEGRADED_MONITORING_TIMEOUT="${REPMGR_DEGRADED_MONITORING_TIMEOUT:-5}" - -export REPMGR_UPGRADE_EXTENSION="${REPMGR_UPGRADE_EXTENSION:-no}" - -# These are internal -export REPMGR_SWITCH_ROLE="${REPMGR_SWITCH_ROLE:-no}" -export REPMGR_CURRENT_PRIMARY_HOST="" -export REPMGR_CURRENT_PRIMARY_PORT="${REPMGR_PRIMARY_PORT}" - -# Aliases to setup PostgreSQL environment variables -export PGCONNECT_TIMEOUT="${PGCONNECT_TIMEOUT:-10}" - -# Credentials -export REPMGR_USERNAME="${REPMGR_USERNAME:-repmgr}" -export REPMGR_DATABASE="${REPMGR_DATABASE:-repmgr}" -export REPMGR_PGHBA_TRUST_ALL="${REPMGR_PGHBA_TRUST_ALL:-no}" -EOF -if [[ -f "${REPMGR_PASSWORD_FILE:-}" ]]; then - cat <<"EOF" -export REPMGR_PASSWORD="$(< "${REPMGR_PASSWORD_FILE}")" -EOF -else - cat <<"EOF" -export REPMGR_PASSWORD="${REPMGR_PASSWORD:-}" -EOF -fi -} - ######################## # Get repmgr node id # Globals: @@ -133,12 +44,12 @@ repmgr_get_node_id() { # None ######################### repmgr_validate() { - repmgr_info "Validating settings in REPMGR_* env vars..." + info "Validating settings in REPMGR_* env vars..." local error_code=0 # Auxiliary functions print_validation_error() { - repmgr_error "$1" + error "$1" error_code=1 } @@ -193,7 +104,7 @@ repmgr_get_upstream_node() { local suggested_primary_port="" if [[ -n "$REPMGR_PARTNER_NODES" ]]; then - repmgr_info "Querying all partner nodes for common upstream node..." + info "Querying all partner nodes for common upstream node..." read -r -a nodes <<< "$(tr ',;' ' ' <<< "${REPMGR_PARTNER_NODES}")" for node in "${nodes[@]}"; do # intentionally accept inncorect address (without [schema:]// ) @@ -201,30 +112,30 @@ repmgr_get_upstream_node() { host="$(parse_uri "$node" 'host')" port="$(parse_uri "$node" 'port')" port="${port:-$REPMGR_PRIMARY_PORT}" - repmgr_debug "Checking node '$host:$port'..." + debug "Checking node '$host:$port'..." local query="SELECT conninfo FROM repmgr.show_nodes WHERE (upstream_node_name IS NULL OR upstream_node_name = '') AND active=true" if ! primary_conninfo="$(echo "$query" | NO_ERRORS=true postgresql_execute "$REPMGR_DATABASE" "$REPMGR_USERNAME" "$REPMGR_PASSWORD" "$host" "$port" "-tA")"; then - repmgr_debug "Skipping: failed to get primary from the node '$host:$port'!" + debug "Skipping: failed to get primary from the node '$host:$port'!" continue elif [[ -z "$primary_conninfo" ]]; then - repmgr_debug "Skipping: failed to get information about primary nodes!" + debug "Skipping: failed to get information about primary nodes!" continue elif [[ "$(echo "$primary_conninfo" | wc -l)" -eq 1 ]]; then suggested_primary_host="$(echo "$primary_conninfo" | awk -F 'host=' '{print $2}' | awk '{print $1}')" suggested_primary_port="$(echo "$primary_conninfo" | awk -F 'port=' '{print $2}' | awk '{print $1}')" - repmgr_debug "Pretending primary role node - '${suggested_primary_host}:${suggested_primary_port}'" + debug "Pretending primary role node - '${suggested_primary_host}:${suggested_primary_port}'" if [[ -n "$pretending_primary_host" ]]; then if [[ "${pretending_primary_host}:${pretending_primary_port}" != "${suggested_primary_host}:${suggested_primary_port}" ]]; then - repmgr_warn "Conflict of pretending primary role nodes (previously: '${pretending_primary_host}:${pretending_primary_port}', now: '${suggested_primary_host}:${suggested_primary_port}')" + warn "Conflict of pretending primary role nodes (previously: '${pretending_primary_host}:${pretending_primary_port}', now: '${suggested_primary_host}:${suggested_primary_port}')" pretending_primary_host="" && pretending_primary_port="" && break fi else - repmgr_debug "Pretending primary set to '${suggested_primary_host}:${suggested_primary_port}'!" + debug "Pretending primary set to '${suggested_primary_host}:${suggested_primary_port}'!" pretending_primary_host="$suggested_primary_host" pretending_primary_port="$suggested_primary_port" fi else - repmgr_warn "There were more than one primary when getting primary from node '$host:$port'" + warn "There were more than one primary when getting primary from node '$host:$port'" pretending_primary_host="" && pretending_primary_port="" && break fi done @@ -253,15 +164,15 @@ repmgr_get_primary_node() { readarray -t upstream_node < <(repmgr_get_upstream_node) upstream_host=${upstream_node[0]} upstream_port=${upstream_node[1]:-$REPMGR_PRIMARY_PORT} - [[ -n "$upstream_host" ]] && repmgr_info "Auto-detected primary node: '${upstream_host}:${upstream_port}'" + [[ -n "$upstream_host" ]] && info "Auto-detected primary node: '${upstream_host}:${upstream_port}'" if [[ -f "$REPMGR_PRIMARY_ROLE_LOCK_FILE_NAME" ]]; then - repmgr_info "This node was acting as a primary before restart!" + info "This node was acting as a primary before restart!" if [[ -z "$upstream_host" ]] || [[ "${upstream_host}:${upstream_port}" = "${REPMGR_NODE_NETWORK_NAME}:${REPMGR_PORT_NUMBER}" ]]; then - repmgr_info "Can not find new primary. Starting PostgreSQL normally..." + info "Can not find new primary. Starting PostgreSQL normally..." else - repmgr_info "Current master is '${upstream_host}:${upstream_port}'. Cloning/rewinding it and acting as a standby node..." + info "Current master is '${upstream_host}:${upstream_port}'. Cloning/rewinding it and acting as a standby node..." rm -f "$REPMGR_PRIMARY_ROLE_LOCK_FILE_NAME" export REPMGR_SWITCH_ROLE="yes" primary_host="$upstream_host" @@ -279,7 +190,7 @@ repmgr_get_primary_node() { fi fi - [[ -n "$primary_host" ]] && repmgr_debug "Primary node: '${primary_host}:${primary_port}'" + [[ -n "$primary_host" ]] && debug "Primary node: '${primary_host}:${primary_port}'" echo "$primary_host" echo "$primary_port" } @@ -304,7 +215,7 @@ repmgr_set_role() { primary_port=${primary_node[1]:-$REPMGR_PRIMARY_PORT} if [[ -z "$primary_host" ]]; then - repmgr_info "There are no nodes with primary role. Assuming the primary role..." + info "There are no nodes with primary role. Assuming the primary role..." role="primary" fi @@ -348,7 +259,7 @@ repmgr_set_property() { repmgr_create_repmgr_user() { local postgres_password="$POSTGRESQL_PASSWORD" local -r escaped_password="${REPMGR_PASSWORD//\'/\'\'}" - repmgr_info "Creating repmgr user: $REPMGR_USERNAME" + info "Creating repmgr user: $REPMGR_USERNAME" [[ "$POSTGRESQL_USERNAME" != "postgres" ]] && [[ -n "$POSTGRESQL_POSTGRES_PASSWORD" ]] && postgres_password="$POSTGRESQL_POSTGRES_PASSWORD" # The repmgr user is created as superuser for simplicity (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) @@ -370,7 +281,7 @@ repmgr_create_repmgr_user() { ######################### repmgr_create_repmgr_db() { local postgres_password="$POSTGRESQL_PASSWORD" - repmgr_info "Creating repmgr database: $REPMGR_DATABASE" + info "Creating repmgr database: $REPMGR_DATABASE" [[ "$POSTGRESQL_USERNAME" != "postgres" ]] && [[ -n "$POSTGRESQL_POSTGRES_PASSWORD" ]] && postgres_password="$POSTGRESQL_POSTGRES_PASSWORD" echo "CREATE DATABASE $REPMGR_DATABASE;" | postgresql_execute "" "postgres" "$postgres_password" @@ -386,7 +297,7 @@ repmgr_create_repmgr_db() { # None ######################### repmgr_inject_postgresql_configuration() { - repmgr_debug "Injecting a new postgresql.conf file..." + debug "Injecting a new postgresql.conf file..." postgresql_create_config # ref: https://repmgr.org/docs/4.3/quickstart-postgresql-configuration.html postgresql_set_property "shared_preload_libraries" "repmgr" @@ -414,7 +325,7 @@ repmgr_inject_postgresql_configuration() { # None ######################### repmgr_inject_pghba_configuration() { - repmgr_debug "Injecting a new pg_hba.conf file..." + debug "Injecting a new pg_hba.conf file..." cat > "${POSTGRESQL_MOUNTED_CONF_DIR}/pg_hba.conf" << EOF host all $REPMGR_USERNAME 0.0.0.0/0 trust @@ -437,10 +348,10 @@ EOF # None ######################### repmgr_postgresql_configuration() { - repmgr_info "Preparing PostgreSQL configuration..." + info "Preparing PostgreSQL configuration..." # User injected custom configuration if [[ -d "$REPMGR_MOUNTED_CONF_DIR" ]] && compgen -G "$REPMGR_MOUNTED_CONF_DIR"/* > /dev/null; then - repmgr_debug "User injected custom configuration detected!" + debug "User injected custom configuration detected!" fi ensure_dir_exists "$POSTGRESQL_MOUNTED_CONF_DIR" if [[ -f "${REPMGR_MOUNTED_CONF_DIR}/postgresql.conf" ]]; then @@ -466,10 +377,10 @@ repmgr_postgresql_configuration() { # None ######################### repmgr_generate_repmgr_config() { - repmgr_info "Preparing repmgr configuration..." + info "Preparing repmgr configuration..." if [[ -f "${REPMGR_MOUNTED_CONF_DIR}/repmgr.conf" ]]; then - repmgr_info "Custom repmgr.conf file detected" + info "Custom repmgr.conf file detected" cp "${REPMGR_MOUNTED_CONF_DIR}/repmgr.conf" "$REPMGR_CONF_FILE" else cat << EOF >> "$REPMGR_CONF_FILE" @@ -511,17 +422,17 @@ repmgr_wait_primary_node() { local -i step=10 local -i max_tries=$(( timeout / step )) local schemata - repmgr_info "Waiting for primary node..." - repmgr_debug "Wait for schema $REPMGR_DATABASE.repmgr on '${REPMGR_CURRENT_PRIMARY_HOST}:${REPMGR_CURRENT_PRIMARY_PORT}', will try $max_tries times with $step delay seconds (TIMEOUT=$timeout)" + info "Waiting for primary node..." + debug "Wait for schema $REPMGR_DATABASE.repmgr on '${REPMGR_CURRENT_PRIMARY_HOST}:${REPMGR_CURRENT_PRIMARY_PORT}', will try $max_tries times with $step delay seconds (TIMEOUT=$timeout)" for ((i = 0 ; i <= timeout ; i+=step )); do local query="SELECT 1 FROM information_schema.schemata WHERE catalog_name='$REPMGR_DATABASE' AND schema_name='repmgr'" if ! schemata="$(echo "$query" | NO_ERRORS=true postgresql_execute "$REPMGR_DATABASE" "$REPMGR_USERNAME" "$REPMGR_PASSWORD" "$REPMGR_CURRENT_PRIMARY_HOST" "$REPMGR_CURRENT_PRIMARY_PORT" "-tA")"; then - repmgr_debug "Host '${REPMGR_CURRENT_PRIMARY_HOST}:${REPMGR_CURRENT_PRIMARY_PORT}' is not accessible" + debug "Host '${REPMGR_CURRENT_PRIMARY_HOST}:${REPMGR_CURRENT_PRIMARY_PORT}' is not accessible" else if [[ $schemata -ne 1 ]]; then - repmgr_debug "Schema $REPMGR_DATABASE.repmgr is still not accessible" + debug "Schema $REPMGR_DATABASE.repmgr is still not accessible" else - repmgr_debug "Schema $REPMGR_DATABASE.repmgr exists!" + debug "Schema $REPMGR_DATABASE.repmgr exists!" return_value=0 && break fi fi @@ -541,7 +452,7 @@ repmgr_wait_primary_node() { # None ######################### repmgr_clone_primary() { - repmgr_info "Cloning data from primary node..." + info "Cloning data from primary node..." local -r flags=("-f" "$REPMGR_CONF_FILE" "-h" "$REPMGR_CURRENT_PRIMARY_HOST" "-p" "$REPMGR_CURRENT_PRIMARY_PORT" "-U" "$REPMGR_USERNAME" "-d" "$REPMGR_DATABASE" "-D" "$POSTGRESQL_DATA_DIR" "standby" "clone" "--fast-checkpoint" "--force") PGPASSWORD="$REPMGR_PASSWORD" debug_execute "${REPMGR_BIN_DIR}/repmgr" "${flags[@]}" @@ -557,12 +468,12 @@ repmgr_clone_primary() { # None ######################### repmgr_rewind() { - repmgr_info "Rejoining node..." + info "Rejoining node..." - repmgr_debug "Deleting old data..." + debug "Deleting old data..." rm -rf "$POSTGRESQL_DATA_DIR" && ensure_dir_exists "$POSTGRESQL_DATA_DIR" - repmgr_debug "Cloning data from primary node..." + debug "Cloning data from primary node..." repmgr_clone_primary } @@ -576,7 +487,7 @@ repmgr_rewind() { # None ######################### repmgr_register_primary() { - repmgr_info "Registering Primary..." + info "Registering Primary..." local -r flags=("-f" "$REPMGR_CONF_FILE" "master" "register" "--force") debug_execute "${REPMGR_BIN_DIR}/repmgr" "${flags[@]}" @@ -592,7 +503,7 @@ repmgr_register_primary() { # None ######################### repmgr_unregister_standby() { - repmgr_info "Unregistering standby node..." + info "Unregistering standby node..." local -r flags=("standby" "unregister" "-f" "$REPMGR_CONF_FILE" "--node-id=$(repmgr_get_node_id)") @@ -610,7 +521,7 @@ repmgr_unregister_standby() { # None ######################### repmgr_register_standby() { - repmgr_info "Registering Standby node..." + info "Registering Standby node..." local -r flags=("standby" "register" "-f" "$REPMGR_CONF_FILE" "--force" "--verbose") debug_execute "${REPMGR_BIN_DIR}/repmgr" "${flags[@]}" @@ -626,7 +537,7 @@ repmgr_register_standby() { # None ######################### repmgr_upgrade_extension() { - repmgr_info "Upgrading repmgr extension..." + info "Upgrading repmgr extension..." echo "ALTER EXTENSION repmgr UPDATE" | postgresql_execute "$REPMGR_DATABASE" "$REPMGR_USERNAME" "$REPMGR_PASSWORD" } @@ -641,8 +552,8 @@ repmgr_upgrade_extension() { # None ######################### repmgr_initialize() { - repmgr_debug "Node ID: '$(repmgr_get_node_id)', Rol: '$REPMGR_ROLE', Primary Node: '${REPMGR_CURRENT_PRIMARY_HOST}:${REPMGR_CURRENT_PRIMARY_PORT}'" - repmgr_info "Initializing Repmgr..." + debug "Node ID: '$(repmgr_get_node_id)', Rol: '$REPMGR_ROLE', Primary Node: '${REPMGR_CURRENT_PRIMARY_HOST}:${REPMGR_CURRENT_PRIMARY_PORT}'" + info "Initializing Repmgr..." if [[ "$REPMGR_ROLE" = "standby" ]]; then repmgr_wait_primary_node || exit 1 @@ -675,10 +586,11 @@ repmgr_initialize() { postgresql_start_bg repmgr_upgrade_extension else - repmgr_debug "Skipping repmgr configuration..." + debug "Skipping repmgr configuration..." fi else - (( POSTGRESQL_MAJOR_VERSION >= 12 )) && postgresql_configure_recovery + local -r psql_major_version="$(postgresql_get_major_version)" + (( psql_major_version >= 12 )) && postgresql_configure_recovery postgresql_start_bg repmgr_unregister_standby repmgr_register_standby diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-env.sh new file mode 100644 index 000000000000..da7d21dc24c1 --- /dev/null +++ b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -0,0 +1,272 @@ +#!/bin/bash +# +# Environment configuration for postgresql + +# The values for all environment variables will be set in the below order of precedence +# 1. Custom environment variables defined below after Bitnami defaults +# 2. Constants defined in this file (environment variables with no default), i.e. BITNAMI_ROOT_DIR +# 3. Environment variables overridden via external files using *_FILE variables (see below) +# 4. Environment variables set externally (i.e. current Bash context/Dockerfile/userdata) + +export BITNAMI_ROOT_DIR="/opt/bitnami" +export BITNAMI_VOLUME_DIR="/bitnami" + +# Logging configuration +export MODULE="${MODULE:-postgresql}" +export BITNAMI_DEBUG="${BITNAMI_DEBUG:-false}" + +# By setting an environment variable matching *_FILE to a file path, the prefixed environment +# variable will be overridden with the value specified in that file +postgresql_env_vars=( + POSTGRESQL_DATA_DIR + POSTGRESQL_INIT_MAX_TIMEOUT + POSTGRESQL_CLUSTER_APP_NAME + POSTGRESQL_DATABASE + POSTGRESQL_INITDB_ARGS + ALLOW_EMPTY_PASSWORD + POSTGRESQL_INITDB_WAL_DIR + POSTGRESQL_MASTER_HOST + POSTGRESQL_MASTER_PORT_NUMBER + POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS + POSTGRESQL_PORT_NUMBER + POSTGRESQL_ALLOW_REMOTE_CONNECTIONS + POSTGRESQL_REPLICATION_MODE + POSTGRESQL_REPLICATION_USER + POSTGRESQL_SYNCHRONOUS_COMMIT_MODE + POSTGRESQL_FSYNC + POSTGRESQL_USERNAME + POSTGRESQL_ENABLE_LDAP + POSTGRESQL_LDAP_URL + POSTGRESQL_LDAP_PREFIX + POSTGRESQL_LDAP_SUFFIX + POSTGRESQL_LDAP_SERVER + POSTGRESQL_LDAP_PORT + POSTGRESQL_LDAP_SCHEME + POSTGRESQL_LDAP_TLS + POSTGRESQL_LDAP_BASE_DN + POSTGRESQL_LDAP_BIND_DN + POSTGRESQL_LDAP_BIND_PASSWORD + POSTGRESQL_LDAP_SEARCH_ATTR + POSTGRESQL_LDAP_SEARCH_FILTER + POSTGRESQL_INITSCRIPTS_USERNAME + POSTGRESQL_PASSWORD + POSTGRESQL_POSTGRES_PASSWORD + POSTGRESQL_REPLICATION_PASSWORD + POSTGRESQL_INITSCRIPTS_PASSWORD + REPMGR_DATA_DIR + REPMGR_NODE_ID + REPMGR_NODE_NAME + REPMGR_NODE_NETWORK_NAME + REPMGR_NODE_PRIORITY + REPMGR_PORT_NUMBER + REPMGR_LOG_LEVEL + REPMGR_START_OPTIONS + REPMGR_CONNECT_TIMEOUT + REPMGR_RECONNECT_ATTEMPTS + REPMGR_RECONNECT_INTERVAL + REPMGR_PARTNER_NODES + REPMGR_PRIMARY_HOST + REPMGR_PRIMARY_PORT + REPMGR_USE_REPLICATION_SLOTS + REPMGR_MASTER_RESPONSE_TIMEOUT + REPMGR_DEGRADED_MONITORING_TIMEOUT + REPMGR_UPGRADE_EXTENSION + REPMGR_SWITCH_ROLE + PGCONNECT_TIMEOUT + REPMGR_USERNAME + REPMGR_DATABASE + REPMGR_PGHBA_TRUST_ALL + REPMGR_PASSWORD + +) +for env_var in "${postgresql_env_vars[@]}"; do + file_env_var="${env_var}_FILE" + if [[ -n "${!file_env_var:-}" ]]; then + export "${env_var}=$(< "${!file_env_var}")" + unset "${file_env_var}" + fi +done +unset postgresql_env_vars + +# Paths +export PATH="/opt/bitnami/postgresql/bin:/opt/bitnami/common/bin:$PATH" +export POSTGRESQL_VOLUME_DIR="/bitnami/postgresql" +export POSTGRESQL_BASE_DIR="/opt/bitnami/postgresql" + +export POSTGRESQL_DATA_DIR="${POSTGRESQL_DATA_DIR:-"${POSTGRES_DATA_DIR:-}"}" +export POSTGRESQL_DATA_DIR="${POSTGRESQL_DATA_DIR:-"${PGDATA:-}"}" +export POSTGRESQL_DATA_DIR="${POSTGRESQL_DATA_DIR:-${POSTGRESQL_VOLUME_DIR}/postgresql/data}" +export POSTGRESQL_CONF_DIR="$POSTGRESQL_BASE_DIR/conf" +export POSTGRESQL_MOUNTED_CONF_DIR="$POSTGRESQL_VOLUME_DIR/conf" +export POSTGRESQL_CONF_FILE="$POSTGRESQL_CONF_DIR/postgresql.conf" +export POSTGRESQL_PGHBA_FILE="$POSTGRESQL_CONF_DIR/pg_hba.conf" +export POSTGRESQL_RECOVERY_FILE="$POSTGRESQL_DATA_DIR/recovery.conf" +export POSTGRESQL_LOG_DIR="$POSTGRESQL_BASE_DIR/logs" +export POSTGRESQL_LOG_FILE="$POSTGRESQL_LOG_DIR/postgresql.log" +export POSTGRESQL_TMP_DIR="$POSTGRESQL_BASE_DIR/tmp" +export POSTGRESQL_PID_FILE="$POSTGRESQL_TMP_DIR/postgresql.pid" +export POSTGRESQL_BIN_DIR="$POSTGRESQL_BASE_DIR/bin" +export POSTGRESQL_INITSCRIPTS_DIR="/docker-entrypoint-initdb.d" +export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" +export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" + +# System users (when running with a privileged user) +export POSTGRESQL_DAEMON_USER="postgres" +export POSTGRESQL_DAEMON_GROUP="postgres" + +# PostgreSQL settings +export POSTGRESQL_INIT_MAX_TIMEOUT="${POSTGRESQL_INIT_MAX_TIMEOUT:-60}" + +export POSTGRESQL_CLUSTER_APP_NAME="${POSTGRESQL_CLUSTER_APP_NAME:-"${POSTGRES_CLUSTER_APP_NAME:-}"}" +export POSTGRESQL_CLUSTER_APP_NAME="${POSTGRESQL_CLUSTER_APP_NAME:-walreceiver}" + +export POSTGRESQL_DATABASE="${POSTGRESQL_DATABASE:-"${POSTGRES_DATABASE:-}"}" +export POSTGRESQL_DATABASE="${POSTGRESQL_DATABASE:-"${POSTGRES_DB:-}"}" +export POSTGRESQL_DATABASE="${POSTGRESQL_DATABASE:-postgres}" + +export POSTGRESQL_INITDB_ARGS="${POSTGRESQL_INITDB_ARGS:-"${POSTGRES_INITDB_ARGS:-}"}" +export POSTGRESQL_INITDB_ARGS="${POSTGRESQL_INITDB_ARGS:-}" +export ALLOW_EMPTY_PASSWORD="${ALLOW_EMPTY_PASSWORD:-no}" + +export POSTGRESQL_INITDB_WAL_DIR="${POSTGRESQL_INITDB_WAL_DIR:-"${POSTGRES_INITDB_WAL_DIR:-}"}" +export POSTGRESQL_INITDB_WAL_DIR="${POSTGRESQL_INITDB_WAL_DIR:-}" + +export POSTGRESQL_MASTER_HOST="${POSTGRESQL_MASTER_HOST:-"${POSTGRES_MASTER_HOST:-}"}" +export POSTGRESQL_MASTER_HOST="${POSTGRESQL_MASTER_HOST:-}" + +export POSTGRESQL_MASTER_PORT_NUMBER="${POSTGRESQL_MASTER_PORT_NUMBER:-"${POSTGRES_MASTER_PORT_NUMBER:-}"}" +export POSTGRESQL_MASTER_PORT_NUMBER="${POSTGRESQL_MASTER_PORT_NUMBER:-5432}" + +export POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS="${POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS:-"${POSTGRES_NUM_SYNCHRONOUS_REPLICAS:-}"}" +export POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS="${POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS:-0}" + +export POSTGRESQL_PORT_NUMBER="${POSTGRESQL_PORT_NUMBER:-"${POSTGRES_PORT_NUMBER:-}"}" +export POSTGRESQL_PORT_NUMBER="${POSTGRESQL_PORT_NUMBER:-5432}" + +export POSTGRESQL_ALLOW_REMOTE_CONNECTIONS="${POSTGRESQL_ALLOW_REMOTE_CONNECTIONS:-"${POSTGRES_ALLOW_REMOTE_CONNECTIONS:-}"}" +export POSTGRESQL_ALLOW_REMOTE_CONNECTIONS="${POSTGRESQL_ALLOW_REMOTE_CONNECTIONS:-yes}" + +export POSTGRESQL_REPLICATION_MODE="${POSTGRESQL_REPLICATION_MODE:-"${POSTGRES_REPLICATION_MODE:-}"}" +export POSTGRESQL_REPLICATION_MODE="${POSTGRESQL_REPLICATION_MODE:-master}" + +export POSTGRESQL_REPLICATION_USER="${POSTGRESQL_REPLICATION_USER:-"${POSTGRES_REPLICATION_USER:-}"}" +export POSTGRESQL_REPLICATION_USER="${POSTGRESQL_REPLICATION_USER:-}" + +export POSTGRESQL_SYNCHRONOUS_COMMIT_MODE="${POSTGRESQL_SYNCHRONOUS_COMMIT_MODE:-"${POSTGRES_SYNCHRONOUS_COMMIT_MODE:-}"}" +export POSTGRESQL_SYNCHRONOUS_COMMIT_MODE="${POSTGRESQL_SYNCHRONOUS_COMMIT_MODE:-on}" + +export POSTGRESQL_FSYNC="${POSTGRESQL_FSYNC:-"${POSTGRES_FSYNC:-}"}" +export POSTGRESQL_FSYNC="${POSTGRESQL_FSYNC:-on}" + +export POSTGRESQL_USERNAME="${POSTGRESQL_USERNAME:-"${POSTGRES_USERNAME:-}"}" +export POSTGRESQL_USERNAME="${POSTGRESQL_USERNAME:-"${POSTGRES_USER:-}"}" +export POSTGRESQL_USERNAME="${POSTGRESQL_USERNAME:-"${POSTGRESQL_USER:-}"}" +export POSTGRESQL_USERNAME="${POSTGRESQL_USERNAME:-postgres}" + +export POSTGRESQL_ENABLE_LDAP="${POSTGRESQL_ENABLE_LDAP:-"${POSTGRES_ENABLE_LDAP:-}"}" +export POSTGRESQL_ENABLE_LDAP="${POSTGRESQL_ENABLE_LDAP:-no}" + +export POSTGRESQL_LDAP_URL="${POSTGRESQL_LDAP_URL:-"${POSTGRES_LDAP_URL:-}"}" +export POSTGRESQL_LDAP_URL="${POSTGRESQL_LDAP_URL:-}" + +export POSTGRESQL_LDAP_PREFIX="${POSTGRESQL_LDAP_PREFIX:-"${POSTGRES_LDAP_PREFIX:-}"}" +export POSTGRESQL_LDAP_PREFIX="${POSTGRESQL_LDAP_PREFIX:-}" + +export POSTGRESQL_LDAP_SUFFIX="${POSTGRESQL_LDAP_SUFFIX:-"${POSTGRES_LDAP_SUFFIX:-}"}" +export POSTGRESQL_LDAP_SUFFIX="${POSTGRESQL_LDAP_SUFFIX:-}" + +export POSTGRESQL_LDAP_SERVER="${POSTGRESQL_LDAP_SERVER:-"${POSTGRES_LDAP_SERVER:-}"}" +export POSTGRESQL_LDAP_SERVER="${POSTGRESQL_LDAP_SERVER:-}" + +export POSTGRESQL_LDAP_PORT="${POSTGRESQL_LDAP_PORT:-"${POSTGRES_LDAP_PORT:-}"}" +export POSTGRESQL_LDAP_PORT="${POSTGRESQL_LDAP_PORT:-}" + +export POSTGRESQL_LDAP_SCHEME="${POSTGRESQL_LDAP_SCHEME:-"${POSTGRES_LDAP_SCHEME:-}"}" +export POSTGRESQL_LDAP_SCHEME="${POSTGRESQL_LDAP_SCHEME:-}" + +export POSTGRESQL_LDAP_TLS="${POSTGRESQL_LDAP_TLS:-"${POSTGRES_LDAP_TLS:-}"}" +export POSTGRESQL_LDAP_TLS="${POSTGRESQL_LDAP_TLS:-}" + +export POSTGRESQL_LDAP_BASE_DN="${POSTGRESQL_LDAP_BASE_DN:-"${POSTGRES_LDAP_BASE_DN:-}"}" +export POSTGRESQL_LDAP_BASE_DN="${POSTGRESQL_LDAP_BASE_DN:-}" + +export POSTGRESQL_LDAP_BIND_DN="${POSTGRESQL_LDAP_BIND_DN:-"${POSTGRES_LDAP_BIND_DN:-}"}" +export POSTGRESQL_LDAP_BIND_DN="${POSTGRESQL_LDAP_BIND_DN:-}" + +export POSTGRESQL_LDAP_BIND_PASSWORD="${POSTGRESQL_LDAP_BIND_PASSWORD:-"${POSTGRES_LDAP_BIND_PASSWORD:-}"}" +export POSTGRESQL_LDAP_BIND_PASSWORD="${POSTGRESQL_LDAP_BIND_PASSWORD:-}" + +export POSTGRESQL_LDAP_SEARCH_ATTR="${POSTGRESQL_LDAP_SEARCH_ATTR:-"${POSTGRES_LDAP_SEARCH_ATTR:-}"}" +export POSTGRESQL_LDAP_SEARCH_ATTR="${POSTGRESQL_LDAP_SEARCH_ATTR:-}" + +export POSTGRESQL_LDAP_SEARCH_FILTER="${POSTGRESQL_LDAP_SEARCH_FILTER:-"${POSTGRES_LDAP_SEARCH_FILTER:-}"}" +export POSTGRESQL_LDAP_SEARCH_FILTER="${POSTGRESQL_LDAP_SEARCH_FILTER:-}" + +export POSTGRESQL_INITSCRIPTS_USERNAME="${POSTGRESQL_INITSCRIPTS_USERNAME:-"${POSTGRES_INITSCRIPTS_USERNAME:-}"}" +export POSTGRESQL_INITSCRIPTS_USERNAME="${POSTGRESQL_INITSCRIPTS_USERNAME:-$POSTGRESQL_USERNAME}" + +export POSTGRESQL_PASSWORD="${POSTGRESQL_PASSWORD:-"${POSTGRES_PASSWORD:-}"}" +export POSTGRESQL_PASSWORD="${POSTGRESQL_PASSWORD:-}" + +export POSTGRESQL_POSTGRES_PASSWORD="${POSTGRESQL_POSTGRES_PASSWORD:-"${POSTGRES_POSTGRES_PASSWORD:-}"}" +export POSTGRESQL_POSTGRES_PASSWORD="${POSTGRESQL_POSTGRES_PASSWORD:-}" + +export POSTGRESQL_REPLICATION_PASSWORD="${POSTGRESQL_REPLICATION_PASSWORD:-"${POSTGRES_REPLICATION_PASSWORD:-}"}" +export POSTGRESQL_REPLICATION_PASSWORD="${POSTGRESQL_REPLICATION_PASSWORD:-}" + +export POSTGRESQL_INITSCRIPTS_PASSWORD="${POSTGRESQL_INITSCRIPTS_PASSWORD:-"${POSTGRES_INITSCRIPTS_PASSWORD:-}"}" +export POSTGRESQL_INITSCRIPTS_PASSWORD="${POSTGRESQL_INITSCRIPTS_PASSWORD:-}" + +# Internal +export POSTGRESQL_FIRST_BOOT="yes" +export NSS_WRAPPER_LIB="/opt/bitnami/common/lib/libnss_wrapper.so" + +# Paths (Replication Manager) +export PATH="/opt/bitnami/repmgr/bin:/opt/bitnami/common/bin:$PATH" +export REPMGR_BASE_DIR="/opt/bitnami/repmgr" +export REPMGR_CONF_DIR="$REPMGR_BASE_DIR/conf" +export REPMGR_VOLUME_DIR="/bitnami/repmgr" +export REPMGR_MOUNTED_CONF_DIR="$REPMGR_VOLUME_DIR/conf" +export REPMGR_TMP_DIR="$REPMGR_BASE_DIR/tmp" +export REPMGR_EVENTS_DIR="$REPMGR_BASE_DIR/events" +export REPMGR_PRIMARY_ROLE_LOCK_FILE_NAME="$REPMGR_TMP_DIR/master.lock" +export REPMGR_STANDBY_ROLE_LOCK_FILE_NAME="$REPMGR_TMP_DIR/master.lock" +export REPMGR_BIN_DIR="$REPMGR_BASE_DIR/bin" +export REPMGR_CONF_FILE="$REPMGR_CONF_DIR/repmgr.conf" +export REPMGR_PID_FILE="$REPMGR_TMP_DIR/repmgr.pid" +export REPMGR_DATA_DIR="${REPMGR_DATA_DIR:-${REPMGR_VOLUME_DIR}/repmgr/data}" + +# Settings (Replication Manager) +export REPMGR_NODE_ID="${REPMGR_NODE_ID:-}" +export REPMGR_NODE_NAME="${REPMGR_NODE_NAME:-$(hostname)}" +export REPMGR_NODE_NETWORK_NAME="${REPMGR_NODE_NETWORK_NAME:-}" +export REPMGR_NODE_PRIORITY="${REPMGR_NODE_PRIORITY:-100}" +export REPMGR_PORT_NUMBER="${REPMGR_PORT_NUMBER:-5432}" +export REPMGR_LOG_LEVEL="${REPMGR_LOG_LEVEL:-NOTICE}" +export REPMGR_START_OPTIONS="${REPMGR_START_OPTIONS:-}" +export REPMGR_CONNECT_TIMEOUT="${REPMGR_CONNECT_TIMEOUT:-5}" +export REPMGR_RECONNECT_ATTEMPTS="${REPMGR_RECONNECT_ATTEMPTS:-3}" +export REPMGR_RECONNECT_INTERVAL="${REPMGR_RECONNECT_INTERVAL:-5}" +export REPMGR_PARTNER_NODES="${REPMGR_PARTNER_NODES:-}" +export REPMGR_PRIMARY_HOST="${REPMGR_PRIMARY_HOST:-}" +export REPMGR_PRIMARY_PORT="${REPMGR_PRIMARY_PORT:-5432}" +export REPMGR_USE_REPLICATION_SLOTS="${REPMGR_USE_REPLICATION_SLOTS:-1}" +export REPMGR_MASTER_RESPONSE_TIMEOUT="${REPMGR_MASTER_RESPONSE_TIMEOUT:-20}" +export REPMGR_DEGRADED_MONITORING_TIMEOUT="${REPMGR_DEGRADED_MONITORING_TIMEOUT:-5}" +export REPMGR_UPGRADE_EXTENSION="${REPMGR_UPGRADE_EXTENSION:-no}" + +# Internal (Replication Manager) +export REPMGR_SWITCH_ROLE="${REPMGR_SWITCH_ROLE:-no}" +export REPMGR_CURRENT_PRIMARY_HOST="" +export REPMGR_CURRENT_PRIMARY_PORT="$REPMGR_PRIMARY_PORT" + +# PostgreSQL env var (Replication Manager) +export PGCONNECT_TIMEOUT="${PGCONNECT_TIMEOUT:-10}" + +# Credentials (Replication Manager) +export REPMGR_USERNAME="${REPMGR_USERNAME:-repmgr}" +export REPMGR_DATABASE="${REPMGR_DATABASE:-repmgr}" +export REPMGR_PGHBA_TRUST_ALL="${REPMGR_PGHBA_TRUST_ALL:-no}" +export REPMGR_PASSWORD="${REPMGR_PASSWORD:-}" + +# Custom environment variables may be defined below diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/entrypoint.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/entrypoint.sh index 38834dc765de..68e3883d8f15 100755 --- a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/entrypoint.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/entrypoint.sh @@ -14,8 +14,7 @@ set -o pipefail . /opt/bitnami/scripts/librepmgr.sh # Load PostgreSQL & repmgr environment variables -eval "$(repmgr_env)" -eval "$(postgresql_env)" +. /opt/bitnami/scripts/postgresql-env.sh export MODULE=postgresql-repmgr print_welcome_page diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/postunpack.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/postunpack.sh index a48d28b0a116..9d29aaa0d326 100755 --- a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/postunpack.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/postunpack.sh @@ -9,14 +9,14 @@ . /opt/bitnami/scripts/librepmgr.sh # Load PostgreSQL & repmgr environment variables -eval "$(repmgr_env)" -eval "$(postgresql_env)" +. /opt/bitnami/scripts/postgresql-env.sh for dir in "$POSTGRESQL_INITSCRIPTS_DIR" "$POSTGRESQL_TMP_DIR" "$POSTGRESQL_LOG_DIR" "$POSTGRESQL_CONF_DIR" "${POSTGRESQL_CONF_DIR}/conf.d" "${POSTGRESQL_MOUNTED_CONF_DIR}" "${POSTGRESQL_MOUNTED_CONF_DIR}/conf.d" "$POSTGRESQL_VOLUME_DIR" "$REPMGR_CONF_DIR" "$REPMGR_TMP_DIR"; do ensure_dir_exists "$dir" chmod -R g+rwX "$dir" done + # Copying events handlers mv /events "$REPMGR_EVENTS_DIR" chmod +x "$REPMGR_EVENTS_DIR"/router.sh "$REPMGR_EVENTS_DIR"/execs/*sh "$REPMGR_EVENTS_DIR"/execs/includes/*sh diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/run.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/run.sh index 6654bd46d427..8538be32b660 100755 --- a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/run.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/run.sh @@ -13,8 +13,7 @@ set -o pipefail . /opt/bitnami/scripts/librepmgr.sh # Load PostgreSQL & repmgr environment variables -eval "$(repmgr_env)" -eval "$(postgresql_env)" +. /opt/bitnami/scripts/postgresql-env.sh readonly repmgr_flags=("--pid-file=$REPMGR_PID_FILE" "-f" "$REPMGR_CONF_FILE" "--daemonize=false") readonly repmgr_cmd=$(command -v repmgrd) diff --git a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/setup.sh b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/setup.sh index 449c0325109e..dc696b40ba9f 100755 --- a/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/setup.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/rootfs/opt/bitnami/scripts/postgresql-repmgr/setup.sh @@ -14,8 +14,7 @@ set -o pipefail . /opt/bitnami/scripts/librepmgr.sh # Load PostgreSQL & repmgr environment variables -eval "$(repmgr_env)" -eval "$(postgresql_env)" +. /opt/bitnami/scripts/postgresql-env.sh # Ensure PostgreSQL & repmgr environment variables settings are valid repmgr_validate diff --git a/bitnami/postgresql-repmgr/README.md b/bitnami/postgresql-repmgr/README.md index 5020b3385d57..5256b401e6aa 100644 --- a/bitnami/postgresql-repmgr/README.md +++ b/bitnami/postgresql-repmgr/README.md @@ -43,7 +43,7 @@ Learn more about the Bitnami tagging policy and the difference between rolling t * [`12-debian-10`, `12.3.0-debian-10-r35`, `12`, `12.3.0` (12/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/12.3.0-debian-10-r35/12/debian-10/Dockerfile) * [`11-debian-10`, `11.8.0-debian-10-r36`, `11`, `11.8.0`, `latest` (11/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/11.8.0-debian-10-r36/11/debian-10/Dockerfile) -* [`10-debian-10`, `10.13.0-debian-10-r35`, `10`, `10.13.0` (10/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/10.13.0-debian-10-r35/10/debian-10/Dockerfile) +* [`10-debian-10`, `10.13.0-debian-10-r36`, `10`, `10.13.0` (10/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/10.13.0-debian-10-r36/10/debian-10/Dockerfile) * [`9.6-debian-10`, `9.6.18-debian-10-r36`, `9.6`, `9.6.18` (9.6/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/9.6.18-debian-10-r36/9.6/debian-10/Dockerfile) Subscribe to project updates by watching the [bitnami/postgresql-repmgr GitHub repo](https://github.com/bitnami/bitnami-docker-postgresql-repmgr).