Automated/scripted reboot in standalone mode

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?

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.

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.

And here it is:

New PR using alternate method (exit code):

In the end, this change (exit code method, with --reboot-exit-code command-line parameter) was merged through PR 603: