8000 Updating to the changed initdb logic of the postgres container. · mbehrle/docker-gnuhealth-demo@dd54666 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd54666

Browse files
committed
Updating to the changed initdb logic of the postgres container.
- The new initdb logic of the postgres container broke the --single setup of our container. As the --single switch is deprecated by the postgres folks, this is the cleaner way anyway. - Simplifying the check for an existing gnuhealth database. Refs: - #2 - docker-library/postgres#75 - docker-library/postgres#78
1 parent b3d3396 commit dd54666

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

postgres-gnuhealth/gnuhealth.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,30 @@ fi
1111
: ${DB_ENCODING:=UTF-8}
1212
: ${DB_DUMPFILE:=/demo.sql.gz}
1313

14+
# Perform all actions as user 'postgres'
15+
export PGUSER=postgres
16+
1417
# Test if the gnuhealth database already exists
15-
INIT=$(gosu postgres postgres --single -j <<-EOSQL
18+
echo "Checking for existing database..."
19+
INIT=$(psql -d template1 -t <<-EOSQL
1620
SELECT COUNT(*) from pg_database where datname = '$GNUHEALTH_DB';
1721
EOSQL
1822
)
19-
if [ `expr "${INIT}" : '.*count = "\([0-9]\).*'` == "0" ]; then
23+
INIT="$(echo "$INIT" | sed -e 's/^[ \t]*//;s/[ \t]*$//')"
24+
25+
if [ "${INIT}" == "0" ]; then
2026
echo "Creating the gnuhealth role..."
21-
gosu postgres postgres --single -jE <<-EOSQL
27+
psql <<-EOSQL
2228
CREATE USER $GNUHEALTH_USER WITH NOSUPERUSER NOINHERIT CREATEDB NOCREATEROLE NOREPLICATION $PASS;
2329
EOSQL
2430
echo
2531
echo "Creating the gnuhealth database..."
26-
gosu postgres postgres --single -jE <<-EOSQL
32+
psql <<-EOSQL
2733
CREATE DATABASE $GNUHEALTH_DB WITH OWNER $GNUHEALTH_USER ENCODING='$DB_ENCODING';
2834
EOSQL
2935
echo
3036
echo "Importing the gnuhealth database..."
31-
{ gosu postgres pg_ctl start -w && gosu postgres gunzip -c "$DB_DUMPFILE" | psql -U postgres -d "$GNUHEALTH_DB" && gosu postgres pg_ctl stop -w; }
37+
{ gosu postgres gunzip -c "$DB_DUMPFILE" | psql -d "$GNUHEALTH_DB"; }
3238
echo
3339
echo "Allowing access for the gnuhealth user from all IPs..."
3440
{ echo; echo "host all $GNUHEALTH_USER 0.0.0.0/0 md5"; } >> "$PGDATA"/pg_hba.conf

0 commit comments

Comments
 (0)
0