Skip to content

Commit

Permalink
Speedup container startup (#456)
Browse files Browse the repository at this point in the history
* Reduce number of verdi invocations on startup
* Set debug outputs
* Cleanup 20_start-postgresql.sh
  • Loading branch information
danielhollas committed Jun 4, 2024
1 parent c752bd6 commit 503d11b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
16 changes: 5 additions & 11 deletions stack/base-with-services/before-notebook.d/20_start-postgresql.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash

# Activate the conda environment with PostgreSQL installed in it.
# conda activate pgsql
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"
Expand All @@ -17,19 +15,15 @@ if [ ! -d /home/${NB_USER}/.postgresql ]; then
echo "unix_socket_directories = '/tmp'" >> /home/${NB_USER}/.postgresql/postgresql.conf
${MAMBA_RUN} ${PSQL_START_CMD}

# else don't
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

# stores return value in $?
running=true
${MAMBA_RUN} ${PSQL_STATUS_CMD} || running=false

# Postgresql was probably not shutdown properly. Cleaning up the mess...
if ! $running ; then
echo "" > /home/${NB_USER}/.postgresql/logfile # empty log files
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
${MAMBA_RUN} ${PSQL_START_CMD}
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -em
set -emx

RABBITMQ_DATA_DIR="/home/${NB_USER}/.rabbitmq"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -em
set -emx

RABBITMQ_DATA_DIR="/home/${NB_USER}/.rabbitmq"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -em
set -emx

# Supress rabbitmq version warning for arm64 since
# it is built using latest version rabbitmq from apt install.
Expand Down
1 change: 1 addition & 0 deletions stack/base/before-notebook.d/10_prepare-home-config.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -x

# If the container is start by spawner and the home is remounted.
# The .bashrc in HOME won't be set properly.
Expand Down
21 changes: 7 additions & 14 deletions stack/base/before-notebook.d/40_prepare-aiida.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/bin/bash

# This script is executed whenever the docker container is (re)started.

# Debugging.
set -x

# Environment.
export SHELL=/bin/bash

# Check if user requested to set up AiiDA profile (and if it exists already)
if [[ ${SETUP_DEFAULT_AIIDA_PROFILE} == true ]] && ! verdi profile show ${AIIDA_PROFILE_NAME} &> /dev/null; then
if [[ ${SETUP_DEFAULT_AIIDA_PROFILE} == true ]] && ! verdi profile show ${AIIDA_PROFILE_NAME} 2> /dev/null; then
NEED_SETUP_PROFILE=true;
else
NEED_SETUP_PROFILE=false;
Expand Down Expand Up @@ -48,7 +45,7 @@ if [[ ${NEED_SETUP_PROFILE} == true ]]; then
exit 1
fi

verdi computer show ${computer_name} || verdi computer setup \
verdi computer setup \
--non-interactive \
--label "${computer_name}" \
--description "this computer" \
Expand All @@ -61,17 +58,13 @@ if [[ ${NEED_SETUP_PROFILE} == true ]]; then
verdi computer configure core.local "${computer_name}" \
--non-interactive \
--safe-interval 0.0
fi


# Show the default profile
verdi profile show || echo "The default profile is not set."
else

# Make sure that the daemon is not running, otherwise the migration will abort.
verdi daemon stop
# Migration will run for the default profile.
verdi storage migrate --force

# Migration will run for the default profile.
verdi storage migrate --force
fi

# Daemon will start only if the database exists and is migrated to the latest version.
verdi daemon start || echo "AiiDA daemon is not running."
verdi daemon start || echo "ERROR: AiiDA daemon is not running!"

0 comments on commit 503d11b

Please sign in to comment.