From 0608422e41db6c1a459f73347afc1822aa0c06b3 Mon Sep 17 00:00:00 2001
From: j1nx
Date: Mon, 24 Jan 2022 20:39:08 +0100
Subject: [PATCH] Add new enclosure-gui systemd service files
---
.../mycroft-enclosure-gui.service | 24 +++++++++++++++
.../mycroft-service/mycroft-service.mk | 4 +++
.../mycroft-service/mycroft-systemd_gui.py | 30 +++++++++++++++++++
.../lib/systemd/system-preset/10-ovos.preset | 1 +
4 files changed, 59 insertions(+)
create mode 100644 buildroot-external/package/mycroft-service/mycroft-enclosure-gui.service
create mode 100755 buildroot-external/package/mycroft-service/mycroft-systemd_gui.py
diff --git a/buildroot-external/package/mycroft-service/mycroft-enclosure-gui.service b/buildroot-external/package/mycroft-service/mycroft-enclosure-gui.service
new file mode 100644
index 00000000..f2f0b6a1
--- /dev/null
+++ b/buildroot-external/package/mycroft-service/mycroft-enclosure-gui.service
@@ -0,0 +1,24 @@
+[Unit]
+Description=Mycroft Enclosure
+PartOf=mycroft.service
+After=mycroft.service
+After=mycroft-messagebus.service
+
+[Service]
+User=mycroft
+Type=notify
+WorkingDirectory=/home/mycroft
+Environment=PYTHONUNBUFFERED=1
+ExecStart=/home/mycroft/.local/share/systemd/mycroft-systemd_gui.py
+StandardOutput=append:/var/log/mycroft/enclosure_gui.log
+StandardError=file:/var/log/mycroft/enclosure_gui.error.log
+TimeoutStartSec=1m
+TimeoutStopSec=1m
+Restart=on-failure
+StartLimitInterval=5min
+StartLimitBurst=4
+#StartLimitAction=reboot-force
+#WatchdogSec=30s
+
+[Install]
+WantedBy=mycroft.service
diff --git a/buildroot-external/package/mycroft-service/mycroft-service.mk b/buildroot-external/package/mycroft-service/mycroft-service.mk
index cc8b8be9..06cfa4a4 100644
--- a/buildroot-external/package/mycroft-service/mycroft-service.mk
+++ b/buildroot-external/package/mycroft-service/mycroft-service.mk
@@ -22,6 +22,8 @@ define MYCROFT_SERVICE_INSTALL_TARGET_CMDS
$(TARGET_DIR)/home/mycroft/.local/share/systemd/mycroft-systemd_skills.py
$(INSTALL) -m 0755 $(@D)/mycroft-systemd_voice.py \
$(TARGET_DIR)/home/mycroft/.local/share/systemd/mycroft-systemd_voice.py
+ $(INSTALL) -m 0755 $(@D)/mycroft-systemd_gui.py \
+ $(TARGET_DIR)/home/mycroft/.local/share/systemd/mycroft-systemd_gui.py
$(INSTALL) -D -m 644 $(@D)/mycroft.service \
$(TARGET_DIR)/usr/lib/systemd/system/mycroft.service
@@ -37,6 +39,8 @@ define MYCROFT_SERVICE_INSTALL_TARGET_CMDS
$(TARGET_DIR)/usr/lib/systemd/system/mycroft-skills.service
$(INSTALL) -D -m 644 $(@D)/mycroft-gui.service \
$(TARGET_DIR)/usr/lib/systemd/system/mycroft-gui.service
+ $(INSTALL) -D -m 644 $(@D)/mycroft-enclosure-gui.service \
+ $(TARGET_DIR)/usr/lib/systemd/system/mycroft-enclosure-gui.service
endef
$(eval $(generic-package))
diff --git a/buildroot-external/package/mycroft-service/mycroft-systemd_gui.py b/buildroot-external/package/mycroft-service/mycroft-systemd_gui.py
new file mode 100755
index 00000000..c4ade3e6
--- /dev/null
+++ b/buildroot-external/package/mycroft-service/mycroft-systemd_gui.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+##########################################################################
+# mycroft-systemd_enclosure.py
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##########################################################################
+import sdnotify
+from mycroft.gui.__main__ import main
+
+n = sdnotify.SystemdNotifier()
+
+def notify_ready():
+ n.notify('READY=1')
+ print('Startup of Mycroft Enclosure service complete')
+
+def notify_stopping():
+ n.notify('STOPPING=1')
+ print('Stopping the Mycroft Enclosure service')
+
+main(ready_hook=notify_ready, stopping_hook=notify_stopping)
diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system-preset/10-ovos.preset b/buildroot-external/rootfs-overlay/usr/lib/systemd/system-preset/10-ovos.preset
index ded7f2ef..0c627526 100644
--- a/buildroot-external/rootfs-overlay/usr/lib/systemd/system-preset/10-ovos.preset
+++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system-preset/10-ovos.preset
@@ -17,6 +17,7 @@ enable mycroft-audio.service
enable mycroft-skills.service
enable mycroft-enclosure.service
enable mycroft-gui.service
+enable mycroft-enclosure-gui.service
enable ovos-splash-quit.service
enable local-backend.service