From 42be2693c5073726efd9977bcc02d1029cd8fbd2 Mon Sep 17 00:00:00 2001 From: Rizky Maulana Nugraha Date: Fri, 1 Feb 2019 21:16:59 +0700 Subject: [PATCH] Implement conf lock file check (#116) It will make sure that the conf file will only be generated once for a given container. --- .dockerignore | 1 + setup-conf.sh | 7 +++++++ setup-pg_hba.sh | 8 ++++++++ setup-ssl.sh | 10 +++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 120000 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/setup-conf.sh b/setup-conf.sh index b5cf4b3..6de4912 100644 --- a/setup-conf.sh +++ b/setup-conf.sh @@ -2,6 +2,11 @@ source /env-data.sh +SETUP_LOCKFILE="${ROOT_CONF}/.postgresql.conf.lock" +if [ -f "${SETUP_LOCKFILE}" ]; then + return 0 +fi + # This script will setup necessary configuration to enable replications # Refresh configuration in case environment settings changed. @@ -32,3 +37,5 @@ EOF echo "kernel.shmmax=543252480" >> /etc/sysctl.conf echo "kernel.shmall=2097152" >> /etc/sysctl.conf +# Put lock file to make sure conf was not reinitialized +touch ${SETUP_LOCKFILE} diff --git a/setup-pg_hba.sh b/setup-pg_hba.sh index 69e46eb..d271f77 100644 --- a/setup-pg_hba.sh +++ b/setup-pg_hba.sh @@ -2,6 +2,11 @@ source /env-data.sh +SETUP_LOCKFILE="${ROOT_CONF}/.pg_hba.conf.lock" +if [ -f "${SETUP_LOCKFILE}" ]; then + return 0 +fi + # This script will setup pg_hba.conf # Reconfigure pg_hba if environment settings changed @@ -46,3 +51,6 @@ if [[ -z "$REPLICATE_FROM" ]]; then echo "Add rule to pg_hba: replication user" echo "host replication all 0.0.0.0/0 $authMethod" >> ${ROOT_CONF}/pg_hba.conf fi + +# Put lock file to make sure conf was not reinitialized +touch ${SETUP_LOCKFILE} diff --git a/setup-ssl.sh b/setup-ssl.sh index b9844e7..50eae85 100644 --- a/setup-ssl.sh +++ b/setup-ssl.sh @@ -2,6 +2,11 @@ source /env-data.sh +SETUP_LOCKFILE="${ROOT_CONF}/.ssl.conf.lock" +if [ -f "${SETUP_LOCKFILE}" ]; then + return 0 +fi + # This script will setup default SSL config # /etc/ssl/private can't be accessed from within container for some reason @@ -23,4 +28,7 @@ echo "ssl = true" >> $CONF echo "ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'" >> $CONF echo "ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'" >> $CONF #echo "ssl_ca_file = '' # (change requires restart)" >> $CONF -#echo "ssl_crl_file = ''" >> $CONF \ No newline at end of file +#echo "ssl_crl_file = ''" >> $CONF + +# Put lock file to make sure conf was not reinitialized +touch ${SETUP_LOCKFILE}