From be83edcf8e6f5a51793c5c57dbb1402e97703e3f Mon Sep 17 00:00:00 2001
From: Esben Haabendal <esben@geanix.com>
Date: Thu, 9 Mar 2023 19:06:56 +0100
Subject: [PATCH] openharmony-standard: Run distributedsched as systemd service

Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 .../files/distributedsched.service            | 20 +++++++++++++++----
 .../openharmony/files/openharmony-preinit     | 11 ----------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/recipes-openharmony/openharmony/files/distributedsched.service b/recipes-openharmony/openharmony/files/distributedsched.service
index 578c42b8..e12863c3 100644
--- a/recipes-openharmony/openharmony/files/distributedsched.service
+++ b/recipes-openharmony/openharmony/files/distributedsched.service
@@ -1,10 +1,22 @@
 [Unit]
-Description=OpenHarmony Distributed Schedule service
+Description=OpenHarmony Distributed Schedule service (SA: 1401)
+Requires=samgr.service
+After=samgr.service
+#Wants=param.service
+#After=param.service
+# Logging to hilogd, but seems to work without it
+Wants=hilogd.service
+After=hilogd.service
+# Requires SA: 4700
+Wants=dsoftbus.service
 
 [Service]
-Type=oneshot
-ExecStart=/bin/echo "OpenHarmony Distributed Schedule Service"
-RemainAfterExit=yes
+Type=notify
+User=system
+Group=system
+SupplementaryGroups=shell
+LimitNICE=40
+ExecStart=/usr/bin/sa_main /system/profile/distributedsched.xml
 
 [Install]
 WantedBy=multi-user.target
diff --git a/recipes-openharmony/openharmony/files/openharmony-preinit b/recipes-openharmony/openharmony/files/openharmony-preinit
index 0276838c..c6ec2f1c 100644
--- a/recipes-openharmony/openharmony/files/openharmony-preinit
+++ b/recipes-openharmony/openharmony/files/openharmony-preinit
@@ -136,17 +136,6 @@ fi
 #sa_main /system/profile/dps_service.xml & # SA: 1401 180 3502
 #sleep "$STARTUP_CMD_SLEEP"
 
-# trigger: post-fs-data
-# "name" : "distributedsched",
-# "path" : ["/system/bin/sa_main", "/system/profile/distributedsched.xml"],
-# "uid" : "system",
-# "gid" : ["system", "shell"]
-if systemctl -q is-enabled distributedsched.service; then
-	echo >/dev/console "Starting OpenHarmony distributedsched service"
-	su system -c '/system/bin/sa_main /system/profile/distributedsched.xml &' # SA: 1401
-	sleep "$STARTUP_CMD_SLEEP"
-fi
-
 # trigger: boot
 # "name" : "distributeddata",
 # "path" : ["/system/bin/sa_main","/system/profile/distributeddata.xml"],
-- 
GitLab