Skip to content

Commit

Permalink
Removed su-exec and added USER to dockerfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
muratgozel committed Sep 26, 2021
1 parent dac7bd8 commit e091e1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN apk add --no-cache --virtual .build-deps gcc g++ make wget pkgconf dpkg-dev
bzip2-dev zlib-dev libuuid linux-headers \
tzdata yaml-dev util-linux-dev && \
apk add --no-cache git bash python3 py3-pip icu libxml2 lz4-dev zstd-dev \
postgresql-dev shadow su-exec && \
postgresql-dev shadow && \
# configure dependencies
ln -sf python3 /usr/bin/python && \
mkdir -p /downloads && \
Expand Down Expand Up @@ -62,6 +62,8 @@ RUN chmod 755 /usr/bin/pgbackrest && \

STOPSIGNAL SIGINT

USER $PGUSER

# start database service
ENV PATH=/usr/local/pgsql/bin:$PATH
ENTRYPOINT ["/entrypoint.sh"]
Expand Down
14 changes: 7 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ hbaconf="$PGDATA/pg_hba.conf"

# create db cluster if it's not exist
if [[ ! -f $PGDATA/PG_VERSION ]]; then
su-exec $PGUSER initdb --encoding=UTF8 --locale=C -D $PGDATA
initdb --encoding=UTF8 --locale=C -D $PGDATA

echo "listen_addresses = '*'" >> $pgconf
echo "port = $PGPORT" >> $pgconf
Expand All @@ -18,7 +18,7 @@ fi

# init pgbackrest
if ! grep -q "pgbackrest" "$pgconf"; then
su-exec $PGUSER pg_ctl start -o "-p $PGPORT -k /var/run/postgresql" -D $PGDATA
pg_ctl start -o "-p $PGPORT -k /var/run/postgresql" -D $PGDATA

echo "wal_level = replica" >> $pgconf
echo "max_wal_size = 1GB" >> $pgconf
Expand All @@ -29,19 +29,19 @@ if ! grep -q "pgbackrest" "$pgconf"; then
echo "log_line_prefix = ''" >> $pgconf
echo "log_timezone = 'Etc/UTC'" >> $pgconf

su-exec $PGUSER pgbackrest --stanza=app --pg1-port=$PGPORT --log-level-console=info stanza-create
su-exec $PGUSER pg_ctl restart -o "-p $PGPORT -k /var/run/postgresql" -D $PGDATA
pgbackrest --stanza=app --pg1-port=$PGPORT --log-level-console=info stanza-create
pg_ctl restart -o "-p $PGPORT -k /var/run/postgresql" -D $PGDATA

su-exec $PGUSER pgbackrest --stanza=app --pg1-port=$PGPORT --log-level-console=info check
pgbackrest --stanza=app --pg1-port=$PGPORT --log-level-console=info check
pgbackrest_check_result=$?

if [ $pgbackrest_check_result -ne 0 ]; then
echo "pgbackrest check failed."
exit $pgbackrest_check_result
fi

su-exec $PGUSER pg_ctl stop -o "-p $PGPORT -k /var/run/postgresql" -D $PGDATA
pg_ctl stop -o "-p $PGPORT -k /var/run/postgresql" -D $PGDATA
fi

# start postgresql server
su-exec $PGUSER "$@"
"$@"

0 comments on commit e091e1f

Please sign in to comment.