Files
Auto-ssl/deploy.sh
T
cnbugs 2d70a15307 feat: add login authentication and certificate expiry notifications
- JWT-based login with ADMIN_USER/ADMIN_PASSWORD env config
- Login page with auth guard for Vue frontend
- Feishu bot webhook notification for expiring certificates
- SMTP email notification for expiring certificates
- Daily 8:00 AM cron for expiry checks
- Startup health check notification
2026-07-23 16:25:02 +08:00

87 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "=== Auto-SSL 一键部署脚本 ===
# 1. 拉取最新代码
echo "1. 拉取最新代码..."
git pull origin master 2>/dev/null || git pull origin 0.01 2>/dev/null || echo " (跳过git拉取)"
# 2. 编译后端
echo "2. 编译Go后端..."
cd backend
go build -o autossl .
cd ..
# 3. 编译前端
echo "3. 编译Vue前端..."
cd frontend
npm install --include=dev
npm run build
cd ..
# 4. 部署前端资源...
echo "4. 部署前端资源..."
rm -rf backend/dist
mkdir -p backend/dist
cp -rf frontend/dist/* backend/dist/
# 5. 创建systemd服务
echo "5. 安装systemd服务..."
cat > /tmp/autossl.service << EOF
[Unit]
Description=Auto-SSL 证书管理服务
After=network.target
Wants=network.target
[Service]
Type=simple
User=root
WorkingDirectory=$PWD/backend
Environment="PORT=9090"
Environment="ACME_PORT=8082"
Environment="GIN_MODE=release"
Environment="ADMIN_USER=admin"
Environment="ADMIN_PASSWORD=****?
Environment="JWT_SECRET="
# 飞书机器人通知(可选)
# Environment="FEISHU_WEBHOOK_URL=https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx"
# 邮件通知(可选)
# Environment="SMTP_HOST=smtp.example.com"
# Environment="SMTP_PORT=587"
# Environment="SMTP_USER=user@example.com"
# Environment="SMTP_PASSWORD=password"
# Environment="SMTP_FROM=user@example.com"
# Environment="NOTIFY_TO=admin@example.com"
ExecStart=$PWD/backend/autossl
Restart=always
RestartSec=3
StandardOutput=journal+console
StandardError=journal+console
SyslogIdentifier=autossl
[Install]
WantedBy=multi-user.target
EOF
sudo cp /tmp/autossl.service /etc/systemd/system/autossl.service
sudo systemctl daemon-reload
sudo systemctl enable autossl
# 6. 重启服务
echo "6. 重启服务..."
sudo systemctl restart autossl
# 7. 检查状态
sleep 2
echo "7. 检查服务状态..."
if curl -s http://127.0.0.1:9090/api/health > /dev/null; then
echo "✅ 部署成功!服务运行在 http://0.0.0.0:9090"
echo "📝 日志查看:journalctl -u autossl -f"
echo ""
echo "默认登录账号: admin / admin123"
echo "请通过环境变量 ADMIN_USER / ADMIN_PASSWORD 修改密码"
else
echo "❌ 部署失败,请检查日志:journalctl -u autossl -n 50"
exit 1
fi