From 196affff22292727f5c8730a0d602fbe02a49786 Mon Sep 17 00:00:00 2001 From: j1nx Date: Mon, 5 Apr 2021 20:15:47 +0200 Subject: [PATCH] Upgrade mycroft-service to use systemd notify through previous scripts --- .../mycroft-service/mycroft-audio.service | 11 ++++++- .../mycroft-service/mycroft-enclosure.service | 10 ++++++- .../mycroft-messagebus.service | 10 ++++++- .../mycroft-service/mycroft-service.mk | 12 ++++++++ .../mycroft-service/mycroft-skills.service | 12 +++++++- .../mycroft-service/mycroft-systemd_audio.py | 30 +++++++++++++++++++ .../mycroft-systemd_enclosure.py | 30 +++++++++++++++++++ .../mycroft-systemd_messagebus.py | 30 +++++++++++++++++++ .../mycroft-service/mycroft-systemd_skills.py | 30 +++++++++++++++++++ .../mycroft-service/mycroft-systemd_voice.py | 30 +++++++++++++++++++ 10 files changed, 201 insertions(+), 4 deletions(-) create mode 100755 buildroot-external/package/mycroft-service/mycroft-systemd_audio.py create mode 100755 buildroot-external/package/mycroft-service/mycroft-systemd_enclosure.py create mode 100755 buildroot-external/package/mycroft-service/mycroft-systemd_messagebus.py create mode 100755 buildroot-external/package/mycroft-service/mycroft-systemd_skills.py create mode 100755 buildroot-external/package/mycroft-service/mycroft-systemd_voice.py diff --git a/buildroot-external/package/mycroft-service/mycroft-audio.service b/buildroot-external/package/mycroft-service/mycroft-audio.service index aadac63b..f57981c1 100644 --- a/buildroot-external/package/mycroft-service/mycroft-audio.service +++ b/buildroot-external/package/mycroft-service/mycroft-audio.service @@ -2,14 +2,23 @@ Description=Mycroft Audio PartOf=mycroft.service After=mycroft.service +After=mycroft-messagebus.service [Service] User=mycroft +Type=notify WorkingDirectory=/home/mycroft -ExecStart=mycroft-audio +Environment=PYTHONUNBUFFERED=1 +ExecStart=/home/mycroft/.local/share/systemd/mycroft-systemd_audio.py StandardOutput=file:/var/log/mycroft/audio.log StandardError=file:/var/log/mycroft/audio.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-enclosure.service b/buildroot-external/package/mycroft-service/mycroft-enclosure.service index 8acac55a..4502f4d3 100644 --- a/buildroot-external/package/mycroft-service/mycroft-enclosure.service +++ b/buildroot-external/package/mycroft-service/mycroft-enclosure.service @@ -6,11 +6,19 @@ After=mycroft-messagebus.service [Service] User=mycroft +Type=notify WorkingDirectory=/home/mycroft -ExecStart=mycroft-enclosure-client +Environment=PYTHONUNBUFFERED=1 +ExecStart=/home/mycroft/.local/share/systemd/mycroft-systemd_enclosure.py StandardOutput=file:/var/log/mycroft/enclosure.log StandardError=file:/var/log/mycroft/enclosure.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-messagebus.service b/buildroot-external/package/mycroft-service/mycroft-messagebus.service index 520f7303..824a9c70 100644 --- a/buildroot-external/package/mycroft-service/mycroft-messagebus.service +++ b/buildroot-external/package/mycroft-service/mycroft-messagebus.service @@ -5,11 +5,19 @@ After=mycroft.service [Service] User=mycroft +Type=notify WorkingDirectory=/home/mycroft -ExecStart=mycroft-messagebus +Environment=PYTHONUNBUFFERED=1 +ExecStart=/home/mycroft/.local/share/systemd/mycroft-systemd_messagebus.py StandardOutput=file:/var/log/mycroft/bus.log StandardError=file:/var/log/mycroft/bus.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 5f520112..cc8b8be9 100644 --- a/buildroot-external/package/mycroft-service/mycroft-service.mk +++ b/buildroot-external/package/mycroft-service/mycroft-service.mk @@ -11,6 +11,18 @@ MYCROFT_SERVICE_LICENSE = Apache License 2.0 MYCROFT_SERVICE_LICENSE_FILES = LICENSE define MYCROFT_SERVICE_INSTALL_TARGET_CMDS + mkdir -p $(TARGET_DIR)/home/mycroft/.local/share/systemd + $(INSTALL) -m 0755 $(@D)/mycroft-systemd_audio.py \ + $(TARGET_DIR)/home/mycroft/.local/share/systemd/mycroft-systemd_audio.py + $(INSTALL) -m 0755 $(@D)/mycroft-systemd_enclosure.py \ + $(TARGET_DIR)/home/mycroft/.local/share/systemd/mycroft-systemd_enclosure.py + $(INSTALL) -m 0755 $(@D)/mycroft-systemd_messagebus.py \ + $(TARGET_DIR)/home/mycroft/.local/share/systemd/mycroft-systemd_messagebus.py + $(INSTALL) -m 0755 $(@D)/mycroft-systemd_skills.py \ + $(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) -D -m 644 $(@D)/mycroft.service \ $(TARGET_DIR)/usr/lib/systemd/system/mycroft.service $(INSTALL) -D -m 644 $(@D)/mycroft-messagebus.service \ diff --git a/buildroot-external/package/mycroft-service/mycroft-skills.service b/buildroot-external/package/mycroft-service/mycroft-skills.service index b0c4c80d..4140ce65 100644 --- a/buildroot-external/package/mycroft-service/mycroft-skills.service +++ b/buildroot-external/package/mycroft-service/mycroft-skills.service @@ -2,14 +2,24 @@ Description=Mycroft Skills PartOf=mycroft.service After=mycroft.service +After=mycroft-messagebus.service +After=mycroft-audio.service [Service] User=mycroft +Type=notify WorkingDirectory=/home/mycroft -ExecStart=mycroft-skills +Environment=PYTHONUNBUFFERED=1 +ExecStart=/home/mycroft/.local/share/systemd/mycroft-systemd_skills.py StandardOutput=file:/var/log/mycroft/skills.log StandardError=file:/var/log/mycroft/skills.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-systemd_audio.py b/buildroot-external/package/mycroft-service/mycroft-systemd_audio.py new file mode 100755 index 00000000..b4d6af64 --- /dev/null +++ b/buildroot-external/package/mycroft-service/mycroft-systemd_audio.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +########################################################################## +# mycroft-systemd_audio.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.audio.__main__ import main + +n = sdnotify.SystemdNotifier() + +def notify_ready(): + n.notify('READY=1') + print('Startup of Mycroft Audio service complete') + +def notify_stopping(): + n.notify('STOPPING=1') + print('Stopping the Mycroft Audio service') + +main(ready_hook=notify_ready, stopping_hook=notify_stopping) diff --git a/buildroot-external/package/mycroft-service/mycroft-systemd_enclosure.py b/buildroot-external/package/mycroft-service/mycroft-systemd_enclosure.py new file mode 100755 index 00000000..7c226bba --- /dev/null +++ b/buildroot-external/package/mycroft-service/mycroft-systemd_enclosure.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.client.enclosure.__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/package/mycroft-service/mycroft-systemd_messagebus.py b/buildroot-external/package/mycroft-service/mycroft-systemd_messagebus.py new file mode 100755 index 00000000..49278b27 --- /dev/null +++ b/buildroot-external/package/mycroft-service/mycroft-systemd_messagebus.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +########################################################################## +# mycroft-systemd_messagebus.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.messagebus.service.__main__ import main + +n = sdnotify.SystemdNotifier() + +def notify_ready(): + n.notify('READY=1') + print('Startup of Mycroft Messagebus service complete') + +def notify_stopping(): + n.notify('STOPPING=1') + print('Stopping the Mycroft Messagebus service') + +main(ready_hook=notify_ready, stopping_hook=notify_stopping) diff --git a/buildroot-external/package/mycroft-service/mycroft-systemd_skills.py b/buildroot-external/package/mycroft-service/mycroft-systemd_skills.py new file mode 100755 index 00000000..02aab4e4 --- /dev/null +++ b/buildroot-external/package/mycroft-service/mycroft-systemd_skills.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +########################################################################## +# mycroft-systemd_skills.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.skills.__main__ import main + +n = sdnotify.SystemdNotifier() + +def notify_ready(): + n.notify('READY=1') + print('Startup of Mycroft Skills service complete') + +def notify_stopping(): + n.notify('STOPPING=1') + print('Stopping the Mycroft Skills service') + +main(ready_hook=notify_ready, stopping_hook=notify_stopping) diff --git a/buildroot-external/package/mycroft-service/mycroft-systemd_voice.py b/buildroot-external/package/mycroft-service/mycroft-systemd_voice.py new file mode 100755 index 00000000..fd0b36ee --- /dev/null +++ b/buildroot-external/package/mycroft-service/mycroft-systemd_voice.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +########################################################################## +# mycroft-systemd_voice.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.client.speech.__main__ import main + +n = sdnotify.SystemdNotifier() + +def notify_ready(): + n.notify('READY=1') + print('Startup of Mycroft Voice service complete') + +def notify_stopping(): + n.notify('STOPPING=1') + print('Stopping the Mycroft Voice service') + +main(ready_hook=notify_ready, stopping_hook=notify_stopping)