# Restart device and update existing python file in RPi

**URL:** <https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998>\
**Category:** General Discussions\
**Created:** [June 3, 2020, 7:31am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998 "2020-06-03T07:31:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 3, 2020, 7:31am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/1 "2020-06-03T07:31:25Z")

</div>

Hi,

I would like to know, how to restart a RPi through mender, and also update  
modify a existing python file through mender.?

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [June 3, 2020, 8:27am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/2 "2020-06-03T08:27:47Z")

</div>

Hi 🙂

Mender supports updating single files through:

> [@Single File](https://hub.mender.io/t/single-file/486):
>
> Description The Single File Update Module installs a user defined file into a given destination directory on the device. If the file already exists in the destination folder on the device, the Update Module will take a backup copy of it. This allows the Mender client to rollback if something goes wrong. Example use-cases: Updating a single-binary application Updating a operating system-wide configuration file Specification Module name single-file Supports rollback yes Requir…

Also, if you are running an A/B partition scheme with Mender a rootfs update will reboot the device.

I guess I’m gonna need a little more on the use-case if you this is not what you need though.

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 3, 2020, 8:56am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/3 "2020-06-03T08:56:24Z")

</div>

Hi 🙂 sure Im also reading thru this now, My case is to reboot RPi at any time thru sudo reboot and also to modify a existing py file\ container file.

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [June 3, 2020, 8:58am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/4 "2020-06-03T08:58:48Z")

</div>

Hi 🙂

Here are all public update modules:  
[https://hub.mender.io/c/update-modules/13](https://hub.mender.io/c/update-modules/13)

They should support most of your use-cases, including containers. The reboot can be done with a script I guess?

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 3, 2020, 10:00am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/5 "2020-06-03T10:00:04Z")

</div>

Hi,

I will look into this page, it looks very informative. I was reading the Single file update link u have shared, Does it have a page with proper documentation instead of a forum, finding difficult to understand.

Also, regarding the reboot, Even if I create a python script with os.system(“sudo reboot”), it wont execute unless we run the script rgt? so how does the script work if we deploy thru mender.

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [June 3, 2020, 10:33am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/6 "2020-06-03T10:33:25Z")

</div>

The script is deployed as an update 😉

Look here for the specifics: [https://docs.mender.io/2.3/devices/update-modules](https://docs.mender.io/2.3/devices/update-modules)

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 3, 2020, 10:37am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/7 "2020-06-03T10:37:29Z")

</div>

Yes I understand this part, But again the script .sh file needs to be executed in order to get the sudo command affect knw? , It gets deployed only rgt, Can we also run the script thru mender

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [June 3, 2020, 10:41am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/8 "2020-06-03T10:41:25Z")

</div>

The script update module runs the script.

The single-file update module simply updates a file.

🙂

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 3, 2020, 12:27pm UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/9 "2020-06-03T12:27:17Z")

</div>

Oh, Let me explore and I would like to get back to you Oleorhagen, Give me sometime. It was nice talkng to u.

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 15, 2020, 6:35am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/10 "2020-06-15T06:35:35Z")

</div>

Hi 🙂  
Like I said, I explored single file and script update module.

Both works great. But Im not able to fill in a “sudo reboot” script to the device without getting a 100% successful deployment. Its just “sudo reboot” in the bash script, maybe thats why it isnt deployed succesfully.

So, the script gets deployed to device and it reboots the device but deploys logs stucks at 70 % only in the mender server. Could you help me with a proper reboot script which support mender way.

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [June 15, 2020, 9:12am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/11 "2020-06-15T09:12:11Z")

</div>

I’m not a 100% understanding your question, so I going to answer:  
“I have deployed a bash script which reboots the device, and the deployments gets stuck at 70% for a while in the Mender server, and then fails, what is going on?”

1. Scripts cannot necessarily be used to reboot the device successfully in any state [1][2]. This is because: How can Mender differentiate a reboot in a state-script from a power-loss, or other significant device failures? Thus, the only state-script state which permits this kind of functionality is `RebootEnter`. Here a script which calls `reboot` can be run, and the Mender-client will be happy to reboot into the newly installed root-filesystem. If this is a script update module [3], it actually seems that the description on Mender-hub is wrong. This module does not support rebooting the device. I will fix this up, after clarifying with the Module author.

Thus, I guess what I am trying to say, is that rebooting the device at any time is not supported as it is now.

Solutions I can think of at the top of my head are:

- Write a custom update-module which runs the script in the `ArtifactReboot` state. This will allow the script to reboot the device successfully, unlike the current ‘official’ script update-module.
- Use some other tool to reboot the device (ssh? maybe), and keep it out of the Mender update loop.

Which solution is best is a little hard to say, as it depends on your specific use-case.

References:  
[1]: [https://docs.mender.io/2.3/artifacts/state-scripts#power-loss](https://docs.mender.io/2.3/artifacts/state-scripts#power-loss)  
[2]: [https://docs.mender.io/2.3/devices/update-modules#power-loss](https://docs.mender.io/2.3/devices/update-modules#power-loss)  
[3]: [Script](https://hub.mender.io/t/script/328)

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 15, 2020, 9:55am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/12 "2020-06-15T09:55:12Z")

</div>

Sure @oleorhagen, I got ur point, Thank you so much for this amazing response. Ill go thru the ArtifactReboot state, Let me explore more on this.

Im actially facing a huge probs now, I have raised another issue:

> [@Mender demo server sudden slow and stuck](https://hub.mender.io/t/mender-demo-server-sudden-slow-and-stuck/2043):
>
> Hi, I have been using Mender for couple of weeks now, suddenly Mender server GUI is stuck and slow, its staggering. No errors in the logs. Could you let me know how to resolve this. Im running the server in a 2 cpus, 8GB RAM. So server requirements also good rgt? or is it less?

No one is actually responding, so I refered here, sorry if its wrong way to do it. But its critical, Im not able to see anything wrong with my server, Its 16GB ram and 4 cpus, But Demo server GUIs doesn’t respond smoothly, It hangs, staggers whenever we click at anything on the gui.

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 16, 2020, 9:51am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/13 "2020-06-16T09:51:08Z")

</div>

Hi @oleorhagen,

Im facing one more issue with my deployment, Once a deployment failes or aborted, the release\artifact is tagged with “Inconsistent” name, and after that the device is never synced in real time update, and because of this I cant deploy any further releases unless I restart the device manually, which is a very unfavourable situation for Mender isn’t it.

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [June 16, 2020, 10:48am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/14 "2020-06-16T10:48:29Z")

</div>

In general I would recommend using another tool for rebooting your entire fleet. It could be done with an update module like:

```bash
#! /bin/bash

set -e

STATE="$1"
FILES="$2"

case "$STATE" in
    NeedsArtifactReboot)
        echo "Automatic"
        ;;
esac
exit 0

```

However, this is slightly cumbersome, as it would change the artifact name installed. There is simply no way around it.

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 16, 2020, 10:59am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/15 "2020-06-16T10:59:50Z")

</div>

Sure @oleorhagen, I understand this reboot is not happening for now, Now Ill give a try with the state script u have mentioned… Changing the artifact name isn’t a nice way actually. But Ill try this once.

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 16, 2020, 11:00am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/16 "2020-06-16T11:00:15Z")

</div>

@oleorhagen Any idea on this ?

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [June 16, 2020, 11:04am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/17 "2020-06-16T11:04:05Z")

</div>

@nishad1092 this is not a state-script.  
It is an [update-module](https://docs.mender.io/2.3/devices/update-modules)

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 16, 2020, 11:09am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/18 "2020-06-16T11:09:04Z")

</div>

Sure, I’m looking into now, Looks different way to execute\deploy this to a device.

---

<div class="post-metadata">

**Author:** ![oleorhagen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/oleorhagen/32/297_2.png) [@oleorhagen](https://hub.mender.io/u/oleorhagen)\
**Post date:** [June 16, 2020, 11:12am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/19 "2020-06-16T11:12:33Z")

</div>

The inconsistent state is related to a failed update-module update.

I’m going to need a little more information on what exactly you are trying to do?

Is this from the script update-module?

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [June 16, 2020, 11:19am UTC](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998/20 "2020-06-16T11:19:26Z")

</div>

Yes, It is from the script module, Few times it worked fine, But twice it failed and yes, It went to “Inconsistent” mode, But after that, the device stopped taking real time update.

[Next page](https://hub.mender.io/t/restart-device-and-update-existing-python-file-in-rpi/1998.md?page=2)
