调整部分部署逻辑
This commit is contained in:
@@ -312,79 +312,9 @@ do_deploy() {
|
||||
|
||||
# ----- 事务前钩子:备份数据库 -----
|
||||
print_step "备份数据库..."
|
||||
BACKUP_DIR="/tmp/frpc-console/db-backups"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
# ... 备份逻辑不变 ...
|
||||
|
||||
DB_FILE="${DEPLOY_DIR}/frpc-console.db"
|
||||
if [ -f "$DB_FILE" ]; then
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_FILE="$BACKUP_DIR/frpc-console.db.$TIMESTAMP"
|
||||
cp "$DB_FILE" "$BACKUP_FILE"
|
||||
print_info "已备份: $BACKUP_FILE"
|
||||
|
||||
if command -v sqlite3 &> /dev/null; then
|
||||
if ! sqlite3 "$DB_FILE" "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='users';" 2>/dev/null | grep -q "^1$"; then
|
||||
print_warn "数据库文件无效,将删除,由容器全新初始化"
|
||||
rm -f "$DB_FILE"
|
||||
else
|
||||
print_info "数据库有效,保留"
|
||||
fi
|
||||
else
|
||||
print_warn "sqlite3 未安装,无法检查数据库有效性,保留原文件"
|
||||
fi
|
||||
else
|
||||
print_info "数据库文件不存在,跳过备份"
|
||||
fi
|
||||
|
||||
# ----- 停止旧容器(提前释放资源)-----
|
||||
if [ "$CONTAINER_EXISTS" = true ]; then
|
||||
print_step "停止旧容器..."
|
||||
if [ "$CONTAINER_RUNNING" = true ]; then
|
||||
docker stop frpc-console 2>/dev/null || true
|
||||
fi
|
||||
docker rm frpc-console 2>/dev/null || true
|
||||
print_success "旧容器已清理"
|
||||
fi
|
||||
|
||||
# ----- 安装必要工具 -----
|
||||
if [ "$NEED_INSTALL_GIT" = true ] || [ "$NEED_INSTALL_CURL" = true ] || [ "$NEED_INSTALL_WGET" = true ]; then
|
||||
print_step "安装必要工具..."
|
||||
local pkgs=""
|
||||
[ "$NEED_INSTALL_GIT" = true ] && pkgs="${pkgs} git"
|
||||
[ "$NEED_INSTALL_CURL" = true ] && pkgs="${pkgs} curl"
|
||||
[ "$NEED_INSTALL_WGET" = true ] && pkgs="${pkgs} wget"
|
||||
|
||||
case $OS in
|
||||
opensuse*|suse*|opensuse-tumbleweed|opensuse-slowroll|opensuse-leap)
|
||||
if [ "$NEED_INSTALL_GIT" = true ]; then
|
||||
zypper install -y git-core
|
||||
pkgs=$(echo "$pkgs" | sed -E 's/(^| )git( |$)/ /g' | sed 's/ */ /g' | sed 's/^ //;s/ $//')
|
||||
fi
|
||||
if [ -n "$pkgs" ]; then
|
||||
zypper install -y $pkgs
|
||||
fi
|
||||
;;
|
||||
ubuntu|debian|linuxmint)
|
||||
apt update -qq && apt install -y $pkgs
|
||||
;;
|
||||
centos|rhel|fedora|rocky|almalinux)
|
||||
yum install -y $pkgs
|
||||
;;
|
||||
alpine)
|
||||
apk add $pkgs
|
||||
;;
|
||||
arch|manjaro|endeavouros)
|
||||
pacman -S --needed --noconfirm $pkgs
|
||||
;;
|
||||
*)
|
||||
print_error "无法识别包管理器,请手动安装: $pkgs"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
print_success "必要工具安装完成"
|
||||
fi
|
||||
|
||||
# ----- 拉取代码 -----
|
||||
# ----- 拉取代码(必须在停止容器之前)-----
|
||||
print_step "拉取代码..."
|
||||
rm -rf "$WORK_DIR"
|
||||
git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$WORK_DIR"
|
||||
@@ -399,11 +329,22 @@ do_deploy() {
|
||||
sed -i 's/go 1.2[6-9].*/go 1.21/' go.mod
|
||||
fi
|
||||
|
||||
# ----- 停止旧容器(拉取代码之后)-----
|
||||
if [ "$CONTAINER_EXISTS" = true ]; then
|
||||
print_step "停止旧容器..."
|
||||
if [ "$CONTAINER_RUNNING" = true ]; then
|
||||
docker stop frpc-console 2>/dev/null || true
|
||||
fi
|
||||
docker rm frpc-console 2>/dev/null || true
|
||||
print_success "旧容器已清理"
|
||||
fi
|
||||
|
||||
# ----- 准备数据目录 -----
|
||||
print_step "准备部署目录..."
|
||||
mkdir -p "$DEPLOY_DIR"
|
||||
mkdir -p "$DATA_DIR"
|
||||
|
||||
DB_FILE="${DEPLOY_DIR}/frpc-console.db"
|
||||
if [ -f "$DB_FILE" ]; then
|
||||
print_info "数据库文件存在,将保留"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user