# Automated/scripted reboot in standalone mode

**URL:** <https://hub.mender.io/t/automated-scripted-reboot-in-standalone-mode/2389>\
**Category:** General Discussions\
**Created:** [September 4, 2020, 3:16pm UTC](https://hub.mender.io/t/automated-scripted-reboot-in-standalone-mode/2389 "2020-09-04T15:16:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hacpa](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hacpa](https://hub.mender.io/u/hacpa)\
**Post date:** [September 4, 2020, 3:16pm UTC](https://hub.mender.io/t/automated-scripted-reboot-in-standalone-mode/2389/1 "2020-09-04T15:16:47Z")

</div>

I want to run a script that installs a Mender Artifact automatically with “mender -install” and **reboots the host if required**. With this script, I will install a mix of rootfs updates and update modules (which do not require a reboot) and I would like the script to reboot the host only when required by the artifact that was installed (specifically, by the particular module that handles this artifact).

It looks like I would need to grep the output of “mender -install” for the word “reboot” (which kinda sucks). Or, fork the mender client and add a command that returns whether a given artifact requires a reboot (based on the module’s response to NeedsArtifactReboot). Is there any other way? fw\_printenv possibly?

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [September 7, 2020, 6:48am UTC](https://hub.mender.io/t/automated-scripted-reboot-in-standalone-mode/2389/2 "2020-09-07T06:48:46Z")

</div>

I believe that is the only way at the moment. It would probably not be hard to add this as a sub command to Mender though, if you would consider contributing. A flag like `mender needs-reboot`, for example?

You could check if the value `upgrade_available=1` exists using `fw_printenv`, but this only works for rootfs-image Artifacts, and only when rebooting into a new image, not when rolling back to an old image.

---

<div class="post-metadata">

**Author:** ![hacpa](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hacpa](https://hub.mender.io/u/hacpa)\
**Post date:** [September 8, 2020, 1:38pm UTC](https://hub.mender.io/t/automated-scripted-reboot-in-standalone-mode/2389/3 "2020-09-08T13:38:15Z")

</div>

Thanks. I do have a “mender query-reboot” command in the works (I’ll rename it to “needs-reboot” as suggested). Currently this command prints “yes” or “no” on the console in response. I will submit this in a PR as is, though I’m unsure whether I should control the return value of the mender client instead of printing “yes” or “no”. I personally think I shouldn’t, as any non-zero return value is an error and may cause some callers to exit.

---

<div class="post-metadata">

**Author:** ![hacpa](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hacpa](https://hub.mender.io/u/hacpa)\
**Post date:** [September 8, 2020, 8:38pm UTC](https://hub.mender.io/t/automated-scripted-reboot-in-standalone-mode/2389/4 "2020-09-08T20:38:33Z")

</div>

And here it is: [https://github.com/mendersoftware/mender/pull/600](https://github.com/mendersoftware/mender/pull/600)

---

<div class="post-metadata">

**Author:** ![hacpa](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hacpa](https://hub.mender.io/u/hacpa)\
**Post date:** [September 9, 2020, 9:11pm UTC](https://hub.mender.io/t/automated-scripted-reboot-in-standalone-mode/2389/5 "2020-09-09T21:11:30Z")

</div>

New PR using alternate method (exit code): [https://github.com/mendersoftware/mender/pull/601](https://github.com/mendersoftware/mender/pull/601)

---

<div class="post-metadata">

**Author:** ![hacpa](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hacpa](https://hub.mender.io/u/hacpa)\
**Post date:** [September 22, 2020, 1:44pm UTC](https://hub.mender.io/t/automated-scripted-reboot-in-standalone-mode/2389/6 "2020-09-22T13:44:53Z")

</div>

In the end, this change (exit code method, with --reboot-exit-code command-line parameter) was merged through PR 603: [https://github.com/mendersoftware/mender/pull/603](https://github.com/mendersoftware/mender/pull/603)
