Skip to content

(Nucleus): Shutdown script is not called before run script of new components #1735

@megakoresh

Description

@megakoresh

Describe the bug
Since this behavior is not documented anywhere, I am reporting it as a bug.

When you deploy new components to a device, their startup and run scripts will be executed before old no-longer-deployed component's shutdown scripts are called.

To Reproduce
Create a database component, e.g.

RecipeFormatVersion: "2020-01-25"
ComponentName: dev.development.QuestDB
ComponentVersion: 8.3.3
ComponentType: "aws.greengrass.generic"
ComponentDescription: QuestDB database
ComponentPublisher: SwagCorp
ComponentConfiguration:
ComponentDependencies:
  aws.greengrass.DockerApplicationManager:
    VersionRequirement: ">=2.0.0 <2.1.0"
    DependencyType: "HARD"
Manifests:
- Platform:
    os: "linux"
    architecture: "amd64"
  Lifecycle:
    Setenv:
      WORKDIR: "{work:path}"
    run: "docker run --rm --network host --name questdb -v questdb-data:/var/lib/questdb questdb/questdb:8.3.3"
    shutdown: "docker stop questdb || true"

Then, say you want to modify the image and you decide to make your own version of this database image with its own component:

RecipeFormatVersion: "2020-01-25"
ComponentName: dev.development.MyQuestDB
ComponentVersion: 1.0.0
ComponentType: "aws.greengrass.generic"
ComponentDescription: QuestDB database
ComponentPublisher: SwagCorp
ComponentConfiguration:
ComponentDependencies:
  aws.greengrass.DockerApplicationManager:
    VersionRequirement: ">=2.0.0 <2.1.0"
    DependencyType: "HARD"
Manifests:
- Platform:
    os: "linux"
    architecture: "amd64"
  Lifecycle:
    Setenv:
      WORKDIR: "{work:path}"
    run: "docker run --rm --network host --name questdb -v questdb-data:/var/lib/questdb -e  QDB_LOG_W_STDOUT_LEVEL=ERROR 133769420.dkr.ecr.eu-west-1.amazonaws.com/questdb:8.3.3"
    shutdown: "docker stop questdb || true"
Artifacts:
- Uri: "docker:133769420.dkr.ecr.eu-west-1.amazonaws.com/questdb:8.3.3"
  Unarchive: "NONE"
  Permission:
  Read: "OWNER"
  Execute: "NONE"

Now when you deploy this second component to your target, it will fail to run because they use the same container name. And if you give them different container names, the new component will still fail because it uses the same volume so new container won't be able to lock the table registry file.

Expected behavior
The old component's shutdown script completes before new component is started.

Actual behavior
The new component is started before old component's shutdown script runs.

Environment

  • OS: Ubuntu 22.04
  • JDK version: OpenJDK 11.0.27
  • Nucleus version: 2.14.3

Additional context

Why is the lifecycle behavior so badly documented in general? There is zero information on when and how different lifecycle scripts are called, relative to other components and deployments. The only thing documentation says is what lifecycle script runs when a component enters a certain lifecycle stage. Anyone who wants to find out when the lifecycle stages actually change and under which conditions is left scouring forums and running experiments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions