87 lines
2.2 KiB
Bash
87 lines
2.2 KiB
Bash
|
|
#!/bin/bash
|
|||
|
|
# 日记系统 - 自动部署脚本
|
|||
|
|
|
|||
|
|
set -e
|
|||
|
|
|
|||
|
|
echo "🚀 开始部署日记系统..."
|
|||
|
|
|
|||
|
|
# 1. 安装依赖
|
|||
|
|
echo "📦 安装 Python 依赖..."
|
|||
|
|
cd /root/.openclaw/workspace/diary-system/backend
|
|||
|
|
pip3 install -r requirements.txt --break-system-packages -q
|
|||
|
|
|
|||
|
|
# 2. 数据库迁移
|
|||
|
|
echo "🗄️ 执行数据库迁移..."
|
|||
|
|
python3 manage.py makemigrations diary --noinput
|
|||
|
|
python3 manage.py migrate --noinput
|
|||
|
|
|
|||
|
|
# 3. 收集静态文件
|
|||
|
|
echo "📁 收集静态文件..."
|
|||
|
|
mkdir -p /root/.openclaw/workspace/diary-system/backend/static
|
|||
|
|
python3 manage.py collectstatic --noinput
|
|||
|
|
|
|||
|
|
# 4. 创建 Gunicorn 服务
|
|||
|
|
echo "⚙️ 创建 Gunicorn 服务..."
|
|||
|
|
cat > /etc/systemd/system/diary-system.service << EOF
|
|||
|
|
[Unit]
|
|||
|
|
Description=Diary System Gunicorn Service
|
|||
|
|
After=network.target
|
|||
|
|
|
|||
|
|
[Service]
|
|||
|
|
User=root
|
|||
|
|
Group=root
|
|||
|
|
WorkingDirectory=/root/.openclaw/workspace/diary-system/backend
|
|||
|
|
ExecStart=/usr/bin/gunicorn --access-logfile - --workers 3 --bind 127.0.0.1:8002 diary_system.wsgi:application
|
|||
|
|
Restart=always
|
|||
|
|
|
|||
|
|
[Install]
|
|||
|
|
WantedBy=multi-user.target
|
|||
|
|
EOF
|
|||
|
|
|
|||
|
|
systemctl daemon-reload
|
|||
|
|
systemctl enable diary-system
|
|||
|
|
systemctl start diary-system
|
|||
|
|
|
|||
|
|
# 5. 配置 Nginx
|
|||
|
|
echo "🌐 配置 Nginx..."
|
|||
|
|
cat > /etc/nginx/sites-available/diary-system << 'EOF'
|
|||
|
|
server {
|
|||
|
|
listen 8001;
|
|||
|
|
server_name _;
|
|||
|
|
|
|||
|
|
location = /favicon.ico { access_log off; log_not_found off; }
|
|||
|
|
|
|||
|
|
location /static/ {
|
|||
|
|
alias /root/.openclaw/workspace/diary-system/backend/static/;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
location /api/ {
|
|||
|
|
proxy_pass http://127.0.0.1:8002;
|
|||
|
|
proxy_set_header Host $host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
location / {
|
|||
|
|
root /root/.openclaw/workspace/diary-system/frontend;
|
|||
|
|
index index.html;
|
|||
|
|
try_files $uri $uri/ /index.html;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
EOF
|
|||
|
|
|
|||
|
|
ln -sf /etc/nginx/sites-available/diary-system /etc/nginx/sites-enabled/
|
|||
|
|
nginx -t
|
|||
|
|
systemctl restart nginx
|
|||
|
|
|
|||
|
|
# 6. 同步日记数据
|
|||
|
|
echo "📊 同步日记数据..."
|
|||
|
|
python3 /root/.openclaw/workspace/diary-system/sync_diary.py
|
|||
|
|
|
|||
|
|
echo ""
|
|||
|
|
echo "✅ 部署完成!"
|
|||
|
|
echo ""
|
|||
|
|
echo "📍 访问地址:http://cssc.datalibstar.com:8001"
|
|||
|
|
echo "📍 API: http://cssc.datalibstar.com:8001/api/"
|
|||
|
|
echo "📍 Admin: http://cssc.datalibstar.com:8001/admin"
|