# Best/Safest way to determine whether an update has taken place after a reboot?

**URL:** <https://hub.mender.io/t/best-safest-way-to-determine-whether-an-update-has-taken-place-after-a-reboot/799>\
**Category:** General Discussions\
**Created:** [July 8, 2019, 12:40pm UTC](https://hub.mender.io/t/best-safest-way-to-determine-whether-an-update-has-taken-place-after-a-reboot/799 "2019-07-08T12:40:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![platisd](https://avatars.discourse-cdn.com/v4/letter/p/7ba0ec/32.png) [@platisd](https://hub.mender.io/u/platisd)\
**Post date:** [July 8, 2019, 12:40pm UTC](https://hub.mender.io/t/best-safest-way-to-determine-whether-an-update-has-taken-place-after-a-reboot/799/1 "2019-07-08T12:40:36Z")

</div>

Hi,  
After booting up, we are trying to determine whether this is the “first boot” after a Mender update and therefore we should commit the update. (note: we’re running things in standalone mode)

Is there a recommended way to achieve this?

We have found two ways, both of which seem to be working reliably:

1. Checking the exit code of `mender -commit`
2. Parsing the output of `fw_printenv upgrade_available`

Is there a good reason on why we should go with one over the other or is it a matter of personal preference?

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [July 8, 2019, 12:50pm UTC](https://hub.mender.io/t/best-safest-way-to-determine-whether-an-update-has-taken-place-after-a-reboot/799/2 "2019-07-08T12:50:03Z")

</div>

Hi @platisd,

> We have found two ways, both of which seem to be working reliably:
> 
> 1. Checking the exit code of `mender -commit`
> 2. Parsing the output of `fw_printenv upgrade_available`  
> Is there a good reason on why we should go with one over the other or is it a matter of personal preference?

I think both methods will work. `mender -commit` actually checks that same flag.

But do you do anything else with this “upgrade in progress” information? Because if it is only to determinate if to commit or not, you can just run `mender -commit` unconditionally on each boot. The Mender client will know if there is something to commit, if not it will not do anything beside change the return code as you have noticed.

---

<div class="post-metadata">

**Author:** ![platisd](https://avatars.discourse-cdn.com/v4/letter/p/7ba0ec/32.png) [@platisd](https://hub.mender.io/u/platisd)\
**Post date:** [July 8, 2019, 12:53pm UTC](https://hub.mender.io/t/best-safest-way-to-determine-whether-an-update-has-taken-place-after-a-reboot/799/3 "2019-07-08T12:53:59Z")

</div>

Thanks (again) for the immediate response.  
We have to update other parts of our system (i.e. a microcontroller) so we do need to know whether this is the “first boot”.

Well, since there’s no other difference, I guess running `mender -commit` and checking its return code is better since it is one line of code less. 🙂

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [July 8, 2019, 12:54pm UTC](https://hub.mender.io/t/best-safest-way-to-determine-whether-an-update-has-taken-place-after-a-reboot/799/4 "2019-07-08T12:54:51Z")

</div>

Less is always better 🙂 and np
