From 61a0ac3841569ff854d8a61b872d99251104e756 Mon Sep 17 00:00:00 2001
From: Philippe Coval <philippe.coval@huawei.com>
Date: Thu, 21 Oct 2021 13:55:08 +0200
Subject: [PATCH] blueprint-vending-machine-ui-application: Add systemd service

To start app in graphics session after control app.

Control app is started before UI app to avoid inconsistencies

vending-machine-ui-application: Move service in package directory
vending-machine-ui-application: Fix systemd integration

Relate-to: https://git.ostc-eu.org/OSTC/planning/core-os/-/issues/233
Forwarded: https://git.ostc-eu.org/distro/oniro/-/merge_requests/357
Thanks-to: Andrei Gherzan <andrei.gherzan@huawei.com>
Signed-off-by: Philippe Coval <philippe.coval@huawei.com>
---
 .../vending-machine-ui-application.service     | 18 ++++++++++++++++++
 .../vending-machine-ui-application_git.bb      |  9 +++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 meta-oniro-blueprints/recipes-apps/vending-machine/vending-machine-ui-application/vending-machine-ui-application.service

diff --git a/meta-oniro-blueprints/recipes-apps/vending-machine/vending-machine-ui-application/vending-machine-ui-application.service b/meta-oniro-blueprints/recipes-apps/vending-machine/vending-machine-ui-application/vending-machine-ui-application.service
new file mode 100644
index 00000000..2f18a95c
--- /dev/null
+++ b/meta-oniro-blueprints/recipes-apps/vending-machine/vending-machine-ui-application/vending-machine-ui-application.service
@@ -0,0 +1,18 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+[Unit]
+Description=Vending Machine UI Application
+Requires=weston@root.service
+After=weston@root.service
+After=vending-machine-control-application.service
+
+[Service]
+Environment="WAYLAND_DISPLAY=wayland-0"
+Environment="XDG_RUNTIME_DIR=/run/user/0"
+ExecStart=/usr/bin/vending-machine-ui-application
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-oniro-blueprints/recipes-apps/vending-machine/vending-machine-ui-application_git.bb b/meta-oniro-blueprints/recipes-apps/vending-machine/vending-machine-ui-application_git.bb
index 48138f16..2e9524fa 100644
--- a/meta-oniro-blueprints/recipes-apps/vending-machine/vending-machine-ui-application_git.bb
+++ b/meta-oniro-blueprints/recipes-apps/vending-machine/vending-machine-ui-application_git.bb
@@ -10,17 +10,22 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=ba963850f6731c74878fe839d227e675"
 
 SRC_URI = "git://git.ostc-eu.org/distro/components/${BPN};protocol=https;branch=main;"
 SRCREV = "f9b9a709a299782f6f3accc7af8c743057294f95"
+SRC_URI += "file://${BPN}.service"
 S = "${WORKDIR}/git"
 
 DEPENDS= "json-c libwebsockets lv-drivers lv-lib-png lvgl"
 
-inherit pkgconfig features_check
+inherit pkgconfig features_check systemd
 
-REQUIRED_DISTRO_FEATURES = "wayland"
+SYSTEMD_SERVICE_${PN} = "${BPN}.service"
+
+REQUIRED_DISTRO_FEATURES = "systemd wayland"
 
 EXTRA_OEMAKE += "DESTDIR=${D}"
 EXTRA_OEMAKE += "sysroot=${RECIPE_SYSROOT}"
 
 do_install() {
     oe_runmake install
+    install -d "${D}${systemd_system_unitdir}/"
+    install -m 0644 "${WORKDIR}/${BPN}.service" "${D}${systemd_system_unitdir}/"
 }
-- 
GitLab