- Newest
- Most votes
- Most comments
Grengrass V2 component recipes have no way of specifying that a component conflicts with another (i.e. that one component cannot be started while the specified other is running). The easiest mitigation without any changes to either recipe is to deploy the removal of the old component, and then in a different, subsequent deployment add the new, conflicting component. This guarantees the shutdown of the old component before the run step of the new component.
answered 10 months ago
In AWS IoT Greengrass v2, the issue you're experiencing is likely related to the shutdown script timing out before it can fully complete its task. When a component is being replaced or updated, Greengrass has a default timeout period for the shutdown script to complete. If your shutdown script doesn't finish within this configured timeout, Greengrass will proceed with starting the new component, even if the old container is still running.
There are a few ways to address this issue:
-
Increase the timeout period for your shutdown script in the component recipe. You can specify a longer
Timeoutvalue in the recipe'sshutdownsection to give your container more time to stop properly. -
Modify your shutdown script to be more effective. Instead of just using
docker stop, which sends a SIGTERM and waits for the container to gracefully shut down, you might need a more forceful approach. Consider using:
docker stop <container name> || docker rm -f <container name> || true
This will attempt to stop the container gracefully first, then forcibly remove it if needed.
- Use
docker compose downinstead of just stopping the container if you're using Docker Compose. This ensures containers are properly removed:
docker compose -f {artifacts:path}/docker-compose.yml down
This stops and removes containers but keeps the images intact.
- For database containers specifically, you might need to add additional commands to ensure proper shutdown of the database process before stopping the container, as databases often need time to flush data to disk and release locks.
Remember that when a component's shutdown script fails to complete within the timeout period, Greengrass logs will show a SHUTDOWN_TIMEOUT error. Checking these logs can help confirm if this is indeed the issue you're facing.
Sources
Error response from daemon: Conflict. The container name "/<container_name>" is already in use by container "xxxx". You have to remove (or rename) that container to be able to reuse that name! | AWS re:Post
Detailed component status codes - AWS IoT Greengrass
answered 10 months ago
No, the docker stop command completes in about 1 second
Relevant content
asked 4 years ago
asked 3 years ago
- AWS OFFICIALUpdated 5 years ago

Judging by the container uptime, greengrass didn't even try to run the shutdown script of the old component down before executing the run script of the new component
Just confirmed by staging a deployment and monitoring lifecycle logs:
New component switched to RUNNING at 9:02:45 Old component switched to STOPPING at 9:02:56
So Greengrass does not stop old component before starting new ones if those components are different. It only does that for new versions of existing components.
So if I deploy new version of the same component, then shutdown script will run before the run script of the new version. But if I deploy a new component, the old components will not be shut down and removed before my new component is started. This behavior is not documented anywhere.
Is there a reason the database component must be renamed instead of just version bumped? Components can only blocked by shutdown step(s) of their dependencies, or else by an existing, in-removal version of itself.