diff --git a/src/openflexure_microscope_server/things/system.py b/src/openflexure_microscope_server/things/system.py index bd3f23f9..831cad8d 100644 --- a/src/openflexure_microscope_server/things/system.py +++ b/src/openflexure_microscope_server/things/system.py @@ -10,6 +10,8 @@ from typing import Optional from uuid import UUID, uuid4 import subprocess import os +from signal import SIGTERM +import time from pydantic import BaseModel @@ -80,6 +82,16 @@ class OpenFlexureSystem(lt.Thing): @lt.thing_action def shutdown(self) -> CommandOutput: """Attempt to shutdown the device.""" + if not self.is_raspberrypi: + os.kill(os.getpid(), SIGTERM) + time.sleep(0.5) + # If this line is reached then the server did not shut down! + return CommandOutput( + output="", + error="Shutdown command sent to server process, but the server has not shutdown.", + ) + + # On a Raspberry Pi p = subprocess.Popen( ["sudo", "shutdown", "-h", "now"], stderr=subprocess.PIPE, @@ -92,6 +104,12 @@ class OpenFlexureSystem(lt.Thing): @lt.thing_action def reboot(self) -> CommandOutput: """Attempt to reboot the device.""" + if not self.is_raspberrypi: + return CommandOutput( + output="", + error="Restart is only available on Raspberry Pi.", + ) + p = subprocess.Popen( ["sudo", "shutdown", "-r", "now"], stderr=subprocess.PIPE, diff --git a/webapp/src/components/tabContentComponents/powerContent.vue b/webapp/src/components/tabContentComponents/powerContent.vue index b442a796..a865e74f 100644 --- a/webapp/src/components/tabContentComponents/powerContent.vue +++ b/webapp/src/components/tabContentComponents/powerContent.vue @@ -1,23 +1,23 @@