Skip to content

Why is shutdown script on component in greengrass deployment not completing before new components are starting?

0

We have components in docker containers, one of which is a database. We renamed the database component and try to deploy it. When the new deployment is executed, the new component is unable to start because old component's container is still running and locking files inside the database volume. We have run scripts like this

docker run --rm --name <container name> -v <volume name>:/data <container image>

And a recover script is defined as well, identical to the run script.

The shutdown script is

docker stop <container name> || true

The || true part is because sometimes when the run fails the container is auto-removed and then the shutdown script fails because the container doesn't exist.

We changed the container name in the new component, no other changes were made. The lock file inside the volume is now preventing new component from starting because old container still runs, even though the shutdown script should have killed it.

Nucleus version is 2.14.3

  • 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.

asked 10 months ago145 views

2 Answers
0

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.

AWS

answered 10 months ago

-1

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:

  1. Increase the timeout period for your shutdown script in the component recipe. You can specify a longer Timeout value in the recipe's shutdown section to give your container more time to stop properly.

  2. 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.

  1. Use docker compose down instead 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.

  1. 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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.