Skip to content

Commit 7d5291e

Browse files
authored
AMQ-9588: Run ActiveMQ with regular user in Docker container, and hook to easily stop the container (#1665)
1 parent a8fa4b0 commit 7d5291e

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

assembly/src/docker/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,23 @@ ENV PATH $PATH:$ACTIVEMQ_HOME/bin
2929
# activemq_dist can point to a directory or a tarball on the local system
3030
ARG activemq_dist=NOT_SET
3131

32+
RUN groupadd -r activemq && useradd -r -g activemq activemq
33+
3234
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
35+
RUN chown activemq:activemq /usr/local/bin/entrypoint.sh && chmod +x /usr/local/bin/entrypoint.sh
3336

3437
# Install build dependencies and activemq
3538
ADD $activemq_dist $ACTIVEMQ_INSTALL_PATH
3639
RUN set -x && \
3740
cp -r $ACTIVEMQ_INSTALL_PATH/apache-activemq-* $ACTIVEMQ_HOME && \
3841
rm -r $ACTIVEMQ_INSTALL_PATH/apache-activemq-*
3942

43+
RUN chown -R activemq:activemq $ACTIVEMQ_HOME
44+
45+
STOPSIGNAL SIGTERM
46+
47+
USER activemq
48+
4049
EXPOSE 8161 61616 5672 61613 1883 61614 1099
4150
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
4251
CMD ["activemq", "console"]

assembly/src/docker/entrypoint.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,17 @@ if [ -z "${ACTIVEMQ_OPTS}" ]; then
8989
export ACTIVEMQ_OPTS
9090
fi
9191

92-
exec "$@"
92+
_term() {
93+
echo "Received signal, stopping ActiveMQ..."
94+
if [ -n "${child_pid:-}" ] && kill -0 "${child_pid}" 2>/dev/null; then
95+
kill -TERM "${child_pid}" 2>/dev/null || true
96+
fi
97+
}
98+
99+
trap _term TERM INT
100+
101+
"$@" &
102+
child_pid=$!
103+
wait "${child_pid}"
104+
105+
exit $?

0 commit comments

Comments
 (0)