Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gracefully stopping ecs container

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.

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.

like image 531
Ram Avatar asked Mar 29 '18 13:03

Ram


1 Answers

ECS by default sends a SIGTERM:

StopTask

Stops a running task.

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.

Note

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.

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

like image 158
MrDuk Avatar answered Nov 18 '22 10:11

MrDuk