diff --git a/.github/workflows/build_and_test_on_pr.yml b/.github/workflows/build_and_test_on_pr.yml index f4e8176..2201f18 100644 --- a/.github/workflows/build_and_test_on_pr.yml +++ b/.github/workflows/build_and_test_on_pr.yml @@ -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. diff --git a/Dockerfile b/Dockerfile index c2e964d..2c422b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,7 +53,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ locales \ less \ psmisc \ - rabbitmq-server \ rsync \ ssh \ unzip \ @@ -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 diff --git a/my_init.d/start-rabbitmq.sh b/my_init.d/start-rabbitmq.sh index bc42cea..d77ddf1 100755 --- a/my_init.d/start-rabbitmq.sh +++ b/my_init.d/start-rabbitmq.sh @@ -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} diff --git a/opt/start-rabbitmq.sh b/opt/start-rabbitmq.sh new file mode 100755 index 0000000..5f7a699 --- /dev/null +++ b/opt/start-rabbitmq.sh @@ -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