Hello Mender Community,
I hope you are all doing well.
I am currently working with Mender to deploy updates to my devices and have a question regarding the capability to automatically execute a script within a single-file Mender artifact during deployment.
Specifically, I have reached the following command:
./single-file-artifact-gen \
--device-type EC-R3566PC \
-o artifact-helloworld.mender \
-n updated-helloworld-1.0 \
--software-name helloworld \
--software-version 4.4 \
--dest-dir /home \
helloworld.sh \
--install \
--state-script state_script
However, I am unsure if Mender allows for the automatic execution of the specified script during deployment. Could anyone provide guidance on how to achieve this?
Any suggestions or best practices you might have would be greatly appreciated.
Thank you for your assistance!
Hi @Domenico232,
Thanks for reaching out! State scripts in general are covered in the documentation. Please check this out to understand at which points in the installation procedure a custom state script can be run.
To have a state script included when an artifact is created, you need to pass the -s
flag with the argument reference an executable script which matches the naming logic. Example:
mender-artifact create ... -s ArtifactInstall_Enter_10
The mentioned single-file-artifact-gen
script is a wrapper around mender-artifact
, which takes care of the specifics of the single-file
update module. It evaluates the command line arguments, until either there are no more of them, or it hits a --
marker. If such a marker is found, everything after the marker is passed directly to mender-artifact
.
So to extend your given command into a working example:
cat >> ArtifactInstall_Enter_10 << EOF
#!/usr/bin/env sh
>&2 echo "Printed from ArtifactInstall_Enter_10"
EOF
chmod a+x ArtifactInstall_Enter_10
./single-file-artifact-gen \
--device-type EC-R3566PC \
-o artifact-helloworld.mender \
-n updated-helloworld-1.0 \
--software-name helloworld \
--software-version 4.4 \
--dest-dir /home \
helloworld.sh \
--\
-s ArtifactInstall_Enter_10
Upon installation, you can find the output in journalctl -u mender-updated
:
Oct 17 08:10:35 qemuarm64 mender-update[544]: record_id=512 severity=info time="2024-Oct-17 08:10:35.808984" name="Global" msg="Installing artifact..."
Oct 17 08:10:35 qemuarm64 mender-update[544]: record_id=513 severity=info time="2024-Oct-17 08:10:35.949002" name="Global" msg="Sending status update to server"
Oct 17 08:10:36 qemuarm64 mender-update[544]: record_id=514 severity=info time="2024-Oct-17 08:10:36.360651" name="Global" msg="Running State Script: /var/lib/mender/scripts/ArtifactInstall_Enter_10"
Oct 17 08:10:36 qemuarm64 mender-update[544]: record_id=515 severity=info time="2024-Oct-17 08:10:36.408544" name="Global" msg="Collected output (stderr) while running script: Printed from ArtifactInstall_Enter_10"
(note that my example was extracted on a qemuarm64
device)
Hope this helps,
Josef