summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2024-11-01 07:32:35 +0000
committerCoprDistGit <infra@openeuler.org>2024-11-01 07:32:35 +0000
commit4b26a0134662460b28d5e30b16e395fec7341e32 (patch)
tree1d737c77d28574f8c30a2f48782692517b2ee9cb
parentd0935aef77f2e579592f4755a8f8b5a6e9656ec7 (diff)
automatic import of systemabilitymgr_safwkopeneuler24.03_LTS
-rw-r--r--.gitignore1
-rw-r--r--0000-remove-dependency-on-hitrace-safwk.patch71
-rw-r--r--0001-feat-for-embedded-fix-config_safwk-include_dirs.patch33
-rw-r--r--innerkits.safwk.BUILD.gn41
-rw-r--r--safwk.bundle.json58
-rw-r--r--safwk.spec125
-rw-r--r--services.safwk.BUILD.gn23
-rw-r--r--sources1
-rwxr-xr-xstart_services.sh178
-rwxr-xr-xstop_services.sh64
10 files changed, 595 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..0ee9ba8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/systemabilitymgr_safwk-OpenHarmony-v3.2-Release.tar.gz
diff --git a/0000-remove-dependency-on-hitrace-safwk.patch b/0000-remove-dependency-on-hitrace-safwk.patch
new file mode 100644
index 0000000..e9d2119
--- /dev/null
+++ b/0000-remove-dependency-on-hitrace-safwk.patch
@@ -0,0 +1,71 @@
+From e0aace24cbc8d0943bb79589d1a236fb8ff5afdb Mon Sep 17 00:00:00 2001
+From: heppen <hepeng68@huawei.com>
+Date: Tue, 20 Jun 2023 17:23:24 +0800
+Subject: [PATCH] remove dependency on hitrace
+
+---
+ interfaces/innerkits/safwk/BUILD.gn | 2 +-
+ services/safwk/src/local_ability_manager.cpp | 4 ++--
+ services/safwk/src/system_ability.cpp | 4 ++--
+ 3 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/interfaces/innerkits/safwk/BUILD.gn b/interfaces/innerkits/safwk/BUILD.gn
+index 5509789..3dd18cb 100644
+--- a/interfaces/innerkits/safwk/BUILD.gn
++++ b/interfaces/innerkits/safwk/BUILD.gn
+@@ -51,7 +51,7 @@ ohos_shared_library("system_ability_fwk") {
+ if (is_standard_system) {
+ external_deps = [
+ "c_utils:utils",
+- "hitrace_native:hitrace_meter",
++ # "hitrace_native:hitrace_meter",
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "samgr:samgr_common",
+diff --git a/services/safwk/src/local_ability_manager.cpp b/services/safwk/src/local_ability_manager.cpp
+index 11f7a06..0af6af9 100644
+--- a/services/safwk/src/local_ability_manager.cpp
++++ b/services/safwk/src/local_ability_manager.cpp
+@@ -22,7 +22,7 @@
+
+ #include "datetime_ex.h"
+ #include "errors.h"
+-#include "hitrace_meter.h"
++// #include "hitrace_meter.h"
+ #include "ipc_skeleton.h"
+ #include "iservice_registry.h"
+ #include "safwk_log.h"
+@@ -88,7 +88,7 @@ void LocalAbilityManager::DoStartSAProcess(const std::string& profilePath, int32
+ }
+ {
+ std::string traceTag = GetTraceTag(realProfilePath);
+- HITRACE_METER_NAME(HITRACE_TAG_SAMGR, traceTag);
++ // HITRACE_METER_NAME(HITRACE_TAG_SAMGR, traceTag);
+ bool ret = InitSystemAbilityProfiles(realProfilePath, saId);
+ if (!ret) {
+ HILOGE(TAG, "InitSystemAbilityProfiles no right profile, will exit");
+diff --git a/services/safwk/src/system_ability.cpp b/services/safwk/src/system_ability.cpp
+index 84911e0..e618560 100644
+--- a/services/safwk/src/system_ability.cpp
++++ b/services/safwk/src/system_ability.cpp
+@@ -19,7 +19,7 @@
+
+ #include "datetime_ex.h"
+ #include "errors.h"
+-#include "hitrace_meter.h"
++// #include "hitrace_meter.h"
+ #include "if_system_ability_manager.h"
+ #include "iservice_registry.h"
+ #include "local_ability_manager.h"
+@@ -114,7 +114,7 @@ void SystemAbility::Start()
+ }
+ HILOGD(TAG, "[PerformanceTest] SAFWK OnStart systemAbilityId:%{public}d", saId_);
+ int64_t begin = GetTickCount();
+- HITRACE_METER_NAME(HITRACE_TAG_SAMGR, ToString(saId_) + "_OnStart");
++ // HITRACE_METER_NAME(HITRACE_TAG_SAMGR, ToString(saId_) + "_OnStart");
+ OnStart();
+ isRunning_ = true;
+ HILOGI(TAG, "[PerformanceTest] SAFWK OnStart systemAbilityId:%{public}d finished, spend:%{public}" PRId64 " ms",
+--
+2.33.0
+
diff --git a/0001-feat-for-embedded-fix-config_safwk-include_dirs.patch b/0001-feat-for-embedded-fix-config_safwk-include_dirs.patch
new file mode 100644
index 0000000..39e41d6
--- /dev/null
+++ b/0001-feat-for-embedded-fix-config_safwk-include_dirs.patch
@@ -0,0 +1,33 @@
+From 17be025e940fea23e6fdb7019f08fe9b3d656b91 Mon Sep 17 00:00:00 2001
+From: s_c_c <shichuchao@huawei.com>
+Date: Mon, 1 Apr 2024 20:14:11 +0800
+Subject: [PATCH] feat for embedded fix config_safwk include_dirs
+
+---
+ services/safwk/BUILD.gn | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/services/safwk/BUILD.gn b/services/safwk/BUILD.gn
+index e25ecb9..09a6acc 100644
+--- a/services/safwk/BUILD.gn
++++ b/services/safwk/BUILD.gn
+@@ -12,6 +12,7 @@
+ # limitations under the License.
+
+ import("//build/ohos.gni")
++import("//build/config/sysroot.gni")
+
+ ################################################################################
+ config("config_safwk") {
+@@ -20,7 +21,7 @@ config("config_safwk") {
+ "//foundation/systemabilitymgr/safwk/services/safwk/include",
+ "//foundation/systemabilitymgr/samgr/services/lsamgr/include",
+ "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
+- "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
++ "${sysroot}/usr/include/ipc",
+ ]
+ }
+
+--
+2.20.1 (Apple Git-117)
+
diff --git a/innerkits.safwk.BUILD.gn b/innerkits.safwk.BUILD.gn
new file mode 100644
index 0000000..0cbc51c
--- /dev/null
+++ b/innerkits.safwk.BUILD.gn
@@ -0,0 +1,41 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# 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("//build/ohos.gni")
+import("//build/ohos_var.gni")
+import("//build/config/sysroot.gni")
+
+# 建立所需头文件链接
+exec_script("//build/openeuler/script/link.py", [ "--src_target", "${sysroot}/usr/include/safwk/system_ability.h", "--dest_target",
+ rebase_path("//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk/system_ability.h") ], "string")
+
+exec_script("//build/openeuler/script/link.py", [ "--src_target", "${sysroot}/usr/include/safwk", "--dest_target",
+ rebase_path("//foundation/systemabilitymgr/safwk/services/safwk/include") ], "string")
+
+config("system_ability_config") {
+ visibility = [ ":*" ]
+ include_dirs = [
+ "${sysroot}/usr/include/safwk",
+ ]
+}
+
+ohos_prebuilt_shared_library("system_ability_fwk") {
+ source = "${sysroot}/usr/lib64/libsystem_ability_fwk.z.so"
+
+ public_configs = [ ":system_ability_config" ]
+
+ install_images = [ system_base_dir ]
+ relative_install_dir = "platformsdk"
+ part_name = "safwk"
+ subsystem_name = "systemabilitymgr"
+} \ No newline at end of file
diff --git a/safwk.bundle.json b/safwk.bundle.json
new file mode 100644
index 0000000..1964532
--- /dev/null
+++ b/safwk.bundle.json
@@ -0,0 +1,58 @@
+{
+ "name": "@ohos/systemabilitymgr_safwk",
+ "description": "system ability framework",
+ "homePage": "https://gitee.com/openharmony",
+ "version": "3.1",
+ "license": "Apache License 2.0",
+ "repository": "https://gitee.com/openharmony/systemabilitymgr_safwk",
+ "publishAs": "code-segment",
+ "segment": {
+ "destPath": "foundation/systemabilitymgr/safwk"
+ },
+ "dirs": {},
+ "scripts": {},
+ "component": {
+ "name": "safwk",
+ "subsystem": "systemabilitymgr",
+ "features": [ "safwk_feature_coverage = false" ],
+ "adapted_system_type": [
+ "standard"
+ ],
+ "rom": "200KB",
+ "ram": "7130KB",
+ "deps": {
+ "components": [
+ "hitrace_native",
+ "hiviewdfx_hilog_native",
+ "ipc",
+ "samgr",
+ "c_utils"
+ ],
+ "third_party": [ "libxml2" ]
+ },
+ "build": {
+ "group_type": {
+ "base_group": [
+ "//foundation/systemabilitymgr/safwk/services/safwk:sa_main",
+ "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk"
+ ],
+ "fwk_group": [],
+ "service_group": []
+ },
+ "inner_kits": [
+ {
+ "header": {
+ "header_base": "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
+ "header_files": [
+ "system_ability.h"
+ ]
+ },
+ "name": "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk"
+ }
+ ],
+ "test": [
+ "//foundation/systemabilitymgr/safwk/test:unittest"
+ ]
+ }
+ }
+}
diff --git a/safwk.spec b/safwk.spec
new file mode 100644
index 0000000..9865b9f
--- /dev/null
+++ b/safwk.spec
@@ -0,0 +1,125 @@
+%define debug_package %{nil}
+%global openHarmony_source_release OpenHarmony-v3.2-Release
+%global samgr_dir %{_builddir}/foundation/systemabilitymgr
+%global build_opt /opt/distributed-middleware-build
+%global safwk_path %{buildroot}%{build_opt}/openeuler/compiler_gn/foundation/systemabilitymgr/safwk
+
+Name: systemabilitymgr_safwk
+Version: 1.0.0
+Release: 5
+Summary: System ability manager
+License: Apache-2.0
+Url: https://gitee.com/openharmony/systemabilitymgr_safwk
+Source1: https://gitee.com/openharmony/systemabilitymgr_safwk/repository/archive/%{openHarmony_source_release}.tar.gz #/systemabilitymgr_safwk-%{openHarmony_source_release}.tar.gz
+Source2: safwk.bundle.json
+Source3: innerkits.safwk.BUILD.gn
+Source4: services.safwk.BUILD.gn
+Source5: start_services.sh
+Source6: stop_services.sh
+
+Patch1: 0000-remove-dependency-on-hitrace-safwk.patch
+Patch2: 0001-feat-for-embedded-fix-config_safwk-include_dirs.patch
+
+BuildRequires: gcc, make, hilog, libboundscheck
+BuildRequires: libatomic, libxml2-devel, cjson-devel
+BuildRequires: distributed-build, distributed-beget
+BuildRequires: commonlibrary_c_utils
+BuildRequires: notification_eventhandler
+BuildRequires: communication_ipc
+BuildRequires: systemabilitymgr_samgr
+
+Requires: commonlibrary_c_utils
+Requires: distributed-beget
+Requires: notification_eventhandler
+Requires: communication_ipc
+Requires: systemabilitymgr_samgr
+
+%description
+OpenEuler supports samgr for distributed softbus capability
+%prep
+rm -rf %{_builddir}/*
+
+cp -rf %{build_opt} %{_builddir}/build
+[ ! -L "%{_builddir}/build.sh" ] && ln -s %{_builddir}/build/build_scripts/build.sh %{_builddir}/build.sh
+[ ! -L "%{_builddir}/.gn" ] && ln -s %{_builddir}/build/core/gn/dotfile.gn %{_builddir}/.gn
+[ ! -L "%{_builddir}/build.py" ] && ln -s %{_builddir}/build/lite/build.py %{_builddir}/build.py
+cp -rf %{_builddir}/build/openeuler/vendor %{_builddir}/
+cp -rf %{_builddir}/build/openeuler/compiler_gn/* %{_builddir}
+
+
+# 统一用setup,不用autosetup,distributed-build除外
+mkdir -p %{samgr_dir}
+%setup -q -D -T -a 1 -c -n %{samgr_dir}
+# patch命令统一使用-P来指定第几个patch
+%patch -P1 -p1 -d %{samgr_dir}/safwk
+%patch -P2 -p1 -d %{samgr_dir}/safwk
+
+%build
+rm -rf %{_builddir}/out
+%ifarch x86_64
+bash %{_builddir}/build.sh --product-name openeuler --target-cpu x86_64
+%endif
+
+%ifarch aarch64
+bash %{_builddir}/build.sh --product-name openeuler --target-cpu arm64
+%endif
+
+%install
+install -d -m 0755 %{buildroot}/%{_includedir}/safwk
+install -d -m 0755 %{buildroot}/%{_libdir}
+install -d -m 0755 %{buildroot}/%{_bindir}
+install -d -m 0755 %{buildroot}/system/bin/
+install -d -m 0755 %{safwk_path}/interfaces/innerkits/safwk
+install -d -m 0755 %{safwk_path}/services/safwk
+
+%ifarch aarch64
+module_out_path="out/openeuler/linux_clang_arm64"
+%endif
+%ifarch x86_64
+module_out_path="out/openeuler/linux_clang_x86_64"
+%endif
+
+# prepare so
+install -m 0755 %{_builddir}/${module_out_path}/systemabilitymgr/safwk/*.so %{buildroot}/%{_libdir}
+
+# prepare bin
+install -m 0755 %{_builddir}/${module_out_path}/systemabilitymgr/safwk/sa_main %{buildroot}/%{_bindir}
+install -m 0755 %{_builddir}/${module_out_path}/systemabilitymgr/safwk/sa_main %{buildroot}/system/bin/
+install -m 0755 %{SOURCE5} %{buildroot}/system/bin/
+install -m 0755 %{SOURCE6} %{buildroot}/system/bin/
+
+# prepare head files
+install -m 554 %{samgr_dir}/safwk/services/safwk/include/*.h %{buildroot}/%{_includedir}/safwk
+install -m 554 %{samgr_dir}/safwk/interfaces/innerkits/safwk/*.h %{buildroot}/%{_includedir}/safwk
+# cp json file
+install -m 554 %{SOURCE2} %{safwk_path}/bundle.json
+
+# cp gn file
+install -m 554 %{SOURCE3} %{safwk_path}/interfaces/innerkits/safwk/BUILD.gn
+install -m 554 %{SOURCE4} %{safwk_path}/services/safwk/BUILD.gn
+
+#create soft link
+ln -s /usr/include/safwk/system_ability.h %{safwk_path}/interfaces/innerkits/safwk/system_ability.h
+
+%files
+%{_includedir}/safwk/*
+%{_libdir}/*.so
+%{_bindir}/sa_main
+/system/*
+%{build_opt}/*
+
+%changelog
+* Tue Apr 2 2024 s_c_c <shichuchao@huawei.com> - 1.0.0-5
+- Fix BUILD.gn sysroot path for embedded
+
+* Mon Apr 1 2024 s_c_c <shichuchao@huawei.com> - 1.0.0-4
+- Fix config_safwk include_dirs for embedded
+
+* Wed Mar 27 2024 tianhang <tian_hang@hoperun.com> - 1.0.0-3
+- update version to 1.0.0-3
+-
+* Mon Dec 18 2023 Peng He <hepeng68@huawei.com> - 1.0.0-2
+- Add shell scripts for services start/stop
+
+* Thu Oct 12 2023 muyuying <muyuying1@huawei.com> - 1.0.0-1
+- Init and adapt safwk to openEuler
diff --git a/services.safwk.BUILD.gn b/services.safwk.BUILD.gn
new file mode 100644
index 0000000..ba4f24a
--- /dev/null
+++ b/services.safwk.BUILD.gn
@@ -0,0 +1,23 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# 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("//build/ohos.gni")
+import("//build/config/sysroot.gni")
+
+ohos_prebuilt_executable("sa_main") {
+ source = "${sysroot}/usr/bin/sa_main"
+ install_enable = true
+
+ part_name = "safwk"
+ subsystem_name = "systemabilitymgr"
+} \ No newline at end of file
diff --git a/sources b/sources
new file mode 100644
index 0000000..abaf403
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+2054182ed9a514a6f233053b4d9bc2e0 systemabilitymgr_safwk-OpenHarmony-v3.2-Release.tar.gz
diff --git a/start_services.sh b/start_services.sh
new file mode 100755
index 0000000..f206f36
--- /dev/null
+++ b/start_services.sh
@@ -0,0 +1,178 @@
+#!/bin/bash
+
+# 此脚本用于拉起分布式各个服务
+# 使用方法:
+# 1. 启动所有服务: ./start_services.sh all
+# 2. 启动某个服务: ./start_services.sh [samgr|huks|deviceauth|softbus|dm|dfs|datamgr]
+
+BIN_PATH="/system/bin"
+
+# 定义map,保存参数和对应执行的shell命令
+# 如果需要增加服务启动,直接往此map中增加字段即可
+declare -A COMMAND_MAP=(
+ ["samgr"]="./samgr > /system/log/samgr.log 2>&1 &"
+ ["huks"]="./sa_main /system/profile/huks_service.xml > /system/log/huks_service.log 2>&1 &"
+ ["deviceauth"]="./deviceauth_service > /system/log/device_auth.log 2>&1 &"
+ ["softbus"]="./sa_main /system/profile/softbus_server.xml > /system/log/softbus_server.log 2>&1 &"
+ ["dm"]="./sa_main /system/profile/device_manager.xml > /system/log/device_manager.log 2>&1 &"
+ ["dfs"]="./sa_main /system/profile/distributedfiledaemon.xml > /system/log/distributedfiledaemon.log 2>&1 &"
+ ["datamgr"]="./sa_main /system/profile/distributeddata.xml > /system/log/datamgr.log 2>&1 &"
+)
+
+# 不同服务的前驱依赖关系
+declare -A CMD_REQUIRES=(
+ ["samgr"]=""
+ ["huks"]="samgr"
+ ["deviceauth"]="samgr huks"
+ ["softbus"]="samgr huks deviceauth"
+ ["dm"]="samgr huks deviceauth softbus"
+ ["dfs"]="samgr huks deviceauth softbus dm"
+ ["datamgr"]="samgr huks deviceauth softbus dm"
+)
+
+start_order=("samgr" "huks" "deviceauth" "softbus" "dm" "dfs" "datamgr")
+
+# 日志打印函数
+log() {
+ case $1 in
+ error)
+ echo "[ERROR] $2"
+ ;;
+ info)
+ echo "[INFO] $2"
+ ;;
+ debug)
+ if [ "$DEBUG_MODE" == "true" ]; then
+ echo "[DEBUG] $2"
+ fi
+ ;;
+ *)
+ echo "Invalid log level: $1"
+ ;;
+ esac
+}
+
+check_process_running() {
+ if pgrep -x "$1" > /dev/null; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+start_process() {
+ process_name=$1
+ deps="${CMD_REQUIRES[$process_name]}"
+
+ for dep in $deps; do
+ if check_process_running "$dep"; then
+ log info "Process '$dep' is already running"
+ continue
+ fi
+ if [ "${COMMAND_MAP[$dep]+isset}" ]; then
+ log info "Starting process '$dep'..."
+ eval ${COMMAND_MAP[$dep]}
+ sleep 1
+ else
+ log error "Invalid dependency: $dep"
+ exit 1
+ fi
+ done
+
+ if check_process_running "$process_name"; then
+ log info "Process '$process_name' is already running"
+ else
+ log info "Starting ddd process '$process_name'..."
+ if [ "${COMMAND_MAP[$process_name]+isset}" ]; then
+ eval ${COMMAND_MAP[$process_name]}
+ else
+ log error "Invalid process: $process_name"
+ exit 1
+ fi
+ fi
+}
+
+# 判断参数是否为空
+if [ -z "$1" ]; then
+ log error "Usage: $0 [all|samgr|huks|deviceauth|softbus|device_manager|dfs|datamgr]"
+ exit 1
+fi
+
+# 新建日志目录
+if [ ! -d "/system/log" ]; then
+ log info "/system/log directory not exist, create it"
+ sudo mkdir -p /system/log
+fi
+
+# 以IP地址生成SN号
+if [ ! -e "/etc/SN" ]; then
+ log info "SN file not exist, add content to it."
+ ipv4_address=$(ip -4 addr show scope global | grep inet | awk '{print $2}' | cut -d '/' -f 1)
+ echo "$ipv4_address" | sudo tee /etc/SN > /dev/null
+fi
+
+# 软链接动态库
+if [ ! -e "/usr/lib64/libsec_shared.z.so" ]; then
+ log info "libsec_shared.z.so not exist, create it"
+ ln -s /usr/lib64/libboundscheck.so /usr/lib64/libsec_shared.z.so
+fi
+
+# 检查 $LD_LIBRARY_PATH 是否包含 "/system/lib64",如果不包含则加入
+if [[ ":$LD_LIBRARY_PATH:" != *":/system/lib64:"* ]]; then
+ log info "/system/lib64 not in LD_LIBRARY_PATH, add it."
+ export LD_LIBRARY_PATH="/system/lib64:$LD_LIBRARY_PATH"
+fi
+
+# 检查是否关闭selinux,如果未关闭则关闭
+selinux_status=$(getenforce)
+if [ "$selinux_status" = "Enforcing" ]; then
+ echo "SELinux set to Permissive..."
+ sudo setenforce 0
+fi
+
+# 如果未开启binder,开启binder
+if [ ! -e "/dev/binder" ]; then
+ log info "Starting insert binder"
+ # 如果当前内核已经自带了binder,则直接进行binder的挂载
+ if grep -q '^CONFIG_ANDROID_BINDER_IPC=y$' /boot/config-$(uname -r); then
+ mkdir /dev/binderfs
+ sudo mount -t binder binder /dev/binderfs
+ sudo ln -s /dev/binderfs/binder /dev/binder
+ else # 内核没有开启binder,插入相关binder的ko
+ if [ ! -f "/lib/modules/$(uname -r)/binder/binder_linux.ko" ]; then
+ log error "no binder ko find, please install binder."
+ exit 1
+ fi
+ insmod /lib/modules/$(uname -r)/binder/binder_linux.ko
+ fi
+fi
+
+cd ${BIN_PATH} || exit
+# 如果有进程还在,暂停服务防止双进程存在
+if pgrep -x "samgr" > /dev/null; then
+ log info "service is running, stop it"
+ /system/bin/stop_services.sh all
+ sleep 2
+fi
+
+# 验证参数并执行相应命令
+if [ "$1" == "all" ]; then
+ log info "Starting all services..."
+ for key in "${start_order[@]}"; do
+ log info "Starting $key service..."
+ # 执行命令
+ eval ${COMMAND_MAP[$key]}
+ sleep 1
+ done
+else
+ if [ "${COMMAND_MAP[$1]+isset}" ]; then
+ log info "Starting $1 service..."
+ # 执行命令
+ start_process "$1"
+ else
+ log error "Invalid parameter: $1"
+ exit 1
+ fi
+fi
+
+log info "Done."
diff --git a/stop_services.sh b/stop_services.sh
new file mode 100755
index 0000000..10f186d
--- /dev/null
+++ b/stop_services.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+# 停止所有启动的分布式服务
+# 使用方法:
+# 1. 暂停所有服务:./stop_services.sh all
+# 2. 暂替某个服务:./stop_services.sh [samgr|huks|deviceauth|softbus|dm|dfs|datamgr]
+
+# 定义map,保存参数和对应执行的shell命令
+declare -A COMMAND_MAP=(
+ ["datamgr"]="pkill -f distributeddata"
+ ["dfs"]="pkill -f distributedfile"
+ ["dm"]="pkill -f device_manager"
+ ["softbus"]="pkill -f softbus_server"
+ ["deviceauth"]="pkill -f deviceauth_service"
+ ["huks"]="pkill -f huks_service"
+ ["samgr"]="pkill -f samgr"
+)
+
+# 日志打印函数
+log() {
+ case $1 in
+ error)
+ echo "[ERROR] $2"
+ ;;
+ info)
+ echo "[INFO] $2"
+ ;;
+ debug)
+ if [ "$DEBUG_MODE" == "true" ]; then
+ echo "[DEBUG] $2"
+ fi
+ ;;
+ *)
+ echo "Invalid log level: $1"
+ ;;
+ esac
+}
+
+# 判断参数是否为空
+if [ -z "$1" ]; then
+ log error "Usage: $0 [all|samgr|huks|deviceauth|softbus|dm|dfs|datamgr]"
+ exit 1
+fi
+
+# 验证参数并执行相应命令
+if [ "$1" == "all" ]; then
+ log info "Stop all services..."
+ for key in "${!COMMAND_MAP[@]}"; do
+ log info "Stop $key service..."
+ # 执行命令
+ eval ${COMMAND_MAP[$key]}
+ done
+else
+ if [ "${COMMAND_MAP[$1]+isset}" ]; then
+ log info "Stop $1 service..."
+ # 执行命令
+ eval ${COMMAND_MAP[$1]}
+ else
+ log error "Invalid parameter: $1"
+ exit 1
+ fi
+fi
+
+log info "Done."