Mender 2.0 - How to get the update progress from standalone mender?

Hi,

I understood that, the mender have logs and we can pipe/grep the logs to get the required data.
But, this is not something recommended to use in our project :zipper_mouth_face:

Hence, I would like to know, how to get the update progress from mender client in standalone mode? Whether I can get the progress via a state script? Should I edit the mender client source to get the progress directly to a file (or some global variable which can pass the progress data to C application)?

Apart from progress, we also need to get the update/fail/rollback status via better API calls which do not have these logs grepping and parsing method.

Please let me know how to achieve this :confused:

1 Like

Hence, I would like to know, how to get the update progress from mender client in standalone mode?

There is currently no IPC mechanism to get the progress of download state and you can not get this information using state-scripts.

So you would need to change the code, to provide an interface to this information, e.g exposing an HTTP server, or implement D-bus, raw unix sockets or files and there are probably other options as well.

Apart from progress, we also need to get the update/fail/rollback status via better API calls which do not have these logs grepping and parsing method.

It seems that this can be done “outside” of Mender, or using state-scripts to some expect and only for the 2.0 version.

There is one example using d-bus here,

1 Like

@mirzak, May I know how you use the d-bus example with mender? Are you passing the state information from Mender client to Qt GUI? I didn’t get the complete picture by just seeing the scripts so asked :slight_smile:

Actually @texierp, has created these scripts so he can best answer that :slight_smile:

Are you passing the state information from Mender client to Qt GUI?

But I think this is a correct understanding, but these can be easily modified to pass the information to non Qt apps as well as long they can interface with D-bus.

2 Likes

@ajithpv, Yes you’re right, The main idea is to be able to manage the full update process via a simple graphical interface with Qt (QML) for instance (retry later, validation and so on). You can find a very basic implementation (without the GUI), for sure, I’ll try to publish the rest of the project (a little cleaning before :wink:).

As Mirza said, with D-Bus you can work with an another framework. For a generic approach (C/C++), it is possible to use sd-bus also.

1 Like

The use case to get the current state of the daemon seems quite common.

It would be nice to have an API to get it through one of the several available IPC like D-Bus or HTTP server.

But by looking at the source code, it does not seem easy to get the state because during a standalone update, the daemon does not seem to be aware of the process actually.

My real issue is that the state-scripts only handle transitions but if the client, say a GUI, is not ready at the right moment, the information is lost.

Do you have any though of a possible and preferable solution that one could try to implement?

AFAIK, standalone have a different code flow and is not calling any daemon logic inside the standalone (except calling mender daemon command option).

You can use the D-Bus to get the state transitions from the statescripts to another application (say a GUI on the client) as how @texierp done.

But, the real problem comes when you need to get more detailed information on the update (say, why the update has failed or what is the current progress of streaming etc.). This required the mender client modification. When I see the source, all these cases are handling with the if-else methods and one need to check all these cases and transfer the information to outside world.

One more catch is that, if you are using the IPC, then you will not get the previous state after the reboot (reboot can happen due to various reasons). Hence, currently, I stick to a file write approach where the file is stored outside filesystem (Ex: data partition). In this way, any application can read and get the status and progress at anytime (even if the mender standalone is not running).

Thanks for your answer @ajithpv
I will try to stick with file writes.

Just a note, that this has changed slightly with the release of 2.x.x, where the standalone mode does share more of the code with managed mode. e.g the 2.x.x Mender client will call state-scripts in standalone mode as well (not all states but some of them), list of states can be found here,

https://docs.mender.io/2.0/artifacts/state-scripts#standalone-mode

It depends on the use case. You don’t have to stick with the file writes if you don’t have a specific need for it :slight_smile:

Whether I will get what kind of error (when it failed to update the system) from the ArtifactFailure script? I’m just curious to know whether the state script gives the high level transitions (from one state to another) alone or will give more details of a particular state (errors, progress etc)

No there is no additional information provided to state-script, e.g why it entered a certain state.

For now, my use case is to know after a boot if I need to commit a new Artifact.

I have seen this fork that adds a isCommitted flag to the mender tool.
Could be interested too.

You can run mender -commit unconditionally. The Mender client will know if there is something to commit or not, it also has a specific return code if there was nothing to commit.

"Commit current Artifact. Returns (2) if no update in progress"

1 Like

Ok, that is interested @mirzak, thank you. But in my case I would prefer a manual action on the web gui to commit.

I am working on a headless system (robotics), so if I messed up the network settings in an update, I won’t be able to connect to the board anymore. Then, if I can access the web based UI, it would means that the network is available. If not, on next reboot, there would be a rollback so I can connect and send a new update.

So the issue remains. How could the UI could know that there is a “pending commit” or a rollback occurred?

Maybe using the fork I have mentioned?
Do you think that this change could be added to the upstream project?

I didn’t get the exact use case. But, the mentioned fork also performing command line check for commit right (instead of a web UI)?
What @mirzak mentioned also perform the same from the command line. If the return value is 2 then you can confirm that, there is no update in progress or artifact performed commit. Else, it will commit the current artifact.
Here, you can perform mender -commit from the standalone without worrying because, this command will not be having any side affects even if we do it more than once.

Sorry @ajithpv I have missed your comment.

My issue is that I do not want to commit automatically on reboot and I would like to show a “Commit” button on the web UI only if an upgrade is pending and not always.

1 Like