Files
agt-build/build/opt/agt/bin/start.sh
2025-09-28 18:12:09 +08:00

90 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.
#!/bin/bash
set -e
# ==== 配置区 ====
MIRROR_URL="https://mirrors.aliyun.com/docker-ce"
COMPOSE_VERSION="2.29.2"
IMAGE_TAR=""
COMPOSE_FILE="../docker/docker-compose.yml"
# ==== 检查 root 权限 ====
if [ "$(id -u)" -ne 0 ]; then
echo "请使用 root 权限运行此脚本"
exit 1
fi
echo "[INFO] 开始启动服务..."
# ==== 检查并安装 Docker ====
if ! command -v docker &> /dev/null; then
echo "[INFO] 未检测到 Docker开始安装..."
if [ -f /etc/os-release ]; then
. /etc/os-release
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL ${MIRROR_URL}/linux/${ID}/gpg | apt-key add -
add-apt-repository \
"deb [arch=amd64] ${MIRROR_URL}/linux/${ID} \
$(lsb_release -cs) stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
elif [[ "$ID" == "centos" || "$ID" == "rhel" ]]; then
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo ${MIRROR_URL}/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
else
echo "[ERROR] 当前系统不支持自动安装 Docker请手动安装"
exit 1
fi
fi
systemctl enable docker
systemctl start docker
# ==== 配置 Docker 镜像加速器 ====
echo "[INFO] 配置 Docker 镜像加速器..."
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://mirror.ccs.tencentyun.com",
"https://mirrors.aliyun.com"
]
}
EOF
systemctl daemon-reload
systemctl restart docker
else
echo "[INFO] 已检测到 Docker"
fi
# ==== 检查并安装 docker-compose ====
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
echo "[INFO] 未检测到 docker-compose开始安装..."
curl -L "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
else
echo "[INFO] 已检测到 docker-compose"
fi
# ==== 导入镜像 ====
if [ -f "$IMAGE_TAR" ]; then
echo "[INFO] 导入镜像 $IMAGE_TAR ..."
docker load -i "$IMAGE_TAR"
fi
# ==== 启动服务 ====
if [ -f "$COMPOSE_FILE" ]; then
echo "[INFO] 使用 docker-compose 启动服务..."
docker compose -f "$COMPOSE_FILE" up -d --build
docker image prune -f
echo "[SUCCESS] 应用已部署完成!"
else
echo "[WARN] 未找到 $COMPOSE_FILE,跳过服务启动"
fi