Skip to content

Commit

Permalink
PGDATA everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed May 21, 2024
1 parent fac06ff commit b4e6145
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion stack/base-with-services/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARG PGSQL_VERSION
ARG TARGETARCH
# Location of the Postgresql DB
# This variable is automatically picked up by initdb
ARG ENV PGDATA=/home/${NB_USER}/.posgresql
ENV PGDATA=/home/${NB_USER}/.posgresql

# Install RabbitMQ and PostgreSQL in a dedicated conda environment.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
set -x

# -w waits until server is up
PSQL_START_CMD="pg_ctl --timeout=180 -w -D /home/${NB_USER}/.postgresql -l /home/${NB_USER}/.postgresql/logfile start"
PSQL_STOP_CMD="pg_ctl -w -D /home/${NB_USER}/.postgresql stop"
PSQL_STATUS_CMD="pg_ctl -D /home/${NB_USER}/.postgresql status"
PSQL_START_CMD="pg_ctl --timeout=180 -w -l ${PGDATA}/logfile start"
PSQL_STOP_CMD="pg_ctl -w stop"
PSQL_STATUS_CMD="pg_ctl status"

MAMBA_RUN="mamba run -n aiida-core-services"

# make DB directory, if not existent
if [ ! -d /home/${NB_USER}/.postgresql ]; then
mkdir /home/${NB_USER}/.postgresql
if [ ! -d ${PGDATA} ]; then
mkdir ${PGDATA}
${MAMBA_RUN} initdb
echo "unix_socket_directories = '/tmp'" >> /home/${NB_USER}/.postgresql/postgresql.conf
echo "unix_socket_directories = '/tmp'" >> ${PGDATA}/postgresql.conf
${MAMBA_RUN} ${PSQL_START_CMD}

else
# Fix problem with kubernetes cluster that adds rws permissions to the group
# for more details see: https://github.com/materialscloud-org/aiidalab-z2jh-eosc/issues/5
chmod g-rwxs /home/${NB_USER}/.postgresql -R
chmod g-rwxs ${PGDATA} -R

if ! ${MAMBA_RUN} ${PSQL_STATUS_CMD}; then
# Cleaning up the mess if Postgresql was not shutdown properly.
# TODO: Rotate logfile
echo "" > /home/${NB_USER}/.postgresql/logfile
rm -vf /home/${NB_USER}/.postgresql/postmaster.pid
echo "" > ${PGDATA}/logfile
rm -vf ${PGDATA}/postmaster.pid
${MAMBA_RUN} ${PSQL_START_CMD}
fi
fi

0 comments on commit b4e6145

Please sign in to comment.