Skip to content

Commit

Permalink
Refactor service restart config and handling (#2)
Browse files Browse the repository at this point in the history
* Add config options for service restart
Add error logging when service restart fails and release GUI

* Remove deprecated `root` flag
Allow some time for the GUI to load before releasing it

* Refactor restart to allow time for the GUI display to start
  • Loading branch information
NeonDaniel authored Dec 28, 2024
1 parent 0379889 commit 8f45221
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions neon_phal_plugin_system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
from os.path import dirname, join
from threading import Event
from time import sleep

from json_database import JsonStorageXDG, JsonDatabaseXDG
from ovos_bus_client.apis.gui import GUIInterface
Expand Down Expand Up @@ -62,6 +63,7 @@ def __init__(self, bus=None, config=None):
self.bus.on("system.mycroft.service.restart.start", self.handle_mycroft_restarting)

self.core_service_name = config.get("core_service") or "neon.service"
self.core_service_is_user = config.get("core_service_is_user", True)
# In Debian, ssh stays active, but sshd is removed when ssh is disabled
self.ssh_service = config.get("ssh_service") or "sshd.service"

Expand Down Expand Up @@ -292,15 +294,14 @@ def handle_mycroft_restarting(self, message: Message):
def handle_mycroft_restart_request(self, message: Message):
service = self.core_service_name
self.bus.emit(message.forward("system.mycroft.service.restart.start", message.data))
# TODO - clean up this mess
# Allow some time for the GUI display to start
sleep(5)
try:
restart_service(service, sudo=False, user=True)
except:
try:
restart_service(service, sudo=True, user=False)
except:
LOG.error("No mycroft or ovos service installed")
return False
restart_service(service, sudo=False,
user=self.core_service_is_user)
except Exception as e:
LOG.error(f"Failed to restart service: {e}")
self.gui.clear() # Release the GUI

def handle_ssh_status(self, message: Message):
"""
Expand Down

0 comments on commit 8f45221

Please sign in to comment.