fusion44 / blitz_api

A management backend for the RaspiBlitz project written in Python / FastAPI
MIT License
19 stars 18 forks source link

implement reboot & shutdown #70

Closed cstenglein closed 2 years ago

cstenglein commented 2 years ago

This implements reboot & shutdown and closes #68 & closes #69.

cstenglein commented 2 years ago

@fusion44 could you take a look please? :)

fusion44 commented 2 years ago

@rootzoll I ran the PR and tried to reboot my my Blitz via the API. The reboot process is started but the Blitz never actually reboots. Here's the log:

Mar 21 19:46:07 sudo[443339]: ['bash /home/admin/config.scripts/blitz.shutdown.sh reboot' exited with 0]
Mar 21 19:46:07 sudo[443339]: [stdout]
Mar 21 19:46:07 sudo[443339]: Green activity light stays dark and LCD turns white when shutdown complete.
Mar 21 19:46:07 sudo[443339]: It will then reboot again automatically.
Mar 21 19:46:07 sudo[443339]: -----------------------------------------------
Mar 21 19:46:07 sudo[443339]: stop electrs - please wait ..
Mar 21 19:46:07 sudo[443339]: stop lightning - please wait ..
Mar 21 19:46:07 sudo[443339]: stop bitcoind (1) - please wait ..
Mar 21 19:46:07 sudo[443339]: stop bitcoind (2) - please wait ..
Mar 21 19:46:07 sudo[443339]: starting shutdown ...
Mar 21 19:46:07 sudo[443339]: WARN: Missing $DBUS_SESSION_BUS_ADDRESS ..
Mar 21 19:46:07 sudo[443339]: RUNNING FALLBACK REBOOT ..
Mar 21 19:46:07 sudo[443339]: [stderr]
Mar 21 19:46:07 sudo[443339]: sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
Mar 21 19:46:07 sudo[443339]: sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
Mar 21 19:46:07 sudo[443339]: sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
Mar 21 19:46:07 sudo[443339]: sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
Mar 21 19:46:07 sudo[443339]: INFO:     127.0.0.1:56804 - "POST /api/latest/system/reboot HTTP/1.0" 200 OK

Does the output tell you anything? I guess this is a rights problem. It doesn't matter whether the script is invoked with sudo or not.

edit I've had one SSH connection going from my dev computer to the Blitz while trying to reboot it via API. Once it didn't work I've started the SSH menu and the 10 s countdown was showing up. After the countdown the menu disappeared but still no shutdown. /edit

fusion44 commented 2 years ago

@cstenglein Other than my comments above, great work!

One additional consideration should be to send a SSE message that a shutdown / reboot is imminent. Other clients that are connected are left wondering why the server isn't reachable anymore.

edit I've been thinking about this some more. The signal should actually come from the blitz.shutdown.sh script. Clients must be notified no matter whether the shutdown was initiated via API or SSH. /edit

lgtm-com[bot] commented 2 years ago

This pull request introduces 1 alert when merging c5aaad738621000091d50ce646d0632d34aa8fef into aa4435656b46c59716afdee4dfb9574277f1209d - view on LGTM.com

new alerts: