deploy.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. set -e
  3. echo "=== Auto-SSL 一键部署脚本 ==="
  4. # 1. 拉取最新代码
  5. echo "1. 拉取最新代码..."
  6. git pull origin 0.01
  7. # 2. 编译后端
  8. echo "2. 编译Go后端..."
  9. cd backend
  10. go build -o autossl .
  11. cd ..
  12. # 3. 编译前端
  13. echo "3. 编译Vue前端..."
  14. cd frontend
  15. npm install --production
  16. npm run build
  17. cd ..
  18. # 4. 部署前端到backend/dist
  19. echo "4. 部署前端资源..."
  20. rm -rf backend/dist/*
  21. cp -rf frontend/dist/* backend/dist/
  22. # 5. 创建systemd服务
  23. echo "5. 安装systemd服务..."
  24. sudo cp autossl.service /etc/systemd/system/
  25. sudo systemctl daemon-reload
  26. sudo systemctl enable autossl
  27. # 6. 重启服务
  28. echo "6. 重启服务..."
  29. sudo systemctl restart autossl
  30. # 7. 检查状态
  31. sleep 2
  32. echo "7. 检查服务状态..."
  33. if curl -s http://127.0.0.1:9090/api/stats > /dev/null; then
  34. echo "✅ 部署成功!服务运行在 http://0.0.0.0:9090"
  35. echo "📝 日志查看:journalctl -u autossl -f"
  36. else
  37. echo "❌ 部署失败,请检查日志:journalctl -u autossl -n 50"
  38. exit 1
  39. fi