Understanding State Scripts

Hello,

I am trying to get a better understanding of State scripts and its difference from updateModules package.

Please correct me if I am wrong.
Mender by default without adding any State Scripts will go through the nine states which are

1.     Idle
2.     Sync
3.     Download
4.     ArtifactInstall
5.     ArtifactReboot
6.     ArtifactCommit
7.     ArtifactRollback
8.     ArtifactRollbackReboot
9.     ArtifactFailure

State scripts by definition are a means to perform a specific action between any state transition.
So If I don’t need any custom action to be performed during state transition. I don’t have to include any state scripts and therefore there won’t be any state scripts present in any physical location

Is my understanding correct?

Now two questions.

Lets say in the future I need to add state scripts. Can I add those script and include them as a part of delta update?
So all the transitions between 9 states where do they take place. Or who instructs them to do that. Does that happen in the u-boot? And is this what updateModules package takes care of ?

Thanks

Great questions.

Is my understanding correct?

Yes, your understanding is correct.

Lets say in the future I need to add state scripts. Can I add those script and include them as a part of delta update?

Yes you can.

To clarify

States 4-9 you add to the Mender Artifact, meaning that they are delivered together with your payload (image or delta update).

States 1-3 must be part of the rootfs as these are executed before the Mender Client has downloaded an Artifact. If they are not part of the rootfs, and you would like to add them, they would be executed on the next update.

So all the transitions between 9 states where do they take place

All scripts are executed by the Mender client in user-space.

And is this what updateModules package takes care of ?

Update Modules are really decoupled from state-scripts. If you write an Update Module you would actually provide custom implementation of states (e.g a custom ArtifactInstall), while state-scripts are just executed before/after a given state.

Update modules enable more update use-cases beside image based updates, as they are listed here:

So when you say Mender-client that’s the mender service that is running?

The reason I brought up Update Module it is because. I remember when I was first integrating it. The rootfs update complained saying a particular folder structure was not available. And It went away as soon as I added Update Modules package from Mender-Demo.

But this really clears a lot of doubts and questions. Thank you

Yes.

The rootfs update complained saying a particular folder structure was not available. And It went away as soon as I added Update Modules package from Mender-Demo.

Update Modules are optional if you are only using rootfs image updates. Delta updates is actually an update module as well so for this it is required.

1 Like

Thank you. This has made my life so much better