diff --git a/pgsql11-primary-centos7/Dockerfile b/pgsql11-primary-centos7/Dockerfile index 7613322..96ea065 100644 --- a/pgsql11-primary-centos7/Dockerfile +++ b/pgsql11-primary-centos7/Dockerfile @@ -34,6 +34,7 @@ ENV PGROOT="/usr/pgsql-${PGVERSION}" RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \ && rpm -Uvh https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm \ + && yum -y install wget tar \ && yum -y update \ && yum -y install postgresql11 postgresql11-server postgresql11-contrib postgresql11-libs \ && yum -y clean all @@ -45,9 +46,18 @@ COPY conf/* /conf/ RUN chown -R postgres:postgres /conf /pgconf /pgdata /pgwal RUN chmod 700 /conf /pgconf /pgdata /pgwal +RUN mkdir -p /usr/local/bin +RUN cd /tmp \ + && wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz \ + && tar xzf node_exporter-0.18.0.linux-amd64.tar.gz \ + && mv node_exporter-0.18.0.linux-amd64/node_exporter /usr/local/bin/node_exporter \ + && rm -Rf node_exporter-0.18.0.linux-amd64 node_exporter-0.18.0.linux-amd64.tar.gz \ + && chown postgres:postgres /usr/local/bin/node_exporter + VOLUME ["/pgconf", "/pgdata", "/pgwal"] EXPOSE 5432 +EXPOSE 9100 USER 26 diff --git a/pgsql11-primary-centos7/README.md b/pgsql11-primary-centos7/README.md index f7cdcab..6900747 100644 --- a/pgsql11-primary-centos7/README.md +++ b/pgsql11-primary-centos7/README.md @@ -9,7 +9,7 @@ This project contains the PostgreSQL Primary image. make build # Run, and register the container under postgresql-primary -podman run -p 5432:5432 --name postgresql-primary -d -e PG_DATABASE=mydb -e PG_USER_NAME=myuser -e PG_USER_PASSWORD=mypass -e PG_REPLICATION_NAME=repl -e PG_REPLICATION_PASSWORD=replpass -e PG_NETWORK_MASK=all pgsql11-primary-centos7 +podman run -p 5432:5432 -p 9100:9100 --name postgresql-primary -d -e PG_DATABASE=mydb -e PG_USER_NAME=myuser -e PG_USER_PASSWORD=mypass -e PG_REPLICATION_NAME=repl -e PG_REPLICATION_PASSWORD=replpass -e PG_NETWORK_MASK=all pgsql11-primary-centos7 # psql to postgresql-primary psql -h localhost -p 5432 -U myuser mydb diff --git a/pgsql11-primary-centos7/root/usr/bin/run-postgresql b/pgsql11-primary-centos7/root/usr/bin/run-postgresql index 66b90c4..702d278 100755 --- a/pgsql11-primary-centos7/root/usr/bin/run-postgresql +++ b/pgsql11-primary-centos7/root/usr/bin/run-postgresql @@ -21,6 +21,14 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +NODE_EXPORTER_PIDFILE=/tmp/node_exporter.pid + +function trap_sigterm() { + kill -SIGINT $(head -1 $NODE_EXPORTER_PIDFILE) +} + +trap 'trap_sigterm' SIGINT SIGTERM + if [ ! -f /pgdata/PG_VERSION ]; then export PG_MAX_CONNECTIONS=${PG_MAX_CONNECTIONS:-100} export PG_SHARED_BUFFERS=${PG_SHARED_BUFFERS:-256} @@ -104,4 +112,7 @@ if [ ! -f /pgdata/PG_VERSION ]; then /usr/pgsql-11/bin/pg_ctl -D /pgdata/ stop fi +/usr/local/bin/node_exporter >> /tmp/node_exporter.log 2>&1 & +echo $! > $NODE_EXPORTER_PIDFILE + exec /usr/pgsql-11/bin/postgres -D /pgdata/ "$@" diff --git a/pgsql11-replica-centos7/Dockerfile b/pgsql11-replica-centos7/Dockerfile index 71eab72..56bc2c5 100644 --- a/pgsql11-replica-centos7/Dockerfile +++ b/pgsql11-replica-centos7/Dockerfile @@ -34,6 +34,7 @@ ENV PGROOT="/usr/pgsql-${PGVERSION}" RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \ && rpm -Uvh https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm \ + && yum -y install wget tar \ && yum -y update \ && yum -y install postgresql11 postgresql11-server postgresql11-contrib postgresql11-libs \ && yum -y clean all @@ -45,9 +46,18 @@ COPY conf/* /conf/ RUN chown -R postgres:postgres /conf /pgconf /pgdata /pgwal RUN chmod 700 /conf /pgconf /pgdata /pgwal +RUN mkdir -p /usr/local/bin +RUN cd /tmp \ + && wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz \ + && tar xzf node_exporter-0.18.0.linux-amd64.tar.gz \ + && mv node_exporter-0.18.0.linux-amd64/node_exporter /usr/local/bin/node_exporter \ + && rm -Rf node_exporter-0.18.0.linux-amd64 node_exporter-0.18.0.linux-amd64.tar.gz \ + && chown postgres:postgres /usr/local/bin/node_exporter + VOLUME ["/pgconf", "/pgdata", "/pgwal"] EXPOSE 5432 +EXPOSE 9100 USER 26 diff --git a/pgsql11-replica-centos7/README.md b/pgsql11-replica-centos7/README.md index f1fde21..f988095 100644 --- a/pgsql11-replica-centos7/README.md +++ b/pgsql11-replica-centos7/README.md @@ -9,7 +9,7 @@ This project contains the PostgreSQL Replica image. make build # Run, and register the container under postgresql-replica -podman run -p 5433:5432 --name postgresql-replica -d -e PG_MASTER=192.168.1.2 -e PG_REPLICATION_NAME=repl -e PG_REPLICATION_PASSWORD=replpass -e PG_SLOT_NAME=replica1 pgsql11-replica-centos7 +podman run -p 5433:5432 -p 9101:9100 --name postgresql-replica -d -e PG_MASTER=192.168.1.2 -e PG_REPLICATION_NAME=repl -e PG_REPLICATION_PASSWORD=replpass -e PG_SLOT_NAME=replica1 pgsql11-replica-centos7 # psql to postgresql-replica psql -h localhost -p 5433 -U myuser -c 'SELECT pg_is_in_recovery();' mydb diff --git a/pgsql11-replica-centos7/root/usr/bin/run-postgresql b/pgsql11-replica-centos7/root/usr/bin/run-postgresql index ddbf6cf..922a28d 100755 --- a/pgsql11-replica-centos7/root/usr/bin/run-postgresql +++ b/pgsql11-replica-centos7/root/usr/bin/run-postgresql @@ -21,6 +21,14 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +NODE_EXPORTER_PIDFILE=/tmp/node_exporter.pid + +function trap_sigterm() { + kill -SIGINT $(head -1 $NODE_EXPORTER_PIDFILE) +} + +trap 'trap_sigterm' SIGINT SIGTERM + if [ ! -f /pgdata/PG_VERSION ]; then export PG_MASTER=${PG_MASTER} export PG_REPLICATION_NAME=${PG_REPLICATION_NAME} @@ -56,4 +64,7 @@ if [ ! -f /pgdata/PG_VERSION ]; then cp /conf/recovery.conf /pgdata/ fi +/usr/local/bin/node_exporter >> /tmp/node_exporter.log 2>&1 & +echo $! > $NODE_EXPORTER_PIDFILE + exec /usr/pgsql-11/bin/postgres -D /pgdata/ "$@"