Skip to content

Commit fbd9ead

Browse files
committed
feat(postgresql-repmgr): Add support for startup scripts
1 parent bfd1685 commit fbd9ead

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

bitnami/postgresql-repmgr/17/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,46 @@ postgresql_initialize() {
747747
postgresql_stop
748748
}
749749

750+
########################
751+
# Run custom start scripts
752+
# Globals:
753+
# POSTGRESQL_*
754+
# Arguments:
755+
# None
756+
# Returns:
757+
# None
758+
#########################
759+
postgresql_custom_start_scripts() {
760+
info "Loading custom start scripts..."
761+
if [[ -d "$POSTGRESQL_STARTSCRIPTS_DIR" ]] && [[ -n $(find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)") ]] ; then
762+
info "Loading user's custom files from $POSTGRESQL_STARTSCRIPTS_DIR ..."
763+
postgresql_start_bg "false"
764+
find "$POSTGRESQL_STARTSCRIPTS_DIR/" -type f -regex ".*\.\(sh\|sql\|sql.gz\)" | sort | while read -r f; do
765+
case "$f" in
766+
*.sh)
767+
if [[ -x "$f" ]]; then
768+
debug "Executing $f"
769+
"$f"
770+
else
771+
debug "Sourcing $f"
772+
. "$f"
773+
fi
774+
;;
775+
*.sql)
776+
debug "Executing $f"
777+
postgresql_execute "$POSTGRESQL_DATABASE" "$POSTGRESQL_INITSCRIPTS_USERNAME" "$POSTGRESQL_INITSCRIPTS_PASSWORD" <"$f"
778+
;;
779+
*.sql.gz)
780+
debug "Executing $f"
781+
gunzip -c "$f" | postgresql_execute "$POSTGRESQL_DATABASE" "$POSTGRESQL_INITSCRIPTS_USERNAME" "$POSTGRESQL_INITSCRIPTS_PASSWORD"
782+
;;
783+
*) debug "Ignoring $f" ;;
784+
esac
785+
done
786+
touch "$POSTGRESQL_VOLUME_DIR"/.user_scripts_initialized
787+
fi
788+
}
789+
750790
########################
751791
# Run custom pre-initialization scripts
752792
# Globals:

bitnami/postgresql-repmgr/17/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,8 @@ repmgr_initialize() {
895895
else
896896
debug "Skipping repmgr configuration..."
897897
fi
898+
# Allow running custom start scripts - always run after initialization
899+
postgresql_custom_start_scripts
898900
elif [[ "$REPMGR_ROLE" = "standby" ]]; then
899901
local -r psql_major_version="$(postgresql_get_major_version)"
900902

bitnami/postgresql-repmgr/17/debian-12/rootfs/opt/bitnami/scripts/postgresql-env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export POSTGRESQL_TMP_DIR="$POSTGRESQL_BASE_DIR/tmp"
242242
export POSTGRESQL_PID_FILE="$POSTGRESQL_TMP_DIR/postgresql.pid"
243243
export POSTGRESQL_BIN_DIR="$POSTGRESQL_BASE_DIR/bin"
244244
export POSTGRESQL_INITSCRIPTS_DIR="/docker-entrypoint-initdb.d"
245+
export POSTGRESQL_STARTSCRIPTS_DIR="/docker-entrypoint-startdb.d"
245246
export POSTGRESQL_PREINITSCRIPTS_DIR="/docker-entrypoint-preinitdb.d"
246247
export PATH="${POSTGRESQL_BIN_DIR}:${BITNAMI_ROOT_DIR}/common/bin:${PATH}"
247248

bitnami/postgresql-repmgr/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ Refer to [issues/27124](https://github.com/bitnami/containers/issues/27124) for
685685
| `POSTGRESQL_PID_FILE` | PostgreSQL PID file | `$POSTGRESQL_TMP_DIR/postgresql.pid` |
686686
| `POSTGRESQL_BIN_DIR` | PostgreSQL executables directory | `$POSTGRESQL_BASE_DIR/bin` |
687687
| `POSTGRESQL_INITSCRIPTS_DIR` | Init scripts directory | `/docker-entrypoint-initdb.d` |
688+
| `POSTGRESQL_STARTSCRIPTS_DIR` | Start scripts directory | `/docker-entrypoint-startdb.d` |
688689
| `POSTGRESQL_PREINITSCRIPTS_DIR` | Pre-init scripts directory | `/docker-entrypoint-preinitdb.d` |
689690
| `POSTGRESQL_DAEMON_USER` | PostgreSQL system user | `postgres` |
690691
| `POSTGRESQL_DAEMON_GROUP` | PostgreSQL system group | `postgres` |

0 commit comments

Comments
 (0)