Restarting a Greengrass component with a container creates two instances of that container

0

I would like to restart a greengrass component, containing a docker container, without creating a second instance of that container. When I run the component restart command via the greengrass-cli, then run "docker container ls", it shows two active containers running.

Is it possible to restart a container component such that the original instance is killed ?

Container recipe lifecycle command pasted below:

{ "Run": "docker run --rm --net=host --runtime nvidia <ECR IMAGE> python3 <python script on container>" }

질문됨 2년 전1121회 조회
2개 답변
0
수락된 답변

You can restart the component and have it restart the container. Essentially Greengrass is sending a SIGTERM to the process running in the 'Run' portion of the lifecycle when stopping. In this case, the docker run command receives the signal. If the container can process the signal and exit gracefully, this will work. Here is more details on the process.

If the container cannot process the SIGTERM, the other way to mange is to use the Startup and Shutdown lifecycles within the recipe file. In this case, you can change your docker run to name the container and run in detached (background) mode. then when Greengrass stops the component, the Shutdown lifecycle would have a docker stop my_container_name which will complete the shutdown.

Using either approach will ensure that only one instance of the container is running. Note that there may be edge cases, so depending upon the situation, you may want to add additional logic to the recipe file to check for errant processes or running containers just like you would if do this directly from a shell script.

Hope this helps!

AWS
Gavin_A
답변함 2년 전
0

Thanks for the prompt reply, a few more clarifying questions.

Can the "Shutdown" lifecycle be used alongside the "Run" cycle, or does the use of "Shutdown" require that there may a "Startup".

If the component spawns the docker container in detached mode, will the docker output still appear in the greengrass component log as the docker runs?

답변함 2년 전
  • A component can have either Run or Startup paired with Shutdownlifecycle, so it's an either/or scenario.

    Component logs only include std* messaging (definitely stdout, pretty sure stderr to). So in detached mode, by default, docker logs would be need to be run at some point.

  • Hi! Checking in to see if this helped you for the container instances and logging.

  • FWIW: i've also added a docker kill and rm just before i start it up again.. that way if for some reason it didn't shutdown cleanly you won't have a failure to startup

    { "Run": " $(docker kill dockername || true) ; $(docker rm dockername || true); docker run --name=dockername ..... xxxxxxxx.dkr.ecr.ap-southeast-2.amazonaws.com/myimage:latest2 runsomestuff.sh" }

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠