Gracefully stop Phusion Passenger running on apache

拈花ヽ惹草 提交于 2020-01-05 04:20:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/40298849/gracefully-stop-phusion-passenger-running-on-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!