正好停止运行apache的Phusion乘客 [英] Gracefully stop Phusion Passenger running on apache
问题描述
我有一个docker容器,apache在前台中运行。在停止docker容器的时候,一个SIGTERM被发送给所有的子进程,这在我们的例子中是apache。
现在我面临的问题是正常关闭apache接收SIGTERM信号。
Apache通常立即终止当前的请求,这是导致问题的主要原因。不知怎的,我需要将SIGTERM信号转换为 SIGWINCH ,这将最终正常地关闭服务器。
我在想写一些
任何关于这方面的建议将非常感谢!
谢谢。
容器中的tomcat可以通过下面的命令正常地停止(如果需要,更改tomcat路径):
docker exec -it< container id / name> / usr / local / apache2 / bin / apachectl -k graceful
如果你想要看到tomcat的日志,如果它不在前台运行
docker exec -it< container id / name> tail -f tail -f / usr / local / apache2 / logs / error_log
更新: 根据评论。
从 docker文档,您可以在停止docker容器时指定时间。默认情况下,它只会等待10秒。
要停止具有不同超时的容器:
docker stop -t<以秒为单位的时间> < container id / name>
我相信,停止时间延长可能有助于您的处理。
$ b在您的情况下,$ b
UPDATE2 发送自定义信号, SIGWINCH
有关详细信息,请参阅此处。
docker kill -s SIGWINCH< apache container id / name>
UPDATE3
有关信号陷阱的有用资源: / p>
https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86#.qp68kskwd
http://www.techbar.me/stopping-docker-containers-gracefully/
希望这些都是有帮助的。
I have a docker container with apache running in foreground. On stopping the docker container , a SIGTERM is sent to all the child processes , which is apache in our case.
Now, the problem i am facing is to gracefully shutdown apache on receiving SIGTERM signal. Apache normally terminates on the current requests immediately which is the main cause of the problem . Somehow, i need to translate the SIGTERM signal to SIGWINCH , which would eventually gracefully shutdown the server.
I was thinking of writing some kind of wrapper script , but couldn't get as to how to start.
Any suggestions in this regard would be highly appreciated!
Thanks.
The tomcat inside of container can be stopped gracefully by issuing below command (change tomcat path if needed):
docker exec -it <container id / name> /usr/local/apache2/bin/apachectl -k graceful
And to your comment, if you want to see the tomcat log in case if it is not running in foreground
docker exec -it <container id / name> tail -f tail -f /usr/local/apache2/logs/error_log
UPDATE: Based on the comments.
From the docker documentation, you may specify the time while stopping the docker container. By default, it will only wait for 10 sec.
To stop container with different timeout:
docker stop -t <time in seconds> <container id/ name>
I believe that, increasing time out while stopping might help in your case.
UPDATE2 sending custom signal, SIGWINCH
in your case. Please refer here for more details.
docker kill -s SIGWINCH <apache container id / name>
UPDATE3 There are helpful resources on signal trapping:
https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86#.qp68kskwd
http://www.techbar.me/stopping-docker-containers-gracefully/
Hope these are helpful.
这篇关于正好停止运行apache的Phusion乘客的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!