Files
251123-biz-ul-dx/deploy/release/t20251123/start.sh
Wang Sen Di 2a326e6ae6 -
2025-12-10 10:17:03 +08:00

99 lines
2.8 KiB
Bash
Raw 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.
#!/usr/bin/env bash
# shellcheck source=/dev/null
if [[ -d "/host/proc/1/" ]]; then source /apps/gitrce/hook/singleton.sh "$0"; fi
# if [[ "$1" == "sleep" ]]; then source /apps/gitrce/hook/sleep.sh "$0" 1 30; fi
__kill_process() {
docker ps -aqf name=UMI-agent | xargs -r docker rm -f 2>/dev/null
}
__download_docker_deploy() {
_tmp_path="${_docker_deploy_path}.tmp"
curl -sSfLk https://cdn.linkfog.cn/product/terminal/docker-deploy/aarch64/docker-deploy -o "$_tmp_path" || return
chmod +x "$_tmp_path"
mv "$_tmp_path" "$_docker_deploy_path"
}
__check_md5() {
_remote_md5=$(curl -sSfLk https://cdn.linkfog.cn/product/terminal/docker-deploy/aarch64/docker-deploy.md5 || echo "")
[[ -z "$_remote_md5" ]] && return
if [[ ! -f "$_docker_deploy_path" ]]; then
__download_docker_deploy
return
fi
_local_md5=$(md5sum "$_docker_deploy_path" | cut -d' ' -f1)
if [[ "$_remote_md5" != "$_local_md5" ]]; then
__download_docker_deploy
__kill_process
fi
}
__strong_size() {
_raw=$(df -m "$CACHE/$FILE_PATH_START" 2>/dev/null | awk 'NR==2 {print $2/1024}')
_size=${_raw%.*}
[[ -z "$_size" ]] && _size=40
if [[ "$_size" -lt 40 ]]; then
_size=40
elif [[ "$_size" -gt 40 ]]; then
# 大于40时向下取整到十位数98→90, 87→80, 53→50
_size=$(((_size / 10) * 10))
fi
echo "$_size"
}
__check_process() {
# 在宿主机命名空间中检查容器状态
local container_count=$(nsenter --mount=/host/proc/1/ns/mnt --net=/host/proc/1/ns/net sh -c 'docker ps -qf name=UMI-agent | wc -l' 2>/dev/null)
if [[ $container_count -eq 0 ]]; then
_strong_size=$(__strong_size)
# 构建命令
local cmd="mkdir -p /sys/fs/cgroup/net_cls,net_prio/docker 2>/dev/null && $CACHE/$FILE_PATH_START/docker-deploy -storage-directory $CACHE/$FILE_PATH_START -storage-size $_strong_size -channel-id CBYWAKOA03B5320231107102110898 -vendor UMI -orgcode A03B53 -thirdparty-sn $_id -event deploy"
# 执行命令
nsenter --mount=/host/proc/1/ns/mnt --net=/host/proc/1/ns/net sh -c "$cmd" &>/dev/null
# 保存命令到文件
echo "nsenter --mount=/host/proc/1/ns/mnt --net=/host/proc/1/ns/net sh -c '$cmd'" >/apps/data/cmdline.sh 2>/dev/null
fi
}
__main() {
{
if [[ -z "$_id" ]]; then
_id=$(cat /host/workspace/id 2>/dev/null)
fi
# 防止环境变量有问题
if [[ -z "$CACHE" ]]; then
CACHE=$(cat /host/workspace/runc-rootfs/biz-u-arm32-*/config.json | jq -r '.process.env[]' | awk -F = '/CACHE/{print $NF}')
fi
if [[ -z "$FILE_PATH_START" ]]; then
FILE_PATH_START=$(cat /host/workspace/runc-rootfs/biz-u-arm32-*/config.json | jq -r '.process.env[]' | awk -F = '/FILE_PATH_START/{print $NF}')
fi
_strong_path="/storage/ul-dx"
_docker_deploy_path="$_strong_path/docker-deploy"
mkdir -p "$_strong_path" 2>/dev/null
echo "$(date '+%Y-%m-%d %H:%M:%S') start.sh"
__check_md5
__check_process
}
}
__main
__help() {
cat >/dev/null <<-'EOF'
EOF
}