You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by "syrm-ll (via GitHub)" <gi...@apache.org> on 2025/07/28 23:58:22 UTC
[I] apache/rocketmq image It seems unable to gracefully shut down [rocketmq-docker]
syrm-ll opened a new issue, #123:
URL: https://github.com/apache/rocketmq-docker/issues/123
I tried two versions of `Apache/RocketMQ: 5.3.2` and `Apache/RocketMQ: 5.3.3` located on Dockerhub, and found that the process with PID 1 started by the container is a shell script rather than a JVM
This violates the best practice of containers. If the shutdown signal forwarding is not manually handled, the JVM should be made a PID1 process to ensure that the JVM shutdown hook is executed correctly, rather than forcing a shutdown after timeout
---
我尝试了位于 dockerhub 的 `apache/rocketmq:5.3.2` `apache/rocketmq:5.3.3` 两个版本, 发现容器启动的 PID 为 1 的进程都是 shell 脚本而非 JVM
这违反了容器的最佳实践, 如果没有手动处理关机信号转发, 应该让 JVM 成为PID1进程, 以确保JVM关机挂钩正确执行, 而非超时后强制关闭
参考: <https://docs.docker.com/build/building/best-practices/#entrypoint>
容器内的进程:
```log
rocketmq 1 0 0 23:38 ? 00:00:00 sh mqbroker
rocketmq 7 1 0 23:38 ? 00:00:00 sh /home/rocketmq/rocketmq-5.3.3/bin/runbroker.sh -Drmq.logback.configurationFile=/home/rocketmq/rocketmq-5.3.3/conf/rmq.broker.logback.xml org.apache.rocketmq.broker.BrokerStartup
rocketmq 14 7 17 23:38 ? 00:00:12 /opt/java/openjdk/bin/java -server -Xms2g -Xmx2g -Xmn1g -XX:MaxDirectMemorySize=1g -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRU
rocketmq 171 0 0 23:39 pts/0 00:00:00 /bin/sh -c [ -e /bin/bash ] && (/bin/bash || exit 0) || /bin/sh
rocketmq 177 171 0 23:39 pts/0 00:00:00 /bin/sh -c [ -e /bin/bash ] && (/bin/bash || exit 0) || /bin/sh
rocketmq 178 177 0 23:39 pts/0 00:00:00 /bin/bash
```
`mqbroker` 启动脚本部分内容:
sh 开启了子进程
```shell
if [ "$enable_proxy" = true ]; then
args_for_proxy=$other_args" -pm local"
if [ "$broker_config" != "" ]; then
args_for_proxy=${args_for_proxy}" -bc "${broker_config}
fi
sh ${ROCKETMQ_HOME}/bin/runbroker.sh -Drmq.logback.configurationFile=$ROCKETMQ_HOME/conf/rmq.proxy.logback.xml org.apache.rocketmq.proxy.ProxyStartup ${args_for_proxy}
else
args_for_broker=$other_args
if [ "$broker_config" != "" ]; then
args_for_broker=${args_for_broker}" -c "${broker_config}
fi
sh ${ROCKETMQ_HOME}/bin/runbroker.sh -Drmq.logback.configurationFile=$ROCKETMQ_HOME/conf/rmq.broker.logback.xml org.apache.rocketmq.broker.BrokerStartup ${args_for_broker}
fi
```
目前在 docker 环境中部署时, `docker compose down` 卸载或 `docker compose restart` 重启能明显感觉到迟缓, 因为没有人处理关机信号, docker 在超时后强制结束容器, 所以始终有固定的延迟
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] apache/rocketmq image It seems unable to gracefully shut down [rocketmq-docker]
Posted by "syrm-ll (via GitHub)" <gi...@apache.org>.
syrm-ll commented on issue #123:
URL: https://github.com/apache/rocketmq-docker/issues/123#issuecomment-3324953632
更新这个问题, JVM 也不适合作为 PID 1 刚发现 JFR 对此有警告
> Process runs with PID 1.
>
> Java processes should not run with PID 1 as this PID is reserved for the init process in Linux, which is responsible for signal handling > and process management. Java processes do not natively handle signals like SIGTERM correctly, leading to issues such as unclean > shutdowns and orphaned child processes.
>
> Enforce the process does not run with PID 1. In Docker, this can be achieved by using the lightweight init system tini with the '--init' > flag. For an example with Docker Compose refer to the documentation from Docker Compose.
但是总好过现在这样连关机信号都没有程序处理
更好的方案是使用 `tini` 或类似工具
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org