- Newest
- Most votes
- Most comments
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!
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?
Relevant content
- asked 2 months ago
- asked a year ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
A component can have either
Run
orStartup
paired withShutdown
lifecycle, 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" }