Greengress IoT Deployment while deploying docker container from ECR doesn't stop previous run

0

I have my docker container hosted in ECR, my component recipe is:

{
  "RecipeFormatVersion": "2020-01-25",
  "ComponentName": <component-name>,
  "ComponentVersion": "1.0.46",
  "ComponentType": "aws.greengrass.generic",
  "ComponentDescription": "A component that runs a Docker container from a private Amazon ECR image.",
  "ComponentPublisher": "Amazon",
  "ComponentDependencies": {
    "aws.greengrass.DockerApplicationManager": {
      "VersionRequirement": ">=2.0.0 <2.1.0",
      "DependencyType": "HARD"
    },
    "aws.greengrass.TokenExchangeService": {
      "VersionRequirement": ">=2.0.0 <2.1.0",
      "DependencyType": "HARD"
    }
  },
  "Manifests": [
    {
      "Platform": {
        "os": "all"
      },
      "Lifecycle": {
        "Run": "docker run --rm --net=host <image_name>",
        "Shutdown": "docker stop $(docker ps -a -q --filter ancestor=<image_name> --format=\"{{.ID}}\")"
      },
      "Artifacts": [
        {
          "Uri": <image_uri>,
          "Unarchive": "NONE",
          "Permission": {
            "Read": "OWNER",
            "Execute": "NONE"
          }
        }
      ]
    }
  ],
  "Lifecycle": {}
}

My question is, sometimes when the internet connection is slow, the previous deployment's docker run doesn't stop, so I end up having 2 running docker containers. How can I ensure the previous one stops, I have added -rm and a SHUTDOWN command.

demandé il y a 2 ans271 vues
2 réponses
0

Hi, can you try forwarding signals to the container itself?

Add --sig-proxy=true to your run command. You can remove the shutdown phase.

AWS
répondu il y a 2 ans
  • Thanks for the response. Doesn't work unfortunately, I still have 2 containers running. I realized this happens when a new version of the docker container is published to ECR and then deployed.

  • Is your process able to process the SIGTERM which is sent by Greengrass? What happens when docker stop is run during shutdown?

0

Hi!

You're on the right approach. In the recipe file above, you are mixing Run with Shutdown. Run stands on its own and is good for foreground processes. But in that case, you must honor and process the SIGTERM received.

With Shutdown you would use Startup instead of Run. For that, Startup would do a docker run -d --name CONTAINER_NAME and name the container, while Shutdown would do a docker stop CONTAINER_NAME.

In summary, Run requires you to run the component in foreground and process SIGTERMs when Greengrass issues a stop to the component. Startup and Shutdown require a exit code of 0 for each, and your Shutdown process would need to know the running container (or process).

HTH!

AWS
Gavin_A
répondu il y a 2 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions