systemabilitymgr_safwk/stop_services.sh
虫儿飞 4075b150bf update the order of stopping services
Services should be stopped in the reverse order in which they were created

Signed-off-by: 虫儿飞 <wei_jiangang@hoperun.com>
2024-03-26 16:37:08 +08:00

65 lines
1.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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."