State-Scripts do not get executed

We are trying to add a state-script to our image deployments that waits until the time is synced and the network is up. Unfortunately I am unable to figure out, how I can get a state-script to be executed during the update process. I placed the scripts in /etc/mender/scripts:

$ tree /etc/mender/scripts/
/etc/mender/scripts/
|-- ArtifactReboot_Leave_00
|-- Sync_Enter_00
`-- version

0 directories, 3 files

I only want to have one script but I tried different naming schemes, that is why there are two files. The version file only contains the number 3. Both scripts have 755 permissions.

Here is part of my deployment log:

{"level":"info","message":"Daemon terminated with SIGTERM","timestamp":"2021-07-16T15:10:27Z"}
{"level":"error","message":"Error rebooting device: signal: terminated","timestamp":"2021-07-16T15:10:27Z"}
{"level":"info","message":"Running Mender client version: 2.5.0","timestamp":"2021-07-16T15:11:04Z"}
{"level":"info","message":"State transition: init [none] -\u003e after-reboot [ArtifactReboot_Leave]","timestamp":"2021-07-16T15:11:04Z"}
{"level":"debug","message":"received the GET_AUTH_TOKEN action","timestamp":"2021-07-16T15:11:04Z"}
{"level":"debug","message":"Have U-Boot variable: upgrade_available=1","timestamp":"2021-07-16T15:11:04Z"}
{"level":"debug","message":"List of U-Boot variables:map[upgrade_available:1]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"info","message":"State transition: after-reboot [ArtifactReboot_Leave] -\u003e after-reboot [ArtifactReboot_Leave]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"received the GET_AUTH_TOKEN action","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Handling state after reboot","timestamp":"2021-07-16T15:11:05Z"}
{"level":"info","message":"State transition: after-reboot [ArtifactReboot_Leave] -\u003e update-commit [ArtifactCommit_Enter]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"received the GET_AUTH_TOKEN action","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"statescript: The timeout for executing scripts is not defined; using default of 1h0m0s seconds","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"statescript: The timeout for executing scripts is not defined; using default of 1h0m0s seconds","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Handle update commit state","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"received the GET_AUTH_TOKEN action","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Connecting to server hosted.mender.io","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Status reported, response 204 No Content","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Have U-Boot variable: upgrade_available=1","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"List of U-Boot variables:map[upgrade_available:1]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"info","message":"Committing update","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Probing the Bootloader environment for which separator to use","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Writing map[mender_uboot_separator:1] to the U-Boot environment, using separator:  ","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Have U-Boot variable: mender_uboot_separator=1","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"List of U-Boot variables:map[mender_uboot_separator:1]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Writing map[mender_uboot_separator:] to the U-Boot environment, using separator:  ","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Using ( ) as the bootloader environment separator","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Writing map[upgrade_available:0] to the U-Boot environment, using separator:  ","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Committing artifact name: 2021-07-16-1427-pi3-buster-armhf","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Committing artifact type-info provides","timestamp":"2021-07-16T15:11:05Z"}
{"level":"info","message":"State transition: update-commit [ArtifactCommit_Enter] -\u003e update-after-first-commit [none]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"info","message":"State transition: update-after-first-commit [none] -\u003e update-after-commit [ArtifactCommit_Leave]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"info","message":"State transition: update-after-commit [ArtifactCommit_Leave] -\u003e cleanup [none]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"statescript: The timeout for executing scripts is not defined; using default of 1h0m0s seconds","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Handling Cleanup state","timestamp":"2021-07-16T15:11:05Z"}
{"level":"info","message":"State transition: cleanup [none] -\u003e update-status-report [none]","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Handling update status report state","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"received the GET_AUTH_TOKEN action","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Connecting to server hosted.mender.io","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Status reported, response 204 No Content","timestamp":"2021-07-16T15:11:05Z"}
{"level":"debug","message":"Reporting complete","timestamp":"2021-07-16T15:11:05Z"}

The mender client somehow acknowledges that there are scripts (since there are some statescript messages in the log) but they do not seem to get executed. Can someone tell me what I am doing wrong?

Thanks for your help.

It looks like you are adding Artifact* scripts to the /etc/mender/scripts folder. This is not how Artifact* state scripts work. They need to be added to the artifact itself with mender-artifact’s -s option. You can see the docs for how to do this for a Debian based and Yocto based build systems, respectively. Or, if you’re calling mender-artifact directly, just use -s <SCRIPT>.

Thanks for you answer! I am aware that Artifact scripts need to be placed inside the Artifact but I also read in the documentation that it is possible to place state-scripts for rootfs updates in the /etc/mender/scripts folder. I tried the Artifact* prefix, because I could not get the non-prefixed scripts to run.

There is a predefined list of state scripts that can run from /etc/mender/scripts, and these are:

  • Idle
  • Sync
  • Download

All the others that have an Artifact prefix need to be added to the artifact using the -s option.

1 Like

Ok, thanks for the clarification. I tried the different route and added my script to the artifact which worked instantly. So I will just stick to this method.