Ok I will summarize info to potentially help others
can state scripts be included in artifacts or they are a part of Mender client?
Both. Client-side state scripts (those for states which are not prefixed with Artifact
) are executed by the mender client regardless of the contents or type of the artifact it installs.
State scripts for states perfixed with Artifact
are intended to be only included in the Artifact itself, thus may vary between Artifacts.
how to design them?
Some examples of client-side state scripts are in the mender client repo. Artifact state scripts may follow the same logic and should follow the same naming format, i.e.
<STATE_NAME>_<ACTION>_<ORDERING_NUMBER>_<OPTIONAL_DESCRIPTION>
retain-ssh-keys
example may give an idea how to transfer files between old and new filesystems when performing full-rootfs updates, if storing persistent files in /data/ is not an option. Yet, IMHO this type of actions should rather be included in Artifact as ArtifactInstall_Enter_...
script as such actions are only needed for full-os updates and not needed to be executed if you perform updates without swithing partitions (i.e. using update modules)
where to place state scripts/how to include in the created artifact/image?
Client state scripts should be placed in /etc/Mender/scripts
of the new rootfs. To add them to an SD image, you can use Modifying disk images workflow from the docs.
To add client state scripts to a Mender artifact, you can use mender-artifact cp
. Keep in mind it is a slow process and takes ~5 min per one file on ~300 MB Artifacts.
In addition, there’s no way of adding Artifact state scripts to already created Mender artifacts with mender-artifact
. Thus if you use mender-convert
workflow and need to include both clien and artifact state scripts, you can discard .mender file generated by mender-convert
, mount .ext4 and copy all required client state scripts inside (as well as your mender.config, identity and inventory if needed), and then create mender Artifact from .ext4 yourself using mender-artifact write rootfs-image
adding all your Artifact scripts by using --script
, something like
mender-artifact --compression "lzma" write rootfs-image \
--file "$releaseName-mender.ext4" \
--device-type "raspberrypi3" \
--artifact-name "$releaseName-mender.mender" \
--script "$scriptsDir/ArtifactInstall_Enter_01_retain_wpa_supplicant" \
--script "$scriptsDir/another_script"
To verify that the scripts are added to the Artifact, you can open .mender as a .tar and check the contents of /header.tar.gz/scripts/