Skip to content

Restart on Manual Build #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/raspberry_pi_os_build_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,19 @@ WorkingDirectory=/home/pi/seedsigner/src/
ExecStart=/usr/bin/python3 main.py
StandardOutput=null
ErrorOutput=null
Restart=always
Restart=no

[Install]
WantedBy=multi-user.target
```

_Note: For local dev you'll want to edit the `Restart=always` line to `Restart=no`. This way when your dev code crashes it won't keep trying to restart itself. Note that the UI "Reset" will no longer work when auto-restarts are disabled._
_Note: The line `Restart=no` ensures that when your dev code crashes it won't keep trying to restart itself._

_Note: Debugging output is completely wiped via routing the stdout and stderr to `/dev/null`. When working in local dev, you'll `kill` the `systemd` SeedSigner service and just directly run the code on demand so you can see all the debugging output live._

Use `CTRL-X` and `y` to exit and save changes.

Configure the service to start running (this will restart the seedsigner code automatically at startup and if it crashes):
Configure the service to start running (this will restart the seedsigner code automatically at startup):
```bash
sudo systemctl enable seedsigner.service
```
Expand Down
29 changes: 20 additions & 9 deletions src/seedsigner/views/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,30 +242,41 @@ def run(self):
return Destination(PowerOffView)



@dataclass
class RestartView(View):
is_screenshot_renderer: bool = False

def run(self):
from seedsigner.gui.screens.screen import ResetScreen
thread = RestartView.DoResetThread()
thread = RestartView.DoResetThread(is_screenshot_renderer=self.is_screenshot_renderer)
thread.start()
self.run_screen(ResetScreen)


class DoResetThread(BaseThread):
def __init__(self, is_screenshot_renderer: bool = False):
self.is_screenshot_renderer = is_screenshot_renderer
super().__init__()


def run(self):
import os
import sys
import time
from subprocess import call

# Give the screen just enough time to display the reset message before
# exiting.
time.sleep(0.25)
if self.is_screenshot_renderer:
# For the screenshot generator, we don't actually want to restart
return

# Flush any buffered data.
sys.stdout.flush()
sys.stderr.flush()

# Kill the SeedSigner process; Running the process again.
# `.*` is a wildcard to detect either `python`` or `python3`.
if Settings.HOSTNAME == Settings.SEEDSIGNER_OS:
call("kill $(pidof python*) & python /opt/src/main.py", shell=True)
else:
call("kill $(ps aux | grep '[p]ython.*main.py' | awk '{print $2}')", shell=True)
# Replace the current process with a new one.
os.execv(sys.executable, [sys.executable] + sys.argv)



Expand Down
2 changes: 1 addition & 1 deletion tests/screenshot_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def PSBTOpReturnView_raw_hex_data_cb_before():
ScreenshotConfig(MainMenuView, screenshot_name='MainMenuView_DireWarningToast', toast_thread=DireWarningToast("This is a dire warning toast!", activation_delay=0, duration=0)),
ScreenshotConfig(MainMenuView, screenshot_name='MainMenuView_ErrorToast', toast_thread=ErrorToast("This is an error toast!", activation_delay=0, duration=0)),
ScreenshotConfig(PowerOptionsView),
ScreenshotConfig(RestartView),
ScreenshotConfig(RestartView, dict(is_screenshot_renderer=True)),
ScreenshotConfig(PowerOffView),
],
"Seed Views": [
Expand Down