From 72351b5bcd09512d263e92f2ca97a85d8d8a040b Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Fri, 28 Nov 2025 09:42:52 -0800 Subject: [PATCH] Set `RUNNING_UNDER_SYSTEMD=true` so `beam.smp` is PID 1 The current Dockerfile / docker-entrypoint.sh results in the following PIDs within a running RabbitMQ container: ``` PID CMD 1 /bin/sh /opt/rabbitmq/sbin/rabbitmq-server 20 /opt/erlang/lib/erlang/erts-15.2.7.4/bin/beam.smp -W w ... 26 erl_child_setup 1024 65 /opt/erlang/lib/erlang/erts-15.2.7.4/bin/inet_gethost 4 66 /opt/erlang/lib/erlang/erts-15.2.7.4/bin/inet_gethost 4 76 /opt/erlang/lib/erlang/erts-15.2.7.4/bin/epmd -daemon 121 /bin/sh -s rabbit_disk_monitor ``` Note that the `rabbitmq-server` script remains running and is PID 1. There was a [long discussion](https://github.com/rabbitmq/cluster-operator/discussions/2012) about what results this particular setup could have in heavily-loaded k8s environments. This prompted me to look at the `rabbitmq-server` script and found that the behavior can be controlled via several env variables: https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbit/scripts/rabbitmq-server#L97 Most notably, if `RUNNING_UNDER_SYSTEMD` is set to a value, the script will `exec` the Erlang VM. This PR sets that value, which results in the following PIDs in a container: ``` PID CMD 1 /opt/erlang/lib/erlang/erts-15.2.7.4/bin/beam.smp -W w ... 25 erl_child_setup 1024 64 /opt/erlang/lib/erlang/erts-15.2.7.4/bin/inet_gethost 4 65 /opt/erlang/lib/erlang/erts-15.2.7.4/bin/inet_gethost 4 75 /opt/erlang/lib/erlang/erts-15.2.7.4/bin/epmd -daemon 120 /bin/sh -s rabbit_disk_monitor ``` The Erlang VM already gracefully stops RabbitMQ on `SIGTERM`, so there is no change in behavior. --- 3.13/alpine/Dockerfile | 4 ++++ 3.13/ubuntu/Dockerfile | 4 ++++ 4.0/alpine/Dockerfile | 4 ++++ 4.0/ubuntu/Dockerfile | 4 ++++ 4.1/alpine/Dockerfile | 4 ++++ 4.1/ubuntu/Dockerfile | 4 ++++ 4.2/alpine/Dockerfile | 4 ++++ 4.2/ubuntu/Dockerfile | 4 ++++ Dockerfile-alpine.template | 4 ++++ Dockerfile-ubuntu.template | 4 ++++ 10 files changed, 40 insertions(+) diff --git a/3.13/alpine/Dockerfile b/3.13/alpine/Dockerfile index 5ae87d51..52ecdeb8 100644 --- a/3.13/alpine/Dockerfile +++ b/3.13/alpine/Dockerfile @@ -317,6 +317,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/3.13/ubuntu/Dockerfile b/3.13/ubuntu/Dockerfile index cd60aae4..3554d435 100644 --- a/3.13/ubuntu/Dockerfile +++ b/3.13/ubuntu/Dockerfile @@ -318,6 +318,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/4.0/alpine/Dockerfile b/4.0/alpine/Dockerfile index fa044d37..725cc227 100644 --- a/4.0/alpine/Dockerfile +++ b/4.0/alpine/Dockerfile @@ -317,6 +317,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/4.0/ubuntu/Dockerfile b/4.0/ubuntu/Dockerfile index 63dc7e44..387c5baf 100644 --- a/4.0/ubuntu/Dockerfile +++ b/4.0/ubuntu/Dockerfile @@ -311,6 +311,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/4.1/alpine/Dockerfile b/4.1/alpine/Dockerfile index 54e2b0fe..e3f80887 100644 --- a/4.1/alpine/Dockerfile +++ b/4.1/alpine/Dockerfile @@ -317,6 +317,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/4.1/ubuntu/Dockerfile b/4.1/ubuntu/Dockerfile index b42ca812..2f150421 100644 --- a/4.1/ubuntu/Dockerfile +++ b/4.1/ubuntu/Dockerfile @@ -311,6 +311,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/4.2/alpine/Dockerfile b/4.2/alpine/Dockerfile index 816ee301..4103ee7e 100644 --- a/4.2/alpine/Dockerfile +++ b/4.2/alpine/Dockerfile @@ -317,6 +317,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/4.2/ubuntu/Dockerfile b/4.2/ubuntu/Dockerfile index 7df763b7..e4f67e69 100644 --- a/4.2/ubuntu/Dockerfile +++ b/4.2/ubuntu/Dockerfile @@ -311,6 +311,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template index 92d29f1b..2d6d5837 100644 --- a/Dockerfile-alpine.template +++ b/Dockerfile-alpine.template @@ -324,6 +324,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/Dockerfile-ubuntu.template b/Dockerfile-ubuntu.template index 07aee153..33ea98dd 100644 --- a/Dockerfile-ubuntu.template +++ b/Dockerfile-ubuntu.template @@ -327,6 +327,10 @@ VOLUME $RABBITMQ_DATA_DIR # https://docs.docker.com/samples/library/ubuntu/#locales ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 +# the rabbitmq-server startup script uses RUNNING_UNDER_SYSTEMD to determine if the erl command +# should be started via exec, which results in beam.smp becoming PID 1 in the container +ENV RUNNING_UNDER_SYSTEMD=true + COPY --chown=rabbitmq:rabbitmq 10-defaults.conf 20-management_agent.disable_metrics_collector.conf /etc/rabbitmq/conf.d/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"]