State scripts: A powerful tool for customizing your OTA software updates
When deploying over-the-air software updates, you will benefit from having the capability to customize software releases and installations on your devices with more flexibility and control over your deployments. During the installation process on the device Mender State scripts and Update Modules are complementing features to customize the installation process to meet your requirements. In this post, we only cover State scripts.
State scripts are used to customize the overall workflow of the installation process. Mender state scripts are more useful than pre/postinstall scripts that may currently be found in some homegrown or other solutions because they can be run in more states and between any state transition, not just (before/after) the install state. The update process with Mender is in nine states in a live device in the field and each state can either be a transition into a state or out from a state. This enables more control over your updates process.
For example, for many devices with a display that interacts with an end user, it is desirable to ask the user before applying the update. This is commonly seen on smartphones, where it will ask a user if they want to update to the latest release of Android or iOS and it only starts after they hit "Apply".
There are two components in the Mender architecture - the server and the client (device). The Mender client runs on the device and reports to the server periodically to check for updates. In the Idle state there is no communication with the server and there is no update in progress. In the Sync state, communication with the server is established while checking if there is an update for the given device and when inventory data is sent to the server. In the user confirmation example, a State script which is implemented as part of a Mender Artifact enables this use case with a script written to create the dialog box on the UI framework used. The script will wait for user input and the client will wait with the update process while waiting for the script to finish. This script can be run in the Download_Enter
state as shown in the diagram below, and the user will be asked before the download begins or it can also be run in the Download_Leave
state, if you want the download to finish first, and the user only to accept installing the update and rebooting.
Another example is, in order to save power and bandwidth, network connectivity such as WiFi may not be enabled by default on devices in the field, so you want to be able to selectively enable it when needed and a state script can allow this to be easily implemented. You can also explicitly disable network connectivity again after Mender has finished the deployment.
There are many use cases that can be implemented to allow you to customize your release and install process and we’ve highlighted just a couple of examples. Scripts can be written in any language and can be utilized to implement use cases that are specifically tailored to your product or update process by inserting scripts at certain steps in the process.
Learn more in this tutorial on how to create state scripts with Mender.
Recent articles
An Overview of EU Cyber Resilience Act (CRA) Compliance
Mender versioning: New releases by component
Driving secure innovation: ISO/SAE 21434 & UNECE compliance
Learn why leading companies choose Mender
Discover how Mender empowers both you and your customers with secure and reliable over-the-air updates for IoT devices. Focus on your product, and benefit from specialized OTA expertise and best practices.