State scripts not getting called

Hi,

I’m trying to implement custom state scripts, but they are not getting called.

They are in /etc/mender/scripts in both the old and new artifact:

root@comp:/etc/mender# tree
.
├── artifact_info
├── mender.conf
└── scripts
    ├── ArtifactCommit_Enter_01.sh
    ├── Download_Enter_01.sh
    ├── Download_Leave_01.sh
    └── version

Version is 3

Here is the deployment log:

root@comp:/etc/mender# cat /var/lib/mender/deployments.0001.1e86afa8-05bb-4f01-b33c-c63190e8a790.log
{"level":"info","message":"Running Mender client version: 4f9c470","timestamp":"2020-07-11T13:24:47-07:00"}
{"level":"info","message":"State transition: update-fetch [Download_Enter] -\u003e update-store [Download_Enter]","timestamp":"2020-07-11T13:24:47-07:00"}
{"level":"info","message":"No public key was provided for authenticating the artifact","timestamp":"2020-07-11T13:24:47-07:00"}
{"level":"info","message":"Opening device \"/dev/sda3\" for writing","timestamp":"2020-07-11T13:24:47-07:00"}
{"level":"info","message":"Native sector size of block device /dev/sda3 is 512 bytes. Mender will write in chunks of 1048576 bytes","timestamp":"2020-07-11T13:24:47-07:00"}
{"level":"info","message":"All bytes were successfully written to the new partition","timestamp":"2020-07-11T13:28:23-07:00"}
{"level":"info","message":"The optimized block-device writer wrote a total of 7921 frames, where 3554 frames did need to be rewritten (i.e., skipped)","timestamp":"2020-07-11T13:28:23-07:00"}
{"level":"info","message":"Wrote 8304721920/8304721920 bytes to the inactive partition","timestamp":"2020-07-11T13:28:23-07:00"}
{"level":"info","message":"State transition: update-store [Download_Enter] -\u003e update-after-store [Download_Leave]","timestamp":"2020-07-11T13:28:23-07:00"}
{"level":"info","message":"State transition: update-after-store [Download_Leave] -\u003e update-install [ArtifactInstall]","timestamp":"2020-07-11T13:28:23-07:00"}
{"level":"warning","message":"Script format mismatch: 'Download_Leave_01.sh' will not be run ","timestamp":"2020-07-11T13:28:23-07:00"}
{"level":"info","message":"Enabling partition with new image installed to be a boot candidate: 3","timestamp":"2020-07-11T13:28:23-07:00"}
{"level":"info","message":"State transition: update-install [ArtifactInstall] -\u003e reboot [ArtifactReboot_Enter]","timestamp":"2020-07-11T13:28:24-07:00"}
{"level":"info","message":"Rebooting device(s)","timestamp":"2020-07-11T13:28:24-07:00"}
{"level":"info","message":"Mender rebooting from active partition: /dev/sda2","timestamp":"2020-07-11T13:28:24-07:00"}
{"level":"info","message":"Running Mender client version: 4f9c470","timestamp":"2020-07-11T13:28:50-07:00"}
{"level":"info","message":"State transition: init [none] -\u003e after-reboot [ArtifactReboot_Leave]","timestamp":"2020-07-11T13:28:50-07:00"}
{"level":"info","message":"State transition: after-reboot [ArtifactReboot_Leave] -\u003e after-reboot [ArtifactReboot_Leave]","timestamp":"2020-07-11T13:28:50-07:00"}
{"level":"info","message":"State transition: after-reboot [ArtifactReboot_Leave] -\u003e update-commit [ArtifactCommit_Enter]","timestamp":"2020-07-11T13:28:50-07:00"}
{"level":"error","message":"Failed to report status: Put https://hosted.mender.io/api/devices/v1/deployments/device/deployments/1e86afa8-05bb-4f01-b33c-c63190e8a790/status: dial tcp: lookup hosted.mender.io: Temporary failure in name resolution","timestamp":"2020-07-11T13:28:50-07:00"}
{"level":"error","message":"error reporting update status: reporting status failed: Put https://hosted.mender.io/api/devices/v1/deployments/device/deployments/1e86afa8-05bb-4f01-b33c-c63190e8a790/status: dial tcp: lookup hosted.mender.io: Temporary failure in name resolution","timestamp":"2020-07-11T13:28:50-07:00"}
{"level":"error","message":"Failed to send status report to server: transient error: reporting status failed: Put https://hosted.mender.io/api/devices/v1/deployments/device/deployments/1e86afa8-05bb-4f01-b33c-c63190e8a790/status: dial tcp: lookup hosted.mender.io: Temporary failure in name resolution","timestamp":"2020-07-11T13:28:50-07:00"}
{"level":"info","message":"State transition: update-commit [ArtifactCommit_Enter] -\u003e update-pre-commit-status-report-retry [ArtifactCommit_Enter]","timestamp":"2020-07-11T13:28:50-07:00"}
{"level":"info","message":"State transition: update-pre-commit-status-report-retry [ArtifactCommit_Enter] -\u003e update-commit [ArtifactCommit_Enter]","timestamp":"2020-07-11T13:29:19-07:00"}
{"level":"info","message":"Committing update","timestamp":"2020-07-11T13:29:19-07:00"}
{"level":"info","message":"State transition: update-commit [ArtifactCommit_Enter] -\u003e update-after-first-commit [none]","timestamp":"2020-07-11T13:29:19-07:00"}
{"level":"info","message":"State transition: update-after-first-commit [none] -\u003e update-after-commit [ArtifactCommit_Leave]","timestamp":"2020-07-11T13:29:19-07:00"}
{"level":"info","message":"State transition: update-after-commit [ArtifactCommit_Leave] -\u003e cleanup [none]","timestamp":"2020-07-11T13:29:19-07:00"}
{"level":"info","message":"State transition: cleanup [none] -\u003e update-status-report [none]","timestamp":"2020-07-11T13:29:19-07:00"}

My Download_Leave_01.sh script isn’t run due to a “Script format mismatch”:

{"level":"warning","message":"Script format mismatch: 'Download_Leave_01.sh' will not be run ","timestamp":"2020-07-11T13:28:23-07:00"}

The other two scripts are not mentioned at all. All three scripts were set up to stop the update for testing purposes… but the update went through.

I put the scripts in /etc/mender/scripts in my original images (i.e. before I hand them over to mender-convert).

The scripts are basically just wrappers around a python module that decides what to do; this is to implement some tricky update logic as I mentioned
here. The Download_Leave script looks like this:

#!/bin/bash

echo "$(mender -show-artifact): $(basename "$0") was called" >&2

# directory of this file
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

UPDATER_SCRIPT=$SCRIPT_DIR/../../../root/updater/updater_state_script.py

# ask the updater state script what to do
$UPDATER_SCRIPT Download_Leave
updater_code=$?

# return the value of provided by the updater state script
exit $updater_code

I’ve tried running the state scripts manually on the device, and they work as expected.

I see in the documentation that “The Artifact scripts are part of the Artifact and are delivered to the Client inside the Artifact”… but it’s not clear to me where they need to go and how to get them there. I am building artifacts from an Ubuntu image using mender-convert.

What do I need to do to get my state scripts to run?

Thanks!

My Download_Leave_01.sh script isn’t run due to a “Script format mismatch”:
[…]
What do I need to do to get my state scripts to run?

You’re not following the naming convention, which must be adhered to exactly as specified in the section of the documentation you referenced. Try renaming your scripts to remove the .sh suffix or replace it with _something-descriptive-for-the-specific-script.

This was something I learned when I first tried to use state scripts - ran into the same error messages, and it took me a while to twig that the format of the name was what they were complaining about.

Thanks, that did it!

Also note that the Artifact scripts are handled differently and are not part of the root filesystem. See this post that I recently made in another thread on this same topic.

Drew

Thanks, that took me forever to find but I did figure it out eventually :slight_smile:

I think a description of how to do that (basically what’s in your other post) should be added to the docs discussing the state scripts, because currently all that entire page says about this is “The Artifact scripts are part of the Artifact and are delivered to the Client inside the Artifact.” - no mention of how to actually get the artifact scripts in the Artifact (at least for non-Yocto images).

Yes, agreed and we are in the process of a major overhaul of the docs so that should eventually make its way into them.
Drew