Files
AIGC/demo/deploy-to-server.sh

75 lines
1.9 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
# ============================================
# AIGC项目部署脚本沙箱测试环境
# ============================================
echo "🚀 开始部署 AIGC 项目到生产服务器..."
# 配置变量
SERVER="root@vionow.com"
REMOTE_DIR="/opt/aigc"
JAR_FILE="target/demo-0.0.1-SNAPSHOT.jar"
FRONTEND_DIR="frontend/dist"
# 检查JAR文件是否存在
if [ ! -f "$JAR_FILE" ]; then
echo "❌ JAR文件不存在请先运行 mvnw clean package"
exit 1
fi
# 检查前端文件是否存在
if [ ! -d "$FRONTEND_DIR" ]; then
echo "❌ 前端dist目录不存在请先运行 npm run build"
exit 1
fi
# 1. 上传后端JAR文件
echo "📦 上传后端JAR文件..."
scp "$JAR_FILE" "$SERVER:$REMOTE_DIR/"
# 2. 上传前端文件
echo "📦 上传前端文件..."
scp -r "$FRONTEND_DIR"/* "$SERVER:/var/www/html/"
# 3. 在服务器上重启服务
echo "🔄 重启服务..."
ssh "$SERVER" << 'ENDSSH'
# 停止旧服务
echo "⏹️ 停止旧服务..."
pkill -f demo-0.0.1-SNAPSHOT.jar
sleep 3
# 启动新服务
echo "▶️ 启动新服务..."
cd /opt/aigc
nohup java -jar demo-0.0.1-SNAPSHOT.jar \
--spring.profiles.active=prod \
--spring.config.additional-location=file:./application-prod.properties \
> app.log 2>&1 &
# 等待启动
sleep 5
# 检查服务状态
if pgrep -f demo-0.0.1-SNAPSHOT.jar > /dev/null; then
echo "✅ 服务启动成功!"
echo "📋 最新日志:"
tail -n 20 app.log
else
echo "❌ 服务启动失败,请检查日志:"
tail -n 50 app.log
exit 1
fi
ENDSSH
echo ""
echo "✅ 部署完成!"
echo "🌐 访问地址:"
echo " 前端https://vionow.com"
echo " 后端https://vionow.com/api/"
echo " Swaggerhttps://vionow.com/swagger-ui.html"
echo ""
echo "📋 查看实时日志:"
echo " ssh $SERVER 'tail -f /opt/aigc/app.log'"