From ce7fdbbad77fb29e724f07321684ec056b1034f5 Mon Sep 17 00:00:00 2001 From: Franco Bladilo Date: Fri, 21 Jul 2017 11:21:01 -0400 Subject: [PATCH 1/3] Allow MIQ PG config overrides to be included - Check for the existance of MIQ PG overrides, if available, include them in postgresql.conf - Defaults taken from https://github.com/ManageIQ/manageiq-appliance/blob/master/COPY/etc/manageiq/postgresql.conf.d/01_miq_overrides.conf - We use include_dir , so more configs can be stacked, PG will process *.conf in a given dir - POSTGRESQL_CONFIG_DIR is set via environment variable and can be customized at users convenience - Can be backported to euwe/4.5 builds to allow functionality to existing users --- docker-assets/run-postgresql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docker-assets/run-postgresql b/docker-assets/run-postgresql index a243f99..7843df5 100755 --- a/docker-assets/run-postgresql +++ b/docker-assets/run-postgresql @@ -12,6 +12,19 @@ function set_miq_role() { psql --command "ALTER ROLE \"${POSTGRESQL_USER}\" SUPERUSER LOGIN PASSWORD '${POSTGRESQL_PASSWORD}';" } +# Include MIQ config overrides if directory present +function include_miq_config() { + POSTGRESQL_CONFIG_DIR=${POSTGRESQL_CONFIG_DIR:-/etc/manageiq/postgresql.conf.d} + if [ -d "${POSTGRESQL_CONFIG_DIR}" ]; then + cat >> "$PGDATA/postgresql.conf" < Date: Mon, 24 Jul 2017 16:41:31 -0400 Subject: [PATCH 2/3] Check before writing postgresql.conf and other fixes - Added a check to avoid creating multiple entries of the same config during reschedules - Create default directory location for PG_CONFIG_DIR on image not on scripts - Change default location for PG_CONFIG_DIR to a known writable location (avoid /etc) --- Dockerfile | 6 +++++- docker-assets/run-postgresql | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4ba8145..0dbc76a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,9 @@ FROM centos/postgresql-95-centos7 MAINTAINER ManageIQ https://github.com/ManageIQ/manageiq-appliance-build +# Include config PG dir +ARG PG_CONF_DIR=/var/lib/pgsql/conf.d + # Switch USER to root to add required repo and packages USER root @@ -22,7 +25,8 @@ LABEL io.openshift.tags="database,postgresql,postgresql95,rh-postgresql95,pglogi COPY docker-assets/run-postgresql /usr/bin # Loosen permission bits to avoid problems running container with arbitrary UID -RUN /usr/libexec/fix-permissions /var/lib/pgsql && \ +RUN mkdir ${PG_CONF_DIR} && \ + /usr/libexec/fix-permissions /var/lib/pgsql && \ /usr/libexec/fix-permissions /var/run/postgresql # Switch USER back to postgres diff --git a/docker-assets/run-postgresql b/docker-assets/run-postgresql index 7843df5..3b7cb6c 100755 --- a/docker-assets/run-postgresql +++ b/docker-assets/run-postgresql @@ -14,14 +14,19 @@ function set_miq_role() { # Include MIQ config overrides if directory present function include_miq_config() { - POSTGRESQL_CONFIG_DIR=${POSTGRESQL_CONFIG_DIR:-/etc/manageiq/postgresql.conf.d} - if [ -d "${POSTGRESQL_CONFIG_DIR}" ]; then + # Set and create default dir if POSTGRESQL_CONFIG_DIR is not defined, compatible with older builds + POSTGRESQL_CONFIG_DIR=${POSTGRESQL_CONFIG_DIR:-/var/lib/pgsql/conf.d} + + # Check for POSTGRESQL_CONFIG_DIR presence in postgresql.conf, if already there skip. + [[ $(grep ${POSTGRESQL_CONFIG_DIR} ${PGDATA}/postgresql.conf) ]] && RET=$? || RET=$? + if [[ $RET == "0" ]]; then + echo "${POSTGRESQL_CONFIG_DIR} already exists on ${PGDATA}/postgresql.conf, skipping.." + else + echo "Writing ${POSTGRESQL_CONFIG_DIR} config directory to ${PGDATA}/postgresql.conf" cat >> "$PGDATA/postgresql.conf" < Date: Mon, 24 Jul 2017 18:11:13 -0400 Subject: [PATCH 3/3] Cleanup/improve grep call --- docker-assets/run-postgresql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-assets/run-postgresql b/docker-assets/run-postgresql index 3b7cb6c..1c44fd7 100755 --- a/docker-assets/run-postgresql +++ b/docker-assets/run-postgresql @@ -18,8 +18,7 @@ function include_miq_config() { POSTGRESQL_CONFIG_DIR=${POSTGRESQL_CONFIG_DIR:-/var/lib/pgsql/conf.d} # Check for POSTGRESQL_CONFIG_DIR presence in postgresql.conf, if already there skip. - [[ $(grep ${POSTGRESQL_CONFIG_DIR} ${PGDATA}/postgresql.conf) ]] && RET=$? || RET=$? - if [[ $RET == "0" ]]; then + if [[ $(grep ${POSTGRESQL_CONFIG_DIR} ${PGDATA}/postgresql.conf) && $? -eq 0 ]]; then echo "${POSTGRESQL_CONFIG_DIR} already exists on ${PGDATA}/postgresql.conf, skipping.." else echo "Writing ${POSTGRESQL_CONFIG_DIR} config directory to ${PGDATA}/postgresql.conf"