State scripting for Raspberry PI board running ubuntu 18.04

Hi All,

As a beginning, I successfully completed the single file update using mender in Raspberry PI board running with Ubuntu 18.04. Now I have another two things to do,

  1. How to update a complete folder using mender ?
  2. I would like to run a custom shell script as soon as the mender updated the new file. How to do that in mender using state scripting, I have read about the state scripting documentation and I have basic idea about the naming convention and the folder structure. But I would like to get the procedure to run a script here.

Any help will be completely appreciable. As I am new to mender, wish to be part of this.

Hi all,

As I am stuck in the state scripting part, expecting some help from the mender experts or people who already worked with mender.

Regards
Dipin

How to update a complete folder using mender

You can use the Directory Update Module to deploy directory updates. There are usage instructions in that link. Note that you have to put the update module in the /usr/share/mender/modules/v3 directory on the device before you can use them.

I would like to run a custom shell script as soon as the mender updated the new file. How to do that in mender using state scripting, I have read about the state scripting documentation and I have basic idea about the naming convention and the folder structure. But I would like to get the procedure to run a script here.

Just specify -s ArtifactInstall_Leave_50_myscript when you make the artifact, and this script will execute after the install stage. You can replace myscript with whatever you want, and the contents can be whatever you want. If you use the artifact generation script for the Directory Update Module, then you can specify such options at the end, after a --. So for example:

./directory-artifact-gen -n ${ARTIFACT_NAME} -t ${DEVICE_TYPE} -d ${DEST_DIR} -o ${OUTPUT_PATH} ${FILE_TREE} -- -s ArtifactInstall_Leave_50_myscript

Thanks for you help.

I am getting an error like ./directory-artifact-gen: line 32: hash: mender-artifact: not found. But I downloaded the latest mender artifact binary and located in /usr/bin/ folder of my computer.

Please suggest to resolve this issue

Did you also make it executable?

chmod ugo+x /usr/bin/mender-artifact

Solved the issue, Thank you very much.
Successfully updated directory also.

Tried to run a script as per your suggestion. I could able to sucesfully create an artifact with my custom script. But the update fails. Attached the screenshot of the failure. My script name is ArtifactInstall_Leave_50_myscript

.

Any modifications required in the client side to run this script?

What does the log say?

2019-10-31 09:01:41 +0000 UTC error: transient error: error executing leave script for update-install state: error running leave state script(s) for ArtifactInstall state: statescript: error executing ‘ArtifactInstall_Leave_50_myscript’: -1 : fork/exec /var/lib/mender/scripts/ArtifactInstall_Leave_50_myscript: exec format error
2019-10-31 09:01:41 +0000 UTC info: State transition: update-install [ArtifactInstall] -> rollback [ArtifactRollback].

This is the part of log which talks about the script.

It will be great help if anyone can help me to solve this issue.

Are you able to execute the script manually, if you copy it over to the device? Again you will need to make it executable if it isn’t.

What kind of script is it? Bash script? Maybe you can post it here, if it’s not sensitive.

I could able to execute the script manually from the server environment. If i make the artifact along with script, the new directory is not even updating in the device. Its an empty folder.
The script is a small shell script. The content of the script is only echo “Hello” for testing purpose.
And while naming the script file it should be only ArtifactInstall_Leave_50_myscript or ArtifactInstall_Leave_50_myscript.sh

A couple of things to check:

  • Does the script contain the #!/bin/sh shebang at the top of the script? If is is #!/bin/bash, try changing it to #!/bin/sh
  • Are any of your filesystems mounted with the noexec option? What is the output from mount?

The .sh extension makes no difference, the script should execute either way.

Thank you very much :grinning:
After changing to #!/bin/sh i could able to deploy the artifact without any error. But how can I verify that my script is running on the device. I am not able to see my script on the device actually

You cannot see it directly, because the script only exists while the update is being installed. But if the script leaves a trace somewhere (for example touch /tmp/script-was-here), you can look for it afterwards.

Thank you for your help… I created a folder using script, so that I can make sure the script is working. Tested the same here and it worked well

./directory-artifact-gen -n {ARTIFACT_NAME} -t {DEVICE_TYPE} -d {DEST_DIR} -o {OUTPUT_PATH} ${FILE_TREE} – -s ArtifactInstall_Leave_50_myscript

This command gives: – -s command not found and without --, it gives unsupported option-s