2503bedb by Adam Heath

Add user authentication checking to pg_isready.

1 parent 1f59c12f
1 #!/bin/sh 1 #!/bin/sh
2 set -ex 2 set -ex
3 3
4 # POSTGRES_HOST
5 # POSTGRES_USER
6 # POSTGRES_DATABASE
7 # PGPASSWORD
8
4 check_pg() { 9 check_pg() {
5 pg_isready -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" -p 5432 10 pg_isready -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}"
11 }
12
13 check_auth() {
14 psql -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" "${POSTGRES_DATABASE}"
6 } 15 }
7 16
8 while ! check_pg; do 17 loop() {
9 echo "Waiting for database" 1>&2 18 checker="$1"
19 message="$2"
20 while ! $checker; do
21 echo "$message" 1>&2
10 sleep 1 22 sleep 1
11 count=5 23 count=5
12 while [ $count -gt 0 ] && ! check_pg; do 24 while [ $count -gt 0 ] && ! $checker; do
13 count=$(($count - 1)) 25 count=$(($count - 1))
14 sleep 1 26 sleep 1
15 done 27 done
16 done 28 done
29 }
30
31 loop check_pg "Waiting for database to be up"
32 loop check_auth "Waiting for user+password to be active"
......
...@@ -113,6 +113,8 @@ releases: ...@@ -113,6 +113,8 @@ releases:
113 - name: postgresql-scripts 113 - name: postgresql-scripts
114 mountPath: /postgresql-scripts 114 mountPath: /postgresql-scripts
115 env: 115 env:
116 - name: POSTGRES_DATABASE
117 value: moqui
116 - name: POSTGRES_HOST 118 - name: POSTGRES_HOST
117 value: {{ .Values.name }}-moqui-postgresql 119 value: {{ .Values.name }}-moqui-postgresql
118 - name: POSTGRES_USER 120 - name: POSTGRES_USER
...@@ -120,6 +122,11 @@ releases: ...@@ -120,6 +122,11 @@ releases:
120 secretKeyRef: 122 secretKeyRef:
121 name: moqui.{{ .Values.name }}-moqui-postgresql.credentials.postgresql.acid.zalan.do 123 name: moqui.{{ .Values.name }}-moqui-postgresql.credentials.postgresql.acid.zalan.do
122 key: username 124 key: username
125 - name: PGPASSWORD
126 valueFrom:
127 secretKeyRef:
128 name: moqui.{{ .Values.name }}-moqui-postgresql.credentials.postgresql.acid.zalan.do
129 key: password
123 {{- end }} 130 {{- end }}
124 {{- if .Values.elasticsearch.enabled }} 131 {{- if .Values.elasticsearch.enabled }}
125 - op: add 132 - op: add
......