Files
chengshishouce/city-manual/deploy.sh

81 lines
1.9 KiB
Bash
Raw Permalink 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
# 城市手册 - 自动部署脚本
set -e
echo "🚀 开始部署城市手册项目..."
# 1. 安装依赖
echo "📦 安装 Python 依赖..."
cd /root/.openclaw/workspace/city-manual/backend
pip3 install -r requirements.txt --break-system-packages -q
# 2. 数据库迁移
echo "🗄️ 执行数据库迁移..."
python3 manage.py migrate --noinput
# 3. 收集静态文件
echo "📁 收集静态文件..."
python3 manage.py collectstatic --noinput
# 4. 创建 Gunicorn 服务
echo "⚙️ 创建 Gunicorn 服务..."
cat > /etc/systemd/system/city-manual.service << EOF
[Unit]
Description=City Manual Gunicorn Service
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/root/.openclaw/workspace/city-manual/backend
ExecStart=/usr/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/city-manual.sock city_manual.wsgi:application
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable city-manual
systemctl start city-manual
# 5. 配置 Nginx
echo "🌐 配置 Nginx..."
cat > /etc/nginx/sites-available/city-manual << 'EOF'
server {
listen 80;
server_name cssc.datalibstar.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /root/.openclaw/workspace/city-manual/backend/static/;
}
location /media/ {
alias /root/.openclaw/workspace/city-manual/backend/media/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/city-manual.sock;
}
}
EOF
ln -sf /etc/nginx/sites-available/city-manual /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
# 6. 导入示例数据
echo "📊 导入示例数据..."
python3 manage.py seed_data
echo ""
echo "✅ 部署完成!"
echo ""
echo "📍 访问地址http://cssc.datalibstar.com"
echo "📍 Admin: http://cssc.datalibstar.com/admin"
echo "📍 测试账号demo / demo123"