Skip to content

Commit 462c738

Browse files
committed
Merge branch 'v9.6.13-1'
2 parents 7e4669d + e3ad097 commit 462c738

File tree

2 files changed

+65
-33
lines changed

2 files changed

+65
-33
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -15,3 +16,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1516
### Changed
1617

1718
* updated gosu to version from 1.2 to 1.10
19+
* Recreate the pg_hba.conf file on each dogu start to keep up with
20+
network changes

resources/startup.sh

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,42 @@ set -o pipefail
66
function mask2cidr() {
77
NBITS=0
88
IFS=.
9-
for DEC in $1 ; do
9+
for DEC in $1; do
1010
case $DEC in
11-
255) let NBITS+=8;;
12-
254) let NBITS+=7 ; break ;;
13-
252) let NBITS+=6 ; break ;;
14-
248) let NBITS+=5 ; break ;;
15-
240) let NBITS+=4 ; break ;;
16-
224) let NBITS+=3 ; break ;;
17-
192) let NBITS+=2 ; break ;;
18-
128) let NBITS+=1 ; break ;;
19-
0);;
20-
*) echo "Error: ${DEC} is not recognised"; exit 1
11+
255) let NBITS+=8 ;;
12+
254)
13+
let NBITS+=7
14+
break
15+
;;
16+
252)
17+
let NBITS+=6
18+
break
19+
;;
20+
248)
21+
let NBITS+=5
22+
break
23+
;;
24+
240)
25+
let NBITS+=4
26+
break
27+
;;
28+
224)
29+
let NBITS+=3
30+
break
31+
;;
32+
192)
33+
let NBITS+=2
34+
break
35+
;;
36+
128)
37+
let NBITS+=1
38+
break
39+
;;
40+
0) ;;
41+
*)
42+
echo "Error: ${DEC} is not recognised"
43+
exit 1
44+
;;
2145
esac
2246
done
2347
echo "${NBITS}"
@@ -40,45 +64,45 @@ function create_hba() {
4064
done
4165
}
4266

43-
function initializePostgreSQL() {
44-
45-
# set stage for health check
46-
doguctl state installing
67+
function write_pg_hba_conf() {
68+
create_hba >"${PGDATA}"/pg_hba.conf
69+
}
4770

48-
# install database
49-
gosu postgres initdb
71+
function initializePostgreSQL() {
72+
# set stage for health check
73+
doguctl state installing
5074

51-
# postgres user
52-
POSTGRES_USER="postgres"
75+
# install database
76+
gosu postgres initdb
5377

54-
# store the user
55-
doguctl config user "${POSTGRES_USER}"
78+
# postgres user
79+
POSTGRES_USER="postgres"
5680

57-
# create random password
58-
POSTGRES_PASSWORD=$(doguctl random)
81+
# store the user
82+
doguctl config user "${POSTGRES_USER}"
5983

60-
# store the password encrypted
61-
doguctl config -e password "${POSTGRES_PASSWORD}"
84+
# create random password
85+
POSTGRES_PASSWORD=$(doguctl random)
6286

63-
# open port
64-
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
87+
# store the password encrypted
88+
doguctl config -e password "${POSTGRES_PASSWORD}"
6589

66-
# set generated password
67-
echo "ALTER USER ${POSTGRES_USER} WITH SUPERUSER PASSWORD '${POSTGRES_PASSWORD}';" | 2>/dev/null 1>&2 gosu postgres postgres --single -jE
90+
# open port
91+
sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
6892

69-
# generate pg_hba.conf
70-
create_hba > "${PGDATA}"/pg_hba.conf
93+
# set generated password
94+
echo "ALTER USER ${POSTGRES_USER} WITH SUPERUSER PASSWORD '${POSTGRES_PASSWORD}';" | gosu 2>/dev/null 1>&2 postgres postgres --single -jE
7195
}
7296

7397
function waitForPostgreSQLStartup() {
74-
while ! pg_isready > /dev/null; do
98+
while ! pg_isready >/dev/null; do
7599
# Postgres is not ready yet to accept connections
76100
sleep 0.1
77101
done
78102
}
79103

80104
function waitForPostgreSQLShutdown() {
81-
while pgrep -x postgres > /dev/null ; do
105+
while pgrep -x postgres >/dev/null; do
82106
# Postgres is still running
83107
sleep 0.1
84108
done
@@ -92,6 +116,7 @@ chown postgres:postgres /run/postgresql
92116

93117
if [ -z "$(ls -A "$PGDATA")" ]; then
94118
initializePostgreSQL
119+
write_pg_hba_conf
95120
elif [ -e "${PGDATA}"/postgresqlFullBackup.dump ]; then
96121
# Moving backup and emptying PGDATA directory
97122
mv "${PGDATA}"/postgresqlFullBackup.dump /tmp/postgresqlFullBackup.dump
@@ -115,6 +140,10 @@ elif [ -e "${PGDATA}"/postgresqlFullBackup.dump ]; then
115140
kill ${PID}
116141
waitForPostgreSQLShutdown
117142
echo "Database dump successfully restored"
143+
144+
write_pg_hba_conf
145+
else
146+
write_pg_hba_conf
118147
fi
119148

120149
# set stage for health check

0 commit comments

Comments
 (0)