-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize DB during image build #457
Merged
Merged
Changes from 15 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f48a799
Reduce number of verdi invocations on startup
danielhollas bdd8ef1
Set debug outputs
danielhollas f02bc28
Cleanup 20_start-postgresql.sh
danielhollas 6f639aa
More tweaks
danielhollas da9cffd
Prepare DB during build
danielhollas 79231b6
Try without root
danielhollas a6320de
Use PGDATA
danielhollas fac06ff
Revert "Try without root"
danielhollas b4e6145
PGDATA everywhere
danielhollas ac248db
back
danielhollas 2e5ba46
Fix?
danielhollas 50e2611
Pass PGDATA for full-stack
danielhollas be5846d
This?
danielhollas e89f505
Update stack/full-stack/Dockerfile
danielhollas 9aaa20d
Update stack/full-stack/Dockerfile
danielhollas 163e4f2
Update stack/full-stack/Dockerfile
danielhollas e4c45e1
Add comment about Erlang
danielhollas 1ac56fb
Come on!
danielhollas bdf3907
Remove meta targets
danielhollas c8c1cef
Preserve logfile
danielhollas 2ddeac0
sigh
danielhollas 7e9c91c
fix
danielhollas 2d0e8f4
remove pg_ctl status
danielhollas d03f11b
To hell with it
danielhollas 94ab041
Try thisA
danielhollas ae59bdb
?
danielhollas 8378fa5
Sigh
danielhollas 236902b
pretty print json output
danielhollas 5b2d0bd
Pretty please
danielhollas 2cfe15a
hmm
danielhollas d480087
...
danielhollas daa56ea
Getting closer
danielhollas c08dd3d
Screw this
danielhollas 7f80842
Merge branch 'main' into initdb
danielhollas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 14 additions & 20 deletions
34
stack/base-with-services/before-notebook.d/20_start-postgresql.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,30 @@ | ||
#!/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" | ||
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 | ||
${MAMBA_RUN} initdb -D /home/${NB_USER}/.postgresql | ||
echo "unix_socket_directories = '/tmp'" >> /home/${NB_USER}/.postgresql/postgresql.conf | ||
if [ ! -d ${PGDATA} ]; then | ||
mkdir ${PGDATA} | ||
${MAMBA_RUN} initdb | ||
echo "unix_socket_directories = '/tmp'" >> ${PGDATA}/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 | ||
chmod -R g-rwxs ${PGDATA} | ||
|
||
# Postgresql was probably not shutdown properly. Cleaning up the mess... | ||
if ! $running ; then | ||
echo "" > /home/${NB_USER}/.postgresql/logfile # empty log files | ||
rm -vf /home/${NB_USER}/.postgresql/postmaster.pid | ||
if ! ${MAMBA_RUN} ${PSQL_STATUS_CMD}; then | ||
# Cleaning up the mess if Postgresql was not shutdown properly. | ||
# TODO: Rotate logfile | ||
echo "" > ${PGDATA}/logfile | ||
rm -vf ${PGDATA}/postmaster.pid | ||
${MAMBA_RUN} ${PSQL_START_CMD} | ||
fi | ||
fi |
2 changes: 1 addition & 1 deletion
2
stack/base-with-services/before-notebook.d/30_start-rabbitmq-amd64.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
stack/base-with-services/before-notebook.d/30_start-rabbitmq-arm64.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
stack/base-with-services/before-notebook.d/41_suppress-rabbitmq-version-warning.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the DB name used when create aiida profile after this change? We set it explicitly in
config-quick-setup.yaml
asaiida_db
.BTW, we need keep in mind to adapt the change to use
verdi presto
after we move to 2.6.0There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question.
-D
parameter doesn't set the db name, it sets the DB location.https://www.postgresql.org/docs/current/app-initdb.html#APP-INITDB-OPTION-PGDATA
in this case it would set it to
~/aiida_db
. But this was broken anyway, since the location instack/base-with-services/before-notebook.d/20_start-postgresql.sh
was set to~/.postgresql
, so essentially this initdb command was being ignored. Now the location is set via the PGDATA variable and thus is guaranteed to be the same everywhere to prevent these kind of mismatches in the future.Note that the the
-U
parameter sets the so-called bootstrap superuser I am not sure if this would have any effect, but we are not using this parameter instack/base-with-services/before-notebook.d/20_start-postgresql.sh
so I deleted it here as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we'll want to use
verdi presto
since we'd loose some config options. Instead I believe we should migrate fromverdi quicksetup
to the fullverdi profile setup
. But that's not that urgent, quicksetup has been deprecated but not removed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks!