From bff343b0e66791cb64d6e64a91e28d4a5598aecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B8nskov=20Luther?= Date: Tue, 25 Jun 2024 08:57:59 +0200 Subject: [PATCH 1/6] Use default moodle db env vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change sql-mysql.sh script to use default moodle environment variables to connect to database #68054 Signed-off-by: Thomas Lønskov Luther --- .../moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh | 6 ++++++ .../moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh | 6 ++++++ .../moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh | 6 ++++++ .../moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh | 8 +++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bitnami/moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh index dc95fc879a0b9..3d6f69aee9210 100755 --- a/bitnami/moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -33,6 +33,12 @@ mysql_execute() { return "$failure" } +MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} +MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} +MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} +MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} + # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" failure=0 diff --git a/bitnami/moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh index dc95fc879a0b9..3d6f69aee9210 100755 --- a/bitnami/moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -33,6 +33,12 @@ mysql_execute() { return "$failure" } +MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} +MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} +MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} +MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} + # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" failure=0 diff --git a/bitnami/moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh index dc95fc879a0b9..3d6f69aee9210 100755 --- a/bitnami/moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -33,6 +33,12 @@ mysql_execute() { return "$failure" } +MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} +MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} +MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} +MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} + # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" failure=0 diff --git a/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh index dc95fc879a0b9..a46dead824c4b 100755 --- a/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -21,7 +21,7 @@ fi mysql_execute() { local -r sql_file="${1:?missing file}" local failure=0 - mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER") + mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER" "-D" "${MARIADB_DATABASE}") if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then mysql_cmd+=("-p${MARIADB_ROOT_PASSWORD}") fi @@ -33,6 +33,12 @@ mysql_execute() { return "$failure" } +MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} +MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} +MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} +MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} + # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" failure=0 From 62d521e8b700ccb8ceea07d60cbbbb1b9809c70b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B8nskov=20Luther?= Date: Tue, 25 Jun 2024 11:24:17 +0200 Subject: [PATCH 2/6] Only set password if ALLOW_EMPTY_PASSWORDS is not set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Lønskov Luther --- bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh index a46dead824c4b..9a41e07e7ff01 100755 --- a/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -36,8 +36,11 @@ mysql_execute() { MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} -MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} +if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then + MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +fi + # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" From c90120e796f133cf71a7aeabef6ae55ef23b9928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B8nskov=20Luther?= Date: Wed, 3 Jul 2024 10:23:57 +0200 Subject: [PATCH 3/6] Allign scripts and enable all versions to connect to database if given --- .../debian-12/rootfs/post-init.d/sql-mysql.sh | 15 +++++++++------ .../debian-12/rootfs/post-init.d/sql-mysql.sh | 15 +++++++++------ .../debian-12/rootfs/post-init.d/sql-mysql.sh | 15 +++++++++------ .../debian-12/rootfs/post-init.d/sql-mysql.sh | 16 ++++++++-------- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/bitnami/moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh index 3d6f69aee9210..f9765d00be43c 100755 --- a/bitnami/moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.1/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -18,10 +18,18 @@ else . /opt/bitnami/scripts/liblog.sh fi +MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} +MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} +MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} +MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} +if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then + MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +fi + mysql_execute() { local -r sql_file="${1:?missing file}" local failure=0 - mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER") + mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER" "-D" "${MARIADB_DATABASE}") if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then mysql_cmd+=("-p${MARIADB_ROOT_PASSWORD}") fi @@ -33,11 +41,6 @@ mysql_execute() { return "$failure" } -MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} -MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} -MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} -MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} -MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" diff --git a/bitnami/moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh index 3d6f69aee9210..f9765d00be43c 100755 --- a/bitnami/moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.2/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -18,10 +18,18 @@ else . /opt/bitnami/scripts/liblog.sh fi +MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} +MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} +MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} +MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} +if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then + MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +fi + mysql_execute() { local -r sql_file="${1:?missing file}" local failure=0 - mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER") + mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER" "-D" "${MARIADB_DATABASE}") if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then mysql_cmd+=("-p${MARIADB_ROOT_PASSWORD}") fi @@ -33,11 +41,6 @@ mysql_execute() { return "$failure" } -MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} -MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} -MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} -MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} -MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" diff --git a/bitnami/moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh index 3d6f69aee9210..f9765d00be43c 100755 --- a/bitnami/moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.3/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -18,10 +18,18 @@ else . /opt/bitnami/scripts/liblog.sh fi +MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} +MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} +MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} +MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} +if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then + MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +fi + mysql_execute() { local -r sql_file="${1:?missing file}" local failure=0 - mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER") + mysql_cmd=("mysql" "-h" "$MARIADB_HOST" "-P" "$MARIADB_PORT_NUMBER" "-u" "$MARIADB_ROOT_USER" "-D" "${MARIADB_DATABASE}") if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then mysql_cmd+=("-p${MARIADB_ROOT_PASSWORD}") fi @@ -33,11 +41,6 @@ mysql_execute() { return "$failure" } -MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} -MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} -MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} -MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} -MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" diff --git a/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh b/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh index 9a41e07e7ff01..f9765d00be43c 100755 --- a/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh +++ b/bitnami/moodle/4.4/debian-12/rootfs/post-init.d/sql-mysql.sh @@ -18,6 +18,14 @@ else . /opt/bitnami/scripts/liblog.sh fi +MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} +MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} +MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} +MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} +if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then + MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} +fi + mysql_execute() { local -r sql_file="${1:?missing file}" local failure=0 @@ -33,14 +41,6 @@ mysql_execute() { return "$failure" } -MARIADB_HOST=${MARIADB_HOST:-$MOODLE_DATABASE_HOST} -MARIADB_PORT_NUMBER=${MARIADB_PORT_NUMBER:-$MOODLE_DATABASE_PORT_NUMBER} -MARIADB_ROOT_USER=${MARIADB_ROOT_USER:-$MOODLE_DATABASE_USER} -MARIADB_DATABASE=${MARIADB_DATABASE:-$MOODLE_DATABASE_NAME} -if [[ "${ALLOW_EMPTY_PASSWORD:-no}" != "yes" ]]; then - MARIADB_ROOT_PASSWORD=${MARIADB_ROOT_PASSWORD:-$MOODLE_DATABASE_PASSWORD} -fi - # Loop through all input files passed via stdin read -r -a custom_init_scripts <<< "$@" From 4074201f921622d471f8baee68780474baec5015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B8nskov=20Luther?= Date: Wed, 7 Aug 2024 13:01:58 +0200 Subject: [PATCH 4/6] Add support for running scripts on primary node every time container is started (#70606) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Lønskov Luther --- .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + bitnami/postgresql-repmgr/README.md | 1 + 16 files changed, 216 insertions(+) diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/README.md b/bitnami/postgresql-repmgr/README.md index f10af7233a658..b63056aa67bf9 100644 --- a/bitnami/postgresql-repmgr/README.md +++ b/bitnami/postgresql-repmgr/README.md @@ -674,6 +674,7 @@ Refer to [issues/27124](https://github.com/bitnami/containers/issues/27124) for | `POSTGRESQL_PID_FILE` | PostgreSQL PID file | `$POSTGRESQL_TMP_DIR/postgresql.pid` | | `POSTGRESQL_BIN_DIR` | PostgreSQL executables directory | `$POSTGRESQL_BASE_DIR/bin` | | `POSTGRESQL_INITSCRIPTS_DIR` | Init scripts directory | `/docker-entrypoint-initdb.d` | +| `POSTGRESQL_STARTSCRIPTS_DIR` | Start scripts directory | `/docker-entrypoint-startdb.d` | | `POSTGRESQL_PREINITSCRIPTS_DIR` | Pre-init scripts directory | `/docker-entrypoint-preinitdb.d` | | `POSTGRESQL_DAEMON_USER` | PostgreSQL system user | `postgres` | | `POSTGRESQL_DAEMON_GROUP` | PostgreSQL system group | `postgres` | From 87e85983d561079e2546fc0842f3f8a605422f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B8nskov=20Luther?= Date: Wed, 7 Aug 2024 13:01:58 +0200 Subject: [PATCH 5/6] Add support for running scripts on primary node every time container is started (#70606) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Lønskov Luther --- .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + bitnami/postgresql-repmgr/README.md | 1 + 16 files changed, 216 insertions(+) diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/README.md b/bitnami/postgresql-repmgr/README.md index f10af7233a658..b63056aa67bf9 100644 --- a/bitnami/postgresql-repmgr/README.md +++ b/bitnami/postgresql-repmgr/README.md @@ -674,6 +674,7 @@ Refer to [issues/27124](https://github.com/bitnami/containers/issues/27124) for | `POSTGRESQL_PID_FILE` | PostgreSQL PID file | `$POSTGRESQL_TMP_DIR/postgresql.pid` | | `POSTGRESQL_BIN_DIR` | PostgreSQL executables directory | `$POSTGRESQL_BASE_DIR/bin` | | `POSTGRESQL_INITSCRIPTS_DIR` | Init scripts directory | `/docker-entrypoint-initdb.d` | +| `POSTGRESQL_STARTSCRIPTS_DIR` | Start scripts directory | `/docker-entrypoint-startdb.d` | | `POSTGRESQL_PREINITSCRIPTS_DIR` | Pre-init scripts directory | `/docker-entrypoint-preinitdb.d` | | `POSTGRESQL_DAEMON_USER` | PostgreSQL system user | `postgres` | | `POSTGRESQL_DAEMON_GROUP` | PostgreSQL system group | `postgres` | From 31039aa8f98bd423afbd7c1b08c10631e5b72bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=B8nskov=20Luther?= Date: Wed, 7 Aug 2024 13:01:58 +0200 Subject: [PATCH 6/6] Add support for running scripts on primary node every time container is started (#70606) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Lønskov Luther --- .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + .../opt/bitnami/scripts/libpostgresql.sh | 40 +++++++++++++++++++ .../rootfs/opt/bitnami/scripts/librepmgr.sh | 2 + .../opt/bitnami/scripts/postgresql-env.sh | 1 + bitnami/postgresql-repmgr/README.md | 1 + 16 files changed, 216 insertions(+) diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh index a1c28111e0ead..5fcf17c6f1aa9 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh @@ -705,6 +705,46 @@ postgresql_custom_pre_init_scripts() { fi } +######################## +# Run custom start scripts +# Globals: +# POSTGRESQL_* +# Arguments: +# None +# Returns: +# None +######################### +postgresql_custom_start_scripts() { + info "Loading custom start scripts..." + if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then + info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..." + postgresql_start_bg "false" + find "$POSTGRESQL_STARTSCRIPTS_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_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 + fi +} + ######################## # Run custom initialization scripts # Globals: diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index e5d602cfbd464..826d8de802083 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -864,6 +864,8 @@ repmgr_initialize() { else debug "Skipping repmgr configuration..." fi + # Allow running custom start scripts - always run after initialization + postgresql_custom_start_scripts elif [[ "$REPMGR_ROLE" = "standby" ]]; then local -r psql_major_version="$(postgresql_get_major_version)" diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh index 09a963b32c2ba..806c8827517bc 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh @@ -231,6 +231,7 @@ 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_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d" export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d" export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}" diff --git a/bitnami/postgresql-repmgr/README.md b/bitnami/postgresql-repmgr/README.md index f10af7233a658..b63056aa67bf9 100644 --- a/bitnami/postgresql-repmgr/README.md +++ b/bitnami/postgresql-repmgr/README.md @@ -674,6 +674,7 @@ Refer to [issues/27124](https://github.com/bitnami/containers/issues/27124) for | `POSTGRESQL_PID_FILE` | PostgreSQL PID file | `$POSTGRESQL_TMP_DIR/postgresql.pid` | | `POSTGRESQL_BIN_DIR` | PostgreSQL executables directory | `$POSTGRESQL_BASE_DIR/bin` | | `POSTGRESQL_INITSCRIPTS_DIR` | Init scripts directory | `/docker-entrypoint-initdb.d` | +| `POSTGRESQL_STARTSCRIPTS_DIR` | Start scripts directory | `/docker-entrypoint-startdb.d` | | `POSTGRESQL_PREINITSCRIPTS_DIR` | Pre-init scripts directory | `/docker-entrypoint-preinitdb.d` | | `POSTGRESQL_DAEMON_USER` | PostgreSQL system user | `postgres` | | `POSTGRESQL_DAEMON_GROUP` | PostgreSQL system group | `postgres` |