Skip to content

Commit

Permalink
Move RabbitMQ to a dedicated conda environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Jul 25, 2022
1 parent 47727a4 commit 6e578d8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test_on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
docker exec --tty --user root $DOCKERID wait-for-services
docker exec --tty --user aiida $DOCKERID wait-for-services
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c '/opt/conda/envs/pgsql/bin/pg_ctl -D /home/$SYSTEM_USER/.postgresql status' # Check that postgres is up.
docker exec --tty --user root $DOCKERID /bin/bash -l -c 'service rabbitmq-server status' # Check that rabbitmq is up.
docker exec --tty --user root $DOCKERID /bin/bash -l -c '/opt/conda/envs/rmq/bin/rabbitmq-server status' # Check that rabbitmq is up.
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'conda create -y -n test_env python=3.8' # Check that one can create a new conda environment.
docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'conda activate test_env' # Check that new environment works.
sudo cp tmp/.ssh/id_rsa . # Copy id_rsa file from the mounted folder.
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
locales \
less \
psmisc \
rabbitmq-server \
rsync \
ssh \
unzip \
Expand Down Expand Up @@ -95,6 +94,9 @@ RUN cd /tmp && \
# Install PostgreSQL in a dedicated conda environment.
RUN conda create -c conda-forge -n pgsql postgresql=10.6 && conda clean --all -f -y

# Install RabbitMQ in a dedicated conda environment.
RUN conda create -c conda-forge -n rmq rabbitmq-server && conda clean --all -f -y

# Copy the script load-singlesshagent.sh to /usr/local/bin.
COPY bin/load-singlesshagent.sh /usr/local/bin/load-singlesshagent.sh

Expand Down
19 changes: 1 addition & 18 deletions my_init.d/start-rabbitmq.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
#!/bin/bash
set -em

DIR_RABBITMQ="/home/${SYSTEM_USER}/.rabbitmq"

mkdir -p "${DIR_RABBITMQ}"
chown rabbitmq:rabbitmq "${DIR_RABBITMQ}"

# Set base directory for RabbitMQ to persist its data. This needs to be set to a folder in the system user's home
# directory as that is the only folder that is persisted outside of the container.
echo MNESIA_BASE="${DIR_RABBITMQ}" >> /etc/rabbitmq/rabbitmq-env.conf
echo LOG_BASE="${DIR_RABBITMQ}/log" >> /etc/rabbitmq/rabbitmq-env.conf

# Explicitly define the node name. This is necessary because the mnesia subdirectory contains the hostname, which by
# default is set to the value of $(hostname -s), which for docker containers, will be a random hexadecimal string. Upon
# restart, this will be different and so the original mnesia folder with the persisted data will not be found. The
# reason RabbitMQ is built this way is through this way it allows to run multiple nodes on a single machine each with
# isolated mnesia directories. Since in the AiiDA setup we only need and run a single node, we can simply use localhost.
echo NODENAME=rabbit@localhost >> /etc/rabbitmq/rabbitmq-env.conf

service rabbitmq-server start
su -c /opt/start-rabbitmq.sh ${SYSTEM_USER}
24 changes: 24 additions & 0 deletions opt/start-rabbitmq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -em

# Activate the conda environment with RabbitMQ installed in it.
conda activate rmq

DIR_RABBITMQ="/home/${SYSTEM_USER}/.rabbitmq"

mkdir -p "${DIR_RABBITMQ}"
#chown rabbitmq:rabbitmq "${DIR_RABBITMQ}"

# Set base directory for RabbitMQ to persist its data. This needs to be set to a folder in the system user's home
# directory as that is the only folder that is persisted outside of the container.
echo MNESIA_BASE="${DIR_RABBITMQ}" >> /opt/conda/envs/rmq/etc/rabbitmq/rabbitmq-env.conf
echo LOG_BASE="${DIR_RABBITMQ}/log" >> /opt/conda/envs/rmq/etc/rabbitmq/rabbitmq-env.conf

# Explicitly define the node name. This is necessary because the mnesia subdirectory contains the hostname, which by
# default is set to the value of $(hostname -s), which for docker containers, will be a random hexadecimal string. Upon
# restart, this will be different and so the original mnesia folder with the persisted data will not be found. The
# reason RabbitMQ is built this way is through this way it allows to run multiple nodes on a single machine each with
# isolated mnesia directories. Since in the AiiDA setup we only need and run a single node, we can simply use localhost.
echo NODENAME=rabbit@localhost >> /opt/conda/envs/rmq/etc/rabbitmq/rabbitmq-env.conf

rabbitmq-server -detached

0 comments on commit 6e578d8

Please sign in to comment.