- Newest
- Most votes
- Most comments
You should use bootstrap if you only want the lifecycle to run once:
- Platform:
os: all
Lifecycle:
bootstrap:
script: |-
echo "Bootstrapping"
exit 0
startup:
script: echo "Finished bootstrapping"
You can also use "skipif" if you want the lifecycle to skip on condition checks:
- Platform:
os: linux
Lifecycle:
install:
Skipif: onpath git
Script: sudo apt-get install git
It sounds like you're experiencing an issue with your AWS IoT Greengrass component executing on every device restart, which is not the desired behavior. Let's address this issue and provide a solution.
The component lifecycle defines how and when a component behaves during different stages. If your component is executing on every restart, it's likely because the lifecycle script is set to run during the install phase, which occurs not only on new deployments but also on device restarts.
To make your component run only when a new version is deployed, you should modify your component's recipe file. Instead of using the install lifecycle, you should use the following lifecycle stages:
-
Bootstrap: This runs before the install lifecycle when the component is deployed for the first time, when the component version changes, or when the bootstrap script itself changes due to a configuration update.
-
Install: This runs when the component is installed on the core device.
-
Run: This defines how the component should run after installation.
Here's an example of how you might structure your lifecycle in the recipe file:
Lifecycle: Bootstrap: Script: | # Your bootstrap script here # This runs only on first install, version change, or bootstrap script change Install: Script: | # Your installation script here # This runs when the component is installed Run: Script: | # Your main component logic here # This runs after installation
By structuring your lifecycle this way, you ensure that the main component logic (in the Run script) only executes when the component is newly deployed or updated, not on every device restart.
If you're having trouble deploying the component after adding the bootstrap lifecycle, make sure that your bootstrap script is correctly formatted and doesn't contain any errors. Also, ensure that you're using the correct indentation in your YAML recipe file, as YAML is sensitive to indentation.
Remember, when you make changes to your component's recipe, you need to increment the component version and create a new deployment for the changes to take effect.
If you continue to have issues, you may want to check the Greengrass logs for any error messages that could provide more insight into why the deployment is failing.
Sources
Develop AWS IoT Greengrass components - AWS IoT Greengrass
AWS IoT Greengrass component recipe reference - AWS IoT Greengrass
Relevant content
- asked 3 years ago
- asked a year ago