postgresql

This commit is contained in:
f 2019-09-24 14:04:19 -03:00
parent a2e27c5316
commit 747ed5a2cc
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
3 changed files with 60 additions and 1 deletions

View file

@ -1,2 +1,24 @@
FROM sutty/monit:latest
FROM sutty/daemonize:latest AS build
MAINTAINER "f <f@sutty.nl>"
RUN echo /home/builder/packages/home > /etc/apk/repositories
RUN apk add --no-cache daemonize
FROM sutty/monit:latest
ENV PGDATA /var/lib/postgresql/11/data
ENV LANG en_US.utf8
ENV PGUSER sutty
ENV PGDB sutty
ENV PGVER 11
RUN apk add --no-cache postgresql postgresql-contrib
COPY --from=build /usr/sbin/daemonize /usr/sbin/daemonize
COPY ./postgresql.sh /usr/local/bin/postgresql
COPY ./monit.conf /etc/monit.d/postgresql.conf
RUN chmod 750 /usr/local/bin/postgresql
EXPOSE 5432
VOLUME $PGDATA

4
monit.conf Normal file
View file

@ -0,0 +1,4 @@
check process postgresql with pidfile /tmp/postgresql.pid
start program = "/usr/local/bin/postgresql start"
stop program = "/usr/local/bin/postgresql stop"
if failed port 5432 protocol pgsql for 3 times within 5 cycles then restart

33
postgresql.sh Normal file
View file

@ -0,0 +1,33 @@
#!/bin/sh
set -e
case $1 in
stop)
/bin/su postgres -c "pg_ctl stop -D ${PGDATA}" ;;
*)
pid=/tmp/postgresql.pid
user=postgres
log=${PGDATA}/postgresql.log
install -dm 2750 -o postgres -g postgres /run/postgresql
chown -R postgres:postgres /var/lib/postgresql
if test ! -f ${PGDATA}/PG_VERSION ; then
su - postgres -c "/usr/bin/initdb --locale ${LANG} -E UTF8 -D ${PGDATA}"
su - postgres -c "/usr/bin/pg_ctl start --pgdata ${PGDATA}"
su - postgres -c "/usr/bin/createuser --login ${PGUSER}"
su - postgres -c "/usr/bin/createdb --owner ${PGUSER} ${PGDB}"
su - postgres -c "/usr/bin/pg_ctl stop --pgdata ${PGDATA}"
echo "host ${PGDB} ${PGUSER} samenet trust" >> ${PGDATA}/pg_hba.conf
echo "host ${PGDB}_test ${PGUSER} samenet trust" >> ${PGDATA}/pg_hba.conf
echo "listen_addresses = '*'" >> ${PGDATA}/postgresql.conf
echo "external_pid_file = '${pid}'" >> ${PGDATA}/postgresql.conf
fi
rm -f ${pid}
daemonize -u ${user} -c ${PGDATA} -o ${log} -a -e ${log} \
/usr/bin/postgres
;;
esac