Skip to content

Commit

Permalink
Refactor listen_addresses to be set in the sample file, and make the …
Browse files Browse the repository at this point in the history
…sample file easier to overwrite
  • Loading branch information
tianon committed Feb 26, 2016
1 parent ec5ce80 commit 41e7a62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ RUN apt-get update \
postgresql-contrib-$PG_MAJOR=$PG_VERSION \
&& rm -rf /var/lib/apt/lists/*

# make the sample config easier to munge (and "correct by default")
RUN mv -v /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample /usr/share/postgresql/ \
&& ln -sv ../postgresql.conf.sample /usr/share/postgresql/$PG_MAJOR/ \
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/postgresql.conf.sample

This comment has been minimized.

Copy link
@euven

euven Mar 9, 2016

should the exclamation marks not be "/"'s??

This comment has been minimized.

Copy link
@tianon

tianon Mar 9, 2016

Author Member

Either is fine: (from https://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command)

The syntax of the s (as in substitute) command is ‘s/regexp/replacement/flags’. The / characters may be uniformly replaced by any other single character within any given s command. The / character (or whatever other character is used in its stead) can appear in the regexp or replacement only if it is preceded by a \ character.


RUN mkdir -p /var/run/postgresql && chown -R postgres /var/run/postgresql

ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
Expand Down
8 changes: 3 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/bash
set -e

set_listen_addresses() {
sedEscapedValue="$(echo "$1" | sed 's/[\/&]/\\&/g')"
sed -ri "s/^#?(listen_addresses\s*=\s*)\S+/\1'$sedEscapedValue'/" "$PGDATA/postgresql.conf"
}
if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi

if [ "$1" = 'postgres' ]; then
mkdir -p "$PGDATA"
Expand Down Expand Up @@ -88,7 +87,6 @@ if [ "$1" = 'postgres' ]; then
done

gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop
set_listen_addresses '*'

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand Down

0 comments on commit 41e7a62

Please sign in to comment.