State Scripts sanity check

I have the following file:

/etc/mender/scripts/ArtifactReboot_Enter_01_machine-safe.sh

Contents are as follows:

#!/usr/bin/env bash

1>&2 echo "Script aborted due to failed bash command. Telling Mender to try later";

# Return code 21 to tell Mender to try again later
exit 21;

It has the following properties:
ls -alrt ArtifactReboot_Enter_01_machine-safe.sh
-rwxrwxrwx 1 root root 235 Aug 15 11:08 ArtifactReboot_Enter_01_machine-safe.sh

I can run the file manually:

# ./ArtifactReboot_Enter_01_machine-safe.sh
Script aborted due to failed bash command. Telling Mender to try later

# echo $?
21

Version of mender:
# mender -version
2.0.0
runtime: go1.9.4

My ultimate goal is for the script to stall the reboot under certain circumstances, but it doesn’t seem to stall it at all. What am I doing wrong?

Scripts for states starting with Artifact must be part of the Mender Artifact and not the root filesystem.

You can provide scripts when creating the Mender Artifact with the -s flag,

$ mender-artifact write rootfs-image --help
NAME:
   mender-artifact write rootfs-image - Writes Mender artifact containing rootfs image

USAGE:
   mender-artifact write rootfs-image [command options] <image path>

OPTIONS:
   --file FILE, -f FILE             Payload FILE.
   --device-type value, -t value    Type of device(s) supported by the Artifact. You can specify multiple compatible devices providing this parameter multiple times.
   --artifact-name value, -n value  Name of the artifact
   --output-path value, -o value    Full path to output artifact file.
   --version value, -v value        Version of the artifact. (default: 3)
   --key value, -k value            Full path to the private key that will be used to verify the artifact signature.
   --script value, -s value         Full path to the state script(s). You can specify multiple scripts providing this parameter multiple times.

If you are using Yocto, take a look at the reference recipe for state-scripts,

1 Like