优雅地停止ECS容器 [英] Gracefully stopping ecs container

查看:67
本文介绍了优雅地停止ECS容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些docker容器,可以监听RabbitMQ并处理收到的消息.我有一个代码管道,可以在有代码提交的情况下启动图像的重建和更新任务.

I am having some docker container which listens on RabbitMQ and process the message received.I have a code pipeline which kicks off the rebuilding of the image and updating the tasks when there is a code commit.

我的问题是在消息处理期间容器将被突然杀死,有什么方法可以停止容器杀死,直到进程完成并允许其停止,以便在创建新容器时自动创建一个新容器.可以,当前容器可以处理带有旧代码的消息.我的容器内部正在运行python代码.

My problem here is the container will be killed abruptly during the message processing is there any way where i can stop the container killing until the process is finished and allow it to stop so that a new new container will be automatically created as i am ok with the current container processing the message with the old code.My container is running python code inside.

谢谢

推荐答案

ECS默认情况下会发送SIGTERM :

StopTask

停止正在运行的任务.

在任务上调用 StopTask 时,相当于docker stop是发出给在任务中运行的容器.这导致SIGTERM和默认的30秒超时,然后发送SIGKILL并且容器被强行停止.如果容器处理SIGTERM正常运行,并在收到信号后30秒内退出,否SIGKILL已发送.

When StopTask is called on a task, the equivalent of docker stop is issued to the containers running in the task. This results in a SIGTERM and a default 30-second timeout, after which SIGKILL is sent and the containers are forcibly stopped. If the container handles the SIGTERM gracefully and exits within 30 seconds from receiving it, no SIGKILL is sent.

注意

可以在Amazon ECS上配置默认的30秒超时具有ECS_CONTAINER_STOP_TIMEOUT变量的容器代理.欲了解更多有关信息,请参阅《 Amazon ECS容器代理配置》中的Amazon Elastic Container Service开发人员指南.

The default 30-second timeout can be configured on the Amazon ECS container agent with the ECS_CONTAINER_STOP_TIMEOUT variable. For more information, see Amazon ECS Container Agent Configuration in the Amazon Elastic Container Service Developer Guide.

知道了这一点,您可以在应用程序中添加一个简单的检查以捕获SIGTERM,并做出适当的反应.

Knowing this, you can add a simple check in your app to catch the SIGTERM, and react appropriately.

这篇关于优雅地停止ECS容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆