mirror of
https://github.com/bitnami/containers.git
synced 2026-02-11 22:47:20 +08:00
10.7.0-debian-9-r69 release
This commit is contained in:
@@ -1,42 +1,32 @@
|
||||
FROM bitnami/minideb-extras:stretch-r358
|
||||
FROM bitnami/minideb-extras-base:stretch-r236
|
||||
LABEL maintainer "Bitnami <containers@bitnami.com>"
|
||||
|
||||
ENV BITNAMI_PKG_CHMOD="-R g+rwX" \
|
||||
HOME="/"
|
||||
HOME="/" \
|
||||
OS_ARCH="amd64" \
|
||||
OS_FLAVOUR="debian-9" \
|
||||
OS_NAME="linux"
|
||||
|
||||
# Install required system packages and dependencies
|
||||
RUN install_packages libbsd0 libc6 libedit2 libgcc1 libicu57 liblzma5 libncurses5 libnss-wrapper libssl1.1 libstdc++6 libtinfo5 libxml2 libxslt1.1 zlib1g
|
||||
RUN bitnami-pkg unpack postgresql-10.7.0-0 --checksum 529fd4863e6a643fa045720ce0ee6283621b0878e36c5903b10b60b5c7b21695
|
||||
RUN install_packages libbsd0 libc6 libedit2 libgcc1 libicu57 liblzma5 libncurses5 libnss-wrapper libssl1.1 libstdc++6 libtinfo5 libxml2 libxslt1.1 locales zlib1g
|
||||
RUN . ./libcomponent.sh && component_unpack "postgresql" "10.7.0-0" --checksum 529fd4863e6a643fa045720ce0ee6283621b0878e36c5903b10b60b5c7b21695
|
||||
RUN echo 'en_GB.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen
|
||||
RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen
|
||||
RUN mkdir /docker-entrypoint-initdb.d /opt/bitnami/postgresql/conf/
|
||||
RUN chmod -R g+rwX /opt/bitnami/postgresql/conf/
|
||||
|
||||
COPY rootfs /
|
||||
RUN /postunpack.sh
|
||||
ENV BITNAMI_APP_NAME="postgresql" \
|
||||
BITNAMI_IMAGE_VERSION="10.7.0-debian-9-r68" \
|
||||
BITNAMI_IMAGE_VERSION="10.7.0-debian-9-r69" \
|
||||
LANG="en_US.UTF-8" \
|
||||
LANGUAGE="en_US:en" \
|
||||
NAMI_PREFIX="/.nami" \
|
||||
PATH="/opt/bitnami/postgresql/bin:$PATH" \
|
||||
POSTGRESQL_CLUSTER_APP_NAME="walreceiver" \
|
||||
POSTGRESQL_DATABASE="" \
|
||||
POSTGRESQL_DATA_DIR="/bitnami/postgresql" \
|
||||
POSTGRESQL_INITDB_ARGS="" \
|
||||
POSTGRESQL_INITDB_WALDIR="" \
|
||||
POSTGRESQL_MASTER_HOST="" \
|
||||
POSTGRESQL_MASTER_PORT_NUMBER="5432" \
|
||||
POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS="0" \
|
||||
POSTGRESQL_PASSWORD="" \
|
||||
POSTGRESQL_PORT_NUMBER="5432" \
|
||||
POSTGRESQL_REPLICATION_MODE="master" \
|
||||
POSTGRESQL_REPLICATION_PASSWORD="" \
|
||||
POSTGRESQL_REPLICATION_USER="" \
|
||||
POSTGRESQL_SYNCHRONOUS_COMMIT_MODE="on" \
|
||||
POSTGRESQL_USERNAME="postgres"
|
||||
NSS_WRAPPER_LIB="/usr/lib/libnss_wrapper.so" \
|
||||
PATH="/opt/bitnami/postgresql/bin:$PATH"
|
||||
|
||||
VOLUME [ "/bitnami/postgresql", "/docker-entrypoint-initdb.d" ]
|
||||
|
||||
EXPOSE 5432
|
||||
|
||||
USER 1001
|
||||
ENTRYPOINT [ "/app-entrypoint.sh" ]
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
||||
CMD [ "/run.sh" ]
|
||||
|
||||
@@ -7,6 +7,8 @@ services:
|
||||
- '5432:5432'
|
||||
volumes:
|
||||
- 'postgresql_data:/bitnami'
|
||||
environment:
|
||||
- 'ALLOW_EMPTY_PASSWORD=yes'
|
||||
|
||||
volumes:
|
||||
postgresql_data:
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
. /opt/bitnami/base/functions
|
||||
. /opt/bitnami/base/helpers
|
||||
|
||||
print_welcome_page
|
||||
|
||||
if [[ "$1" == "nami" && "$2" == "start" ]] || [[ "$1" == "/run.sh" ]]; then
|
||||
# Copy mounted configuration files
|
||||
PERSIST_CONF_DIR=/bitnami/postgresql/conf
|
||||
CONF_DIR=/opt/bitnami/postgresql/conf
|
||||
if [[ -d "$PERSIST_CONF_DIR" ]]; then
|
||||
mkdir -p $CONF_DIR
|
||||
cp -r $PERSIST_CONF_DIR/. $CONF_DIR
|
||||
fi
|
||||
|
||||
if ! getent passwd "$(id -u)" &> /dev/null && [ -e /usr/lib/libnss_wrapper.so ]; then
|
||||
export LD_PRELOAD='/usr/lib/libnss_wrapper.so'
|
||||
# shellcheck disable=SC2155
|
||||
export NSS_WRAPPER_PASSWD="$(mktemp)"
|
||||
# shellcheck disable=SC2155
|
||||
export NSS_WRAPPER_GROUP="$(mktemp)"
|
||||
echo "postgres:x:$(id -u):$(id -g):PostgreSQL:$PGDATA:/bin/false" > "$NSS_WRAPPER_PASSWD"
|
||||
echo "postgres:x:$(id -g):" > "$NSS_WRAPPER_GROUP"
|
||||
fi
|
||||
|
||||
if [[ -n $POSTGRESQL_PASSWORD_FILE ]]; then
|
||||
declare PASSWORD_AUX
|
||||
PASSWORD_AUX="$(< "${POSTGRESQL_PASSWORD_FILE}")"
|
||||
export POSTGRESQL_PASSWORD=$PASSWORD_AUX
|
||||
fi
|
||||
|
||||
if [[ -n $POSTGRESQL_REPLICATION_PASSWORD_FILE ]]; then
|
||||
declare REPLICATION_PASSWORD_AUX
|
||||
REPLICATION_PASSWORD_AUX="$(< "${POSTGRESQL_REPLICATION_PASSWORD_FILE}")"
|
||||
export POSTGRESQL_REPLICATION_PASSWORD=$REPLICATION_PASSWORD_AUX
|
||||
fi
|
||||
|
||||
declareEnvironmentVariableAlias() {
|
||||
if env | grep -q "$2"; then
|
||||
export "$1"="${!2}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Alias created for official postgre image compatibility
|
||||
declareEnvironmentVariableAlias POSTGRESQL_PASSWORD POSTGRES_PASSWORD
|
||||
declareEnvironmentVariableAlias POSTGRESQL_DATABASE POSTGRES_DB
|
||||
declareEnvironmentVariableAlias POSTGRESQL_USERNAME POSTGRES_USER
|
||||
declareEnvironmentVariableAlias POSTGRESQL_DATA_DIR PGDATA
|
||||
declareEnvironmentVariableAlias POSTGRESQL_INITDB_WALDIR POSTGRES_INITDB_WALDIR
|
||||
declareEnvironmentVariableAlias POSTGRESQL_INITDB_ARGS POSTGRES_INITDB_ARGS
|
||||
|
||||
# Alias created for maintain consistency using prefix
|
||||
declareEnvironmentVariableAlias POSTGRESQL_CLUSTER_APP_NAME POSTGRES_CLUSTER_APP_NAME
|
||||
declareEnvironmentVariableAlias POSTGRESQL_MASTER_HOST POSTGRES_MASTER_HOST
|
||||
declareEnvironmentVariableAlias POSTGRESQL_MASTER_PORT_NUMBER POSTGRES_MASTER_PORT_NUMBER
|
||||
declareEnvironmentVariableAlias POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS POSTGRES_NUM_SYNCHRONOUS_REPLICAS
|
||||
declareEnvironmentVariableAlias POSTGRESQL_PORT_NUMBER POSTGRES_PORT_NUMBER
|
||||
declareEnvironmentVariableAlias POSTGRESQL_REPLICATION_MODE POSTGRES_REPLICATION_MODE
|
||||
declareEnvironmentVariableAlias POSTGRESQL_REPLICATION_PASSWORD POSTGRES_REPLICATION_PASSWORD
|
||||
declareEnvironmentVariableAlias POSTGRESQL_REPLICATION_USER POSTGRES_REPLICATION_USER
|
||||
declareEnvironmentVariableAlias POSTGRESQL_SYNCHRONOUS_COMMIT_MODE POSTGRES_SYNCHRONOUS_COMMIT_MODE
|
||||
declareEnvironmentVariableAlias POSTGRESQL_PASSWORD_FILE POSTGRES_PASSWORD_FILE
|
||||
declareEnvironmentVariableAlias POSTGRESQL_REPLICATION_PASSWORD_FILE POSTGRES_REPLICATION_PASSWORD_FILE
|
||||
|
||||
nami_initialize postgresql
|
||||
info "Starting postgresql... "
|
||||
fi
|
||||
|
||||
exec tini -- "$@"
|
||||
28
bitnami/postgresql/10/debian-9/rootfs/entrypoint.sh
Executable file
28
bitnami/postgresql/10/debian-9/rootfs/entrypoint.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
#set -o xtrace
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Load libraries
|
||||
. /libbitnami.sh
|
||||
. /libpostgresql.sh
|
||||
|
||||
# Load Redis environment variables
|
||||
eval "$(postgresql_env)"
|
||||
|
||||
print_welcome_page
|
||||
|
||||
# Enable the nss_wrapper settings
|
||||
postgresql_enable_nss_wrapper
|
||||
|
||||
if [[ "$*" = *"/run.sh"* ]]; then
|
||||
info "** Starting PostgreSQL setup **"
|
||||
/setup.sh
|
||||
info "** PostgreSQL setup finished! **"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
exec "$@"
|
||||
700
bitnami/postgresql/10/debian-9/rootfs/libpostgresql.sh
Normal file
700
bitnami/postgresql/10/debian-9/rootfs/libpostgresql.sh
Normal file
@@ -0,0 +1,700 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Bitnami PostgreSQL library
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Load Generic Libraries
|
||||
. /libfile.sh
|
||||
. /liblog.sh
|
||||
. /libservice.sh
|
||||
. /libvalidations.sh
|
||||
|
||||
########################
|
||||
# Configure libnss_wrapper so PostgreSQL commands work with a random user.
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_enable_nss_wrapper() {
|
||||
if ! getent passwd "$(id -u)" &> /dev/null && [ -e "$NSS_WRAPPER_LIB" ]; then
|
||||
debug "Configuring libnss_wrapper..."
|
||||
export LD_PRELOAD="$NSS_WRAPPER_LIB"
|
||||
# shellcheck disable=SC2155
|
||||
export NSS_WRAPPER_PASSWD="$(mktemp)"
|
||||
# shellcheck disable=SC2155
|
||||
export NSS_WRAPPER_GROUP="$(mktemp)"
|
||||
echo "postgres:x:$(id -u):$(id -g):PostgreSQL:$POSTGRESQL_DATA_DIR:/bin/false" > "$NSS_WRAPPER_PASSWD"
|
||||
echo "postgres:x:$(id -g):" > "$NSS_WRAPPER_GROUP"
|
||||
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 env | grep -q "${original}"; then
|
||||
cat << EOF
|
||||
export $alias="${!original}"
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
# Alias created for official PostgreSQL image compatibility
|
||||
declare_env_alias POSTGRESQL_DATABASE POSTGRES_DB
|
||||
declare_env_alias POSTGRESQL_USERNAME POSTGRES_USER
|
||||
declare_env_alias POSTGRESQL_DATA_DIR PGDATA
|
||||
|
||||
local -r suffixes=(
|
||||
"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"
|
||||
"SYNCHRONOUS_COMMIT_MODE" "PASSWORD_FILE" "REPLICATION_PASSWORD_FILE" "INIT_MAX_TIMEOUT"
|
||||
)
|
||||
for s in "${suffixes[@]}"; do
|
||||
declare_env_alias "POSTGRESQL_${s}" "POSTGRES_${s}"
|
||||
done
|
||||
|
||||
cat <<"EOF"
|
||||
# Paths
|
||||
export 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 PATH="$POSTGRESQL_BIN_DIR:$PATH"
|
||||
|
||||
# Users
|
||||
export POSTGRESQL_DAEMON_USER="postgresql"
|
||||
export POSTGRESQL_DAEMON_GROUP="postgresql"
|
||||
|
||||
# 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:-}"
|
||||
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_USERNAME="${POSTGRESQL_USERNAME:-postgres}"
|
||||
EOF
|
||||
if [[ -n "${POSTGRESQL_PASSWORD_FILE:-}" ]] && [[ -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 [[ -n "${POSTGRESQL_REPLICATION_PASSWORD_FILE:-}" ]] && [[ -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
|
||||
}
|
||||
|
||||
########################
|
||||
# Validate settings in POSTGRESQL_* environment variables
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_validate() {
|
||||
info "Validating settings in POSTGRESQL_* env vars.."
|
||||
|
||||
# Auxiliary functions
|
||||
empty_password_enabled_warn() {
|
||||
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() {
|
||||
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."
|
||||
exit 1
|
||||
}
|
||||
if is_boolean_yes "$ALLOW_EMPTY_PASSWORD"; then
|
||||
empty_password_enabled_warn
|
||||
else
|
||||
if [[ -z "$POSTGRESQL_PASSWORD" ]]; then
|
||||
empty_password_error "POSTGRESQL_PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
if (( ${#POSTGRESQL_PASSWORD} > 32 )); then
|
||||
error "The password cannot be longer than 32 characters. Set the environment variable POSTGRESQL_PASSWORD with a shorter value"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n "$POSTGRESQL_USERNAME" ]] && [[ -z "$POSTGRESQL_PASSWORD" ]]; then
|
||||
empty_password_error "POSTGRESQL_PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n "$POSTGRESQL_USERNAME" ]] && [[ "$POSTGRESQL_USERNAME" != "postgres" ]] && [[ -n "$POSTGRESQL_PASSWORD" ]] && [[ -z "$POSTGRESQL_DATABASE" ]]; then
|
||||
error "In order to use a custom PostgreSQL user you need to set the environment variable POSTGRESQL_DATABASE as well"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if [[ -n "$POSTGRESQL_REPLICATION_MODE" ]]; then
|
||||
if [[ "$POSTGRESQL_REPLICATION_MODE" = "master" ]]; then
|
||||
if (( POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS < 0 )); then
|
||||
error "The number of synchronous replicas cannot be less than 0. Set the environment variable POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS"
|
||||
exit 1
|
||||
fi
|
||||
elif [[ "$POSTGRESQL_REPLICATION_MODE" = "slave" ]]; then
|
||||
if [[ -z "$POSTGRESQL_MASTER_HOST" ]]; then
|
||||
error "Slave replication mode chosen without setting the environment variable POSTGRESQL_MASTER_HOST. Use it to indicate where the Master node is running"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z "$POSTGRESQL_REPLICATION_USER" ]]; then
|
||||
error "Slave replication mode chosen without setting the environment variable POSTGRESQL_REPLICATION_USER. Make sure that the master also has this parameter set"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
error "Invalid replication mode. Available options are 'master/slave'"
|
||||
exit 1
|
||||
fi
|
||||
# Common replication checks
|
||||
if [[ -n "$POSTGRESQL_REPLICATION_USER" ]] && [[ -z "$POSTGRESQL_REPLICATION_PASSWORD" ]]; then
|
||||
empty_password_error "POSTGRESQL_REPLICATION_PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if is_boolean_yes "$ALLOW_EMPTY_PASSWORD"; then
|
||||
empty_password_enabled_warn
|
||||
else
|
||||
if [[ -z "$POSTGRESQL_PASSWORD" ]]; then
|
||||
empty_password_error "POSTGRESQL_PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n "$POSTGRESQL_USERNAME" ]] && [[ -z "$POSTGRESQL_PASSWORD" ]]; then
|
||||
empty_password_error "POSTGRESQL_PASSWORD"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Create basic postgresql.conf file using the example provided in the share/ folder
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_create_config() {
|
||||
info "postgresql.conf file not detected. Generating it..."
|
||||
cp "$POSTGRESQL_BASE_DIR/share/postgresql.conf.sample" "$POSTGRESQL_CONF_FILE"
|
||||
sed -i 's/#include_dir/include_dir/g' "$POSTGRESQL_CONF_FILE"
|
||||
}
|
||||
|
||||
########################
|
||||
# Create basic pg_hba.conf file
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_create_pghba() {
|
||||
info "pg_hba.conf file not detected. Generating it..."
|
||||
cat << EOF > "$POSTGRESQL_PGHBA_FILE"
|
||||
host all all 0.0.0.0/0 trust
|
||||
host all all ::1/128 trust
|
||||
EOF
|
||||
}
|
||||
|
||||
########################
|
||||
# Change pg_hba.conf so it allows local UNIX socket-based connections
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_allow_local_connection() {
|
||||
cat << EOF >> "$POSTGRESQL_PGHBA_FILE"
|
||||
local all all trust
|
||||
EOF
|
||||
}
|
||||
|
||||
########################
|
||||
# Change pg_hba.conf so only password-based authentication is allowed
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_restrict_pghba() {
|
||||
if [[ -n "$POSTGRESQL_PASSWORD" ]];then
|
||||
sed -i 's/trust/md5/g' "$POSTGRESQL_PGHBA_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Change pg_hba.conf so it allows access from replication users
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_add_replication_to_pghba() {
|
||||
local replication_auth="trust"
|
||||
if [[ -n "$POSTGRESQL_REPLICATION_PASSWORD" ]];then
|
||||
replication_auth="md5"
|
||||
fi
|
||||
cat << EOF >> "$POSTGRESQL_PGHBA_FILE"
|
||||
host replication all 0.0.0.0/0 ${replication_auth}
|
||||
EOF
|
||||
}
|
||||
|
||||
########################
|
||||
# Change a PostgreSQL configuration file by setting a property
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# $1 - property
|
||||
# $2 - value
|
||||
# $3 - Path to configuration file (default: $POSTGRESQL_CONF_FILE)
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_set_property() {
|
||||
local -r property="${1:?missing property}"
|
||||
local -r value="${2:?missing value}"
|
||||
local -r conf_file="${3:-$POSTGRESQL_CONF_FILE}"
|
||||
sed -i "s?^#*\s*${property}\s*=.*?${property} = '${value}'?g" "$conf_file"
|
||||
}
|
||||
|
||||
########################
|
||||
# Create a user for master-slave replication
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_create_replication_user() {
|
||||
local -r escaped_password="${POSTGRESQL_REPLICATION_PASSWORD//\'/\'\'}"
|
||||
info "Creating replication user $POSTGRESQL_REPLICATION_USER"
|
||||
echo "CREATE ROLE $POSTGRESQL_REPLICATION_USER REPLICATION LOGIN ENCRYPTED PASSWORD '$escaped_password'" | postgresql_execute
|
||||
}
|
||||
|
||||
########################
|
||||
# Change postgresql.conf by setting replication parameters
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_configure_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"
|
||||
postgresql_set_property "wal_keep_segments" "12"
|
||||
postgresql_set_property "hot_standby" "on"
|
||||
if (( POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS > 0 ));then
|
||||
postgresql_set_property "synchronous_commit" "$POSTGRESQL_SYNCHRONOUS_COMMIT_MODE"
|
||||
postgresql_set_property "synchronous_standby_names" "$POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS ($POSTGRESQL_CLUSTER_APP_NAME)"
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Alter password of the postgres user
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_alter_postgres_user() {
|
||||
local -r escaped_password="${POSTGRESQL_PASSWORD//\'/\'\'}"
|
||||
info "Changing password of ${POSTGRESQL_USERNAME}"
|
||||
echo "ALTER ROLE postgres WITH PASSWORD '$escaped_password';" | postgresql_execute
|
||||
}
|
||||
|
||||
########################
|
||||
# Create an admin user with all privileges in POSTGRESQL_DATABASE
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_create_admin_user() {
|
||||
local -r escaped_password="${POSTGRESQL_PASSWORD//\'/\'\'}"
|
||||
info "Creating user ${POSTGRESQL_USERNAME}"
|
||||
echo "CREATE ROLE ${POSTGRESQL_USERNAME} WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute
|
||||
info "Grating 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"
|
||||
}
|
||||
|
||||
########################
|
||||
# Create a database with name $POSTGRESQL_DATABASE
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_create_custom_database() {
|
||||
echo "CREATE DATABASE $POSTGRESQL_DATABASE" | postgresql_execute "" "postgres" "" "localhost"
|
||||
}
|
||||
|
||||
########################
|
||||
# Change postgresql.conf to listen in 0.0.0.0
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_enable_remote_connections() {
|
||||
postgresql_set_property "listen_addresses" "*"
|
||||
}
|
||||
|
||||
########################
|
||||
# Check if a given configuration file was mounted externally
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# $1 - Filename
|
||||
# Returns:
|
||||
# 1 if the file was mounted externally, 0 otherwise
|
||||
#########################
|
||||
postgresql_is_file_external() {
|
||||
local -r filename=$1
|
||||
if [[ -d "$POSTGRESQL_MOUNTED_CONF_DIR" ]] && [[ -f "$POSTGRESQL_MOUNTED_CONF_DIR"/"$filename" ]]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Ensure PostgreSQL is initialized
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_initialize() {
|
||||
info "Initializing PostgreSQL database..."
|
||||
|
||||
# User injected custom configuration
|
||||
if [[ -d "$POSTGRESQL_MOUNTED_CONF_DIR" ]] && compgen -G "$POSTGRESQL_MOUNTED_CONF_DIR"/* > /dev/null;then
|
||||
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
|
||||
info "Custom configuration $POSTGRESQL_CONF_FILE detected"
|
||||
create_conf_file=no
|
||||
fi
|
||||
|
||||
if postgresql_is_file_external "pg_hba.conf"; then
|
||||
info "Custom configuration $POSTGRESQL_PGHBA_FILE detected"
|
||||
create_pghba_file=no
|
||||
fi
|
||||
|
||||
debug "Ensuring expected directories/files exist..."
|
||||
for dir in "$POSTGRESQL_TMP_DIR" "$POSTGRESQL_LOG_DIR"; do
|
||||
ensure_dir_exists "$dir"
|
||||
am_i_root && chown "$DB_DAEMON_USER:$DB_DAEMON_GROUP" "$dir"
|
||||
done
|
||||
is_boolean_yes "$create_conf_file" && postgresql_create_config
|
||||
is_boolean_yes "$create_pghba_file" && postgresql_create_pghba && postgresql_allow_local_connection
|
||||
|
||||
if [[ -e "$POSTGRESQL_DATA_DIR" ]]; then
|
||||
info "Deploying PostgreSQL with persisted data..."
|
||||
local -r postmaster_path="$POSTGRESQL_DATA_DIR"/postmaster.pid
|
||||
if [[ -f "$postmaster_path" ]];then
|
||||
info "Cleaning stale postmaster.pid file"
|
||||
rm "$postmaster_path"
|
||||
fi
|
||||
is_boolean_yes "$create_pghba_file" && postgresql_restrict_pghba
|
||||
is_boolean_yes "$create_conf_file" && postgresql_configure_replication_parameters
|
||||
[[ "$POSTGRESQL_REPLICATION_MODE" = "master" ]] && [[ -n "$POSTGRESQL_REPLICATION_USER" ]] && is_boolean_yes "$create_pghba_file" && postgresql_add_replication_to_pghba
|
||||
else
|
||||
ensure_dir_exists "$POSTGRESQL_DATA_DIR"
|
||||
am_i_root && chown "$DB_DAEMON_USER:$DB_DAEMON_GROUP" "$POSTGRESQL_DATA_DIR"
|
||||
if [[ "$POSTGRESQL_REPLICATION_MODE" = "master" ]];then
|
||||
postgresql_master_init_db
|
||||
postgresql_start_bg
|
||||
[[ -n "${POSTGRESQL_DATABASE}" ]] && postgresql_create_custom_database
|
||||
if [[ "$POSTGRESQL_USERNAME" = "postgres" ]];then
|
||||
postgresql_alter_postgres_user
|
||||
else
|
||||
postgresql_create_admin_user
|
||||
fi
|
||||
is_boolean_yes "$create_pghba_file" && postgresql_restrict_pghba
|
||||
[[ -n "$POSTGRESQL_REPLICATION_USER" ]] && postgresql_create_replication_user
|
||||
is_boolean_yes "$create_conf_file" && postgresql_configure_replication_parameters
|
||||
[[ -n "$POSTGRESQL_REPLICATION_USER" ]] && is_boolean_yes "$create_pghba_file" && postgresql_add_replication_to_pghba
|
||||
else
|
||||
postgresql_slave_init_db
|
||||
is_boolean_yes "$create_pghba_file" && postgresql_restrict_pghba
|
||||
is_boolean_yes "$create_conf_file" && postgresql_configure_replication_parameters
|
||||
postgresql_configure_recovery
|
||||
fi
|
||||
fi
|
||||
|
||||
# Delete conf files generated on first run
|
||||
rm -f "$POSTGRESQL_DATA_DIR"/postgresql.conf "$POSTGRESQL_DATA_DIR"/pg_hba.conf
|
||||
}
|
||||
|
||||
########################
|
||||
# Run custom initialization scripts
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_custom_init_scripts() {
|
||||
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
|
||||
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
|
||||
debug "Executing $f"; "$f"
|
||||
else
|
||||
debug "Sourcing $f"; . "$f"
|
||||
fi
|
||||
;;
|
||||
*.sql) debug "Executing $f"; postgresql_execute "$POSTGRESQL_DATABASE" "$POSTGRESQL_USERNAME" "$POSTGRESQL_PASSWORD" < "$f";;
|
||||
*.sql.gz) debug "Executing $f"; gunzip -c "$f" | postgresql_execute "$POSTGRESQL_DATABASE" "$POSTGRESQL_USERNAME" "$POSTGRESQL_PASSWORD";;
|
||||
*) debug "Ignoring $f" ;;
|
||||
esac
|
||||
done
|
||||
touch "$POSTGRESQL_VOLUME_DIR"/.user_scripts_initialized
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Stop PostgreSQL
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_stop() {
|
||||
info "Stopping PostgreSQL..."
|
||||
stop_service_using_pid "$POSTGRESQL_PID_FILE"
|
||||
}
|
||||
|
||||
########################
|
||||
# Execute an arbitrary query/queries against the running PostgreSQL service
|
||||
# Stdin:
|
||||
# Query/queries to execute
|
||||
# Globals:
|
||||
# BITNAMI_DEBUG
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# $1 - Database where to run the queries
|
||||
# $2 - User to run queries
|
||||
# $3 - Password
|
||||
# $4 - Host
|
||||
# Returns:
|
||||
# None
|
||||
postgresql_execute() {
|
||||
local -r db="${1:-}"
|
||||
local -r user="${2:-postgres}"
|
||||
local -r pass="${3:-}"
|
||||
local -r host="${4:-localhost}"
|
||||
local args=( "-h" "$host" "-U" "$user" )
|
||||
local cmd=("$POSTGRESQL_BIN_DIR/psql")
|
||||
[[ -n "$db" ]] && args+=( "-d" "$db" )
|
||||
if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then
|
||||
PGPASSWORD=$pass "${cmd[@]}" "${args[@]}"
|
||||
else
|
||||
PGPASSWORD=$pass "${cmd[@]}" "${args[@]}" >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Start PostgreSQL and wait until it is ready
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
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")
|
||||
info "Starting PostgreSQL in background..."
|
||||
is_postgresql_running && return
|
||||
"$POSTGRESQL_BIN_DIR"/pg_ctl "start" "${pg_ctl_flags[@]}"
|
||||
local -r pg_isready_args=("-U" "postgres")
|
||||
local counter=$POSTGRESQL_INIT_MAX_TIMEOUT
|
||||
while ! "$POSTGRESQL_BIN_DIR"/pg_isready "${pg_isready_args[@]}";do
|
||||
sleep 1
|
||||
counter=$((counter - 1 ))
|
||||
if (( counter <= 0 ));then
|
||||
error "PostgreSQL is not ready after $POSTGRESQL_INIT_MAX_TIMEOUT seconds"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
########################
|
||||
# Check if PostgreSQL is running
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Boolean
|
||||
#########################
|
||||
is_postgresql_running() {
|
||||
local pid
|
||||
pid="$(get_pid_from_file "$POSTGRESQL_PID_FILE")"
|
||||
|
||||
if [[ -z "$pid" ]]; then
|
||||
false
|
||||
else
|
||||
is_service_running "$pid"
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Initialize master node database by running initdb
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Boolean
|
||||
#########################
|
||||
postgresql_master_init_db() {
|
||||
local initdb_args=()
|
||||
if [[ -n "${POSTGRESQL_INITDB_ARGS[*]}" ]];then
|
||||
initdb_args+=(${POSTGRESQL_INITDB_ARGS[@]})
|
||||
fi
|
||||
if [[ -n "$POSTGRESQL_INITDB_WAL_DIR" ]];then
|
||||
ensure_dir_exists "$POSTGRESQL_INITDB_WAL_DIR"
|
||||
am_i_root && chown "$DB_DAEMON_USER:$DB_DAEMON_GROUP" "$POSTGRESQL_INITDB_WAL_DIR"
|
||||
initdb_args+=("--waldir" "$POSTGRESQL_INITDB_WAL_DIR")
|
||||
fi
|
||||
if [[ -n "${initdb_args[*]:-}" ]];then
|
||||
info "Initializing PostgreSQL with ${initdb_args[*]} extra initdb arguments"
|
||||
"$POSTGRESQL_BIN_DIR/initdb" -E UTF8 -D "$POSTGRESQL_DATA_DIR" -U "postgres" "${initdb_args[@]}"
|
||||
else
|
||||
"$POSTGRESQL_BIN_DIR/initdb" -E UTF8 -D "$POSTGRESQL_DATA_DIR" -U "postgres"
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Initialize slave node by running pg_basebackup
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Boolean
|
||||
#########################
|
||||
postgresql_slave_init_db() {
|
||||
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 -r check_cmd=("$POSTGRESQL_BIN_DIR"/pg_isready)
|
||||
local ready_counter=$POSTGRESQL_INIT_MAX_TIMEOUT
|
||||
|
||||
while ! PGPASSWORD=$POSTGRESQL_REPLICATION_PASSWORD "${check_cmd[@]}" "${check_args[@]}";do
|
||||
sleep 1
|
||||
ready_counter=$(( ready_counter - 1 ))
|
||||
if (( ready_counter <= 0 ));then
|
||||
error "PostgreSQL master is not ready after $POSTGRESQL_INIT_MAX_TIMEOUT seconds"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
done
|
||||
info "Replicating the initial database"
|
||||
local -r backup_args=("-D" "$POSTGRESQL_DATA_DIR" "-U" "$POSTGRESQL_REPLICATION_USER" "-h" "$POSTGRESQL_MASTER_HOST" "-X" "stream" "-w" "-v" "-P")
|
||||
local -r backup_cmd=("$POSTGRESQL_BIN_DIR"/pg_basebackup)
|
||||
local replication_counter=$POSTGRESQL_INIT_MAX_TIMEOUT
|
||||
while ! PGPASSWORD=$POSTGRESQL_REPLICATION_PASSWORD "${backup_cmd[@]}" "${backup_args[@]}";do
|
||||
debug "Backup command failed. Sleeping and trying again"
|
||||
sleep 1
|
||||
replication_counter=$(( replication_counter - 1 ))
|
||||
if (( replication_counter <= 0 ));then
|
||||
error "Slave replication failed after trying for $POSTGRESQL_INIT_MAX_TIMEOUT seconds"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
chmod 0700 "$POSTGRESQL_DATA_DIR"
|
||||
}
|
||||
|
||||
########################
|
||||
# Create recovery.conf in slave node
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# Boolean
|
||||
#########################
|
||||
postgresql_configure_recovery() {
|
||||
info "Setting up streaming replication slave..."
|
||||
cp -f "$POSTGRESQL_BASE_DIR/share/recovery.conf.sample" "$POSTGRESQL_RECOVERY_FILE"
|
||||
chmod 600 "$POSTGRESQL_RECOVERY_FILE"
|
||||
postgresql_set_property "standby_mode" "on" "$POSTGRESQL_RECOVERY_FILE"
|
||||
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_RECOVERY_FILE"
|
||||
postgresql_set_property "trigger_file" "/tmp/postgresql.trigger.$POSTGRESQL_MASTER_PORT_NUMBER" "$POSTGRESQL_RECOVERY_FILE"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"clusterAppName": "{{$global.env.POSTGRESQL_CLUSTER_APP_NAME}}",
|
||||
"database": "{{$global.env.POSTGRESQL_DATABASE}}",
|
||||
"initdbArgs": "{{$global.env.POSTGRESQL_INITDB_ARGS}}",
|
||||
"initdbWalDir": "{{$global.env.POSTGRESQL_INITDB_WALDIR}}",
|
||||
"masterHost": "{{$global.env.POSTGRESQL_MASTER_HOST}}",
|
||||
"masterPort": "{{$global.env.POSTGRESQL_MASTER_PORT_NUMBER}}",
|
||||
"numSynchronousReplicas": "{{$global.env.POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS}}",
|
||||
"password": "{{$global.env.POSTGRESQL_PASSWORD}}",
|
||||
"persistDir": "{{$global.env.POSTGRESQL_DATA_DIR}}",
|
||||
"postgresqlPort": "{{$global.env.POSTGRESQL_PORT_NUMBER}}",
|
||||
"replicationMode": "{{$global.env.POSTGRESQL_REPLICATION_MODE}}",
|
||||
"replicationPassword": "{{$global.env.POSTGRESQL_REPLICATION_PASSWORD}}",
|
||||
"replicationUser": "{{$global.env.POSTGRESQL_REPLICATION_USER}}",
|
||||
"synchronousCommitMode": "{{$global.env.POSTGRESQL_SYNCHRONOUS_COMMIT_MODE}}",
|
||||
"username": "{{$global.env.POSTGRESQL_USERNAME}}"
|
||||
}
|
||||
18
bitnami/postgresql/10/debian-9/rootfs/postunpack.sh
Executable file
18
bitnami/postgresql/10/debian-9/rootfs/postunpack.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Load libraries
|
||||
. /libfs.sh
|
||||
. /libpostgresql.sh
|
||||
|
||||
# Load MySQL environment variables
|
||||
eval "$(postgresql_env)"
|
||||
|
||||
for dir in "$POSTGRESQL_INITSCRIPTS_DIR" "$POSTGRESQL_TMP_DIR" "$POSTGRESQL_LOG_DIR" "$POSTGRESQL_CONF_DIR" "${POSTGRESQL_CONF_DIR}/conf.d" "$POSTGRESQL_VOLUME_DIR"; do
|
||||
ensure_dir_exists "$dir"
|
||||
done
|
||||
chmod -R g+rwX "$POSTGRESQL_INITSCRIPTS_DIR" "$POSTGRESQL_TMP_DIR" "$POSTGRESQL_LOG_DIR" "$POSTGRESQL_CONF_DIR" "${POSTGRESQL_CONF_DIR}/conf.d" "$POSTGRESQL_VOLUME_DIR"
|
||||
|
||||
# Redirect all logging to stdout
|
||||
ln -sf /dev/stdout "$POSTGRESQL_LOG_DIR/postgresql.log"
|
||||
@@ -1,84 +1,23 @@
|
||||
#!/bin/bash
|
||||
. /opt/bitnami/base/functions
|
||||
. /opt/bitnami/base/helpers
|
||||
|
||||
POSTGRESQL_BASE_DIR="/opt/bitnami/postgresql"
|
||||
MOUNT_POINT_DIR="${POSTGRESQL_DATA_DIR:-/bitnami/postgresql}"
|
||||
DATA_DIR="${MOUNT_POINT_DIR}/data"
|
||||
CONF_FILE="${POSTGRESQL_BASE_DIR}/conf/postgresql.conf"
|
||||
PID_FILE="${POSTGRESQL_BASE_DIR}/tmp/postgresql.pid"
|
||||
PG_HBA_FILE="${POSTGRESQL_BASE_DIR}/data/pg_hba.conf"
|
||||
if [[ -f "${POSTGRESQL_BASE_DIR}/conf/pg_hba.conf" ]];then
|
||||
PG_HBA_FILE="${POSTGRESQL_BASE_DIR}/conf/pg_hba.conf"
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
# set -o xtrace # Uncomment this line for debugging purpose
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Load libraries
|
||||
. /libpostgresql.sh
|
||||
. /libos.sh
|
||||
|
||||
# Load PostgreSQL environment variables
|
||||
eval "$(postgresql_env)"
|
||||
readonly flags=("-D" "$POSTGRESQL_DATA_DIR" "--config-file=$POSTGRESQL_CONF_FILE" "--external_pid_file=$POSTGRESQL_PID_FILE" "--hba_file=$POSTGRESQL_PGHBA_FILE")
|
||||
readonly cmd=$(command -v postgres)
|
||||
|
||||
info "** Starting PostgreSQL **"
|
||||
if am_i_root; then
|
||||
exec gosu "$POSTGRESQL_DAEMON_USER" "${cmd}" "${flags[@]}"
|
||||
else
|
||||
exec "${cmd}" "${flags[@]}"
|
||||
fi
|
||||
|
||||
START_ARGS=("-D" "$DATA_DIR" "--config-file=$CONF_FILE" "--external_pid_file=$PID_FILE" "--hba_file=$PG_HBA_FILE")
|
||||
STOP_ARGS=("stop" "-w" "-D" "$DATA_DIR")
|
||||
|
||||
function postgresqlStart {
|
||||
# If container is started as `root` user
|
||||
if [ $EUID -eq 0 ]; then
|
||||
exec gosu postgres postgres "${START_ARGS[@]}"
|
||||
else
|
||||
exec postgres "${START_ARGS[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
function postgresqlStop {
|
||||
# If container is started as `root` user
|
||||
if [ $EUID -eq 0 ]; then
|
||||
gosu postgres pg_ctl "${STOP_ARGS[@]}"
|
||||
else
|
||||
pg_ctl "${STOP_ARGS[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "${LD_PRELOAD:-}" = '/usr/lib/libnss_wrapper.so' ]; then
|
||||
rm -f "$NSS_WRAPPER_PASSWD" "$NSS_WRAPPER_GROUP"
|
||||
unset LD_PRELOAD NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
|
||||
fi
|
||||
|
||||
# allow running custom initialization scripts
|
||||
if [[ -n $(find /docker-entrypoint-initdb.d/ -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] && [[ ! -f /bitnami/postgresql/.user_scripts_initialized ]]; then
|
||||
info "Loading user files from /docker-entrypoint-initdb.d";
|
||||
if [[ -n $POSTGRESQL_PASSWORD ]]; then
|
||||
export PGPASSWORD=$POSTGRESQL_PASSWORD
|
||||
fi
|
||||
if [[ $POSTGRESQL_USERNAME == "postgres" ]]; then
|
||||
psql=( psql -U postgres)
|
||||
else
|
||||
psql=( psql -U "$POSTGRESQL_USERNAME" -d "$POSTGRESQL_DATABASE" )
|
||||
fi
|
||||
postgresqlStart &
|
||||
info "Initialization: Waiting for PostgreSQL to be available"
|
||||
retries=30
|
||||
until "${psql[@]}" -h 127.0.0.1 -c "select 1" > /dev/null 2>&1 || [ $retries -eq 0 ]; do
|
||||
info "Waiting for PostgreSQL server: $((retries--)) remaining attempts..."
|
||||
sleep 2
|
||||
done
|
||||
if [[ $retries == 0 ]]; then
|
||||
echo "Error: PostgreSQL is not available after 60 seconds"
|
||||
exit 1
|
||||
fi
|
||||
tmp_file=/tmp/filelist
|
||||
find /docker-entrypoint-initdb.d/ -type f -regex ".*\.\(sh\|sql\|sql.gz\)" | sort > $tmp_file
|
||||
while read -r f; do
|
||||
case "$f" in
|
||||
*.sh)
|
||||
if [ -x "$f" ]; then
|
||||
echo "Executing $f"; "$f"
|
||||
else
|
||||
echo "Sourcing $f"; . "$f"
|
||||
fi
|
||||
;;
|
||||
*.sql) echo "Executing $f"; "${psql[@]}" -f "$f"; echo ;;
|
||||
*.sql.gz) echo "Executing $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
|
||||
*) echo "Ignoring $f" ;;
|
||||
esac
|
||||
done < $tmp_file
|
||||
rm $tmp_file
|
||||
touch /bitnami/postgresql/.user_scripts_initialized
|
||||
postgresqlStop
|
||||
fi
|
||||
|
||||
postgresqlStart
|
||||
|
||||
40
bitnami/postgresql/10/debian-9/rootfs/setup.sh
Executable file
40
bitnami/postgresql/10/debian-9/rootfs/setup.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Bitnami PostgreSQL setup
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# Load Generic Libraries
|
||||
. /libfile.sh
|
||||
. /liblog.sh
|
||||
. /libservice.sh
|
||||
. /libvalidations.sh
|
||||
. /libfs.sh
|
||||
. /libos.sh
|
||||
. /libpostgresql.sh
|
||||
|
||||
# Load PostgreSQL environment variables
|
||||
eval "$(postgresql_env)"
|
||||
|
||||
# Ensure PostgreSQL environment variables settings are valid
|
||||
postgresql_validate
|
||||
# Ensure PostgreSQL is stopped when this script ends.
|
||||
trap "postgresql_stop" EXIT
|
||||
# Ensure 'daemon' user exists when running as 'root'
|
||||
am_i_root && ensure_user_exists "$POSTGRESQL_DAEMON_USER" "$POSTGRESQL_DAEMON_GROUP"
|
||||
# Ensure PostgreSQL is initialized
|
||||
postgresql_initialize
|
||||
# Allow running custom initialization scripts
|
||||
postgresql_custom_init_scripts
|
||||
|
||||
# Allow remote connections once the initialization is finished
|
||||
if ! postgresql_is_file_external "postgresql.conf"; then
|
||||
info "Enabling remote connections"
|
||||
postgresql_enable_remote_connections
|
||||
postgresql_set_property "port" "$POSTGRESQL_PORT_NUMBER"
|
||||
fi
|
||||
@@ -46,9 +46,9 @@ Learn more about the Bitnami tagging policy and the difference between rolling t
|
||||
* [`11-ol-7`, `11.2.0-ol-7-r72` (11/ol-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/11.2.0-ol-7-r72/11/ol-7/Dockerfile)
|
||||
* [`11-debian-9`, `11.2.0-debian-9-r69`, `11`, `11.2.0`, `11.2.0-r69` (11/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/11.2.0-debian-9-r69/11/debian-9/Dockerfile)
|
||||
* [`10-ol-7`, `10.7.0-ol-7-r72` (10/ol-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/10.7.0-ol-7-r72/10/ol-7/Dockerfile)
|
||||
* [`10-debian-9`, `10.7.0-debian-9-r68`, `10`, `10.7.0`, `10.7.0-r68`, `latest` (10/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/10.7.0-debian-9-r68/10/debian-9/Dockerfile)
|
||||
* [`10-debian-9`, `10.7.0-debian-9-r69`, `10`, `10.7.0`, `10.7.0-r69`, `latest` (10/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/10.7.0-debian-9-r69/10/debian-9/Dockerfile)
|
||||
* [`9.6-ol-7`, `9.6.12-ol-7-r73` (9.6/ol-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/9.6.12-ol-7-r73/9.6/ol-7/Dockerfile)
|
||||
* [`9.6-debian-9`, `9.6.12-debian-9-r70`, `9.6`, `9.6.12`, `9.6.12-r70` (9.6/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/9.6.12-debian-9-r70/9.6/debian-9/Dockerfile)
|
||||
* [`9.6-debian-9`, `9.6.12-debian-9-r69`, `9.6`, `9.6.12`, `9.6.12-r69` (9.6/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/9.6.12-debian-9-r69/9.6/debian-9/Dockerfile)
|
||||
|
||||
Subscribe to project updates by watching the [bitnami/postgresql GitHub repo](https://github.com/bitnami/bitnami-docker-postgresql).
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ services:
|
||||
- POSTGRESQL_REPLICATION_MODE=master
|
||||
- POSTGRESQL_REPLICATION_USER=repl_user
|
||||
- POSTGRESQL_REPLICATION_PASSWORD=repl_password
|
||||
- POSTGRESQL_USERNAME=my_user
|
||||
- POSTGRESQL_USERNAME=postgres
|
||||
- POSTGRESQL_PASSWORD=my_password
|
||||
- POSTGRESQL_DATABASE=my_database
|
||||
postgresql-slave:
|
||||
@@ -25,6 +25,7 @@ services:
|
||||
- POSTGRESQL_REPLICATION_USER=repl_user
|
||||
- POSTGRESQL_REPLICATION_PASSWORD=repl_password
|
||||
- POSTGRESQL_MASTER_HOST=postgresql-master
|
||||
- POSTGRESQL_PASSWORD=my_password
|
||||
- POSTGRESQL_MASTER_PORT_NUMBER=5432
|
||||
|
||||
volumes:
|
||||
|
||||
@@ -7,6 +7,8 @@ services:
|
||||
- '5432:5432'
|
||||
volumes:
|
||||
- 'postgresql_data:/bitnami'
|
||||
environment:
|
||||
- 'ALLOW_EMPTY_PASSWORD=yes'
|
||||
|
||||
volumes:
|
||||
postgresql_data:
|
||||
|
||||
Reference in New Issue
Block a user