Files
chengshishouce/city-manual/scripts/deploy-to-cloud.sh
maoshen 3a01b98860 fix: 添加 psycopg2-binary 和 gunicorn 到依赖
- 添加 PostgreSQL 驱动 psycopg2-binary
- 添加 gunicorn 生产服务器
2026-04-12 21:59:43 +00:00

83 lines
2.0 KiB
Bash
Executable File
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
# 城市手册 - 云服务器部署脚本
# 用法:./deploy-to-cloud.sh
set -e
# 配置
SERVER_HOST="cssc.datalibstar.com"
SERVER_USER="ubuntu"
SERVER_PASS="825670@MashenClaw"
PROJECT_PATH="/root/.openclaw/workspace/city-manual"
echo "🚀 开始部署到云服务器..."
echo "服务器:$SERVER_USER@$SERVER_HOST"
echo ""
# 检查 sshpass
if ! command -v sshpass &> /dev/null; then
echo "❌ 错误sshpass 未安装"
echo "请运行sudo apt install sshpass"
exit 1
fi
# 1. 提交本地更改
echo "📝 提交本地更改..."
cd $PROJECT_PATH
git add -A
git commit -m "deploy: 准备部署到云服务器" || echo "无更改需要提交"
git push origin master
# 2. SSH 到服务器并部署
echo "🔌 连接到服务器..."
sshpass -p "$SERVER_PASS" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_HOST << 'ENDSSH'
echo "📦 拉取最新代码..."
cd /root/.openclaw/workspace/city-manual || {
echo "❌ 项目目录不存在"
exit 1
}
git pull origin master
echo "🐍 激活虚拟环境..."
source /root/.openclaw/workspace/city-manual/backend/venv/bin/activate || {
echo "❌ 虚拟环境不存在,请先手动创建"
exit 1
}
echo "📦 安装依赖..."
pip install -r requirements.txt -q
echo "🗄️ 数据库迁移..."
cd backend
python manage.py migrate --noinput
echo "📁 收集静态文件..."
python manage.py collectstatic --noinput --clear
echo "⚙️ 重启 Gunicorn..."
sudo systemctl restart city-manual || {
echo "⚠️ Gunicorn 服务不存在,请手动创建"
}
echo "🌐 检查 Nginx..."
sudo nginx -t && sudo systemctl reload nginx || {
echo "⚠️ Nginx 配置有问题"
}
echo ""
echo "✅ 部署完成!"
echo ""
echo "📍 访问地址http://cssc.datalibstar.com"
echo "📍 Admin: http://cssc.datalibstar.com/admin"
echo "📍 测试账号demo / demo123"
ENDSSH
if [ $? -eq 0 ]; then
echo ""
echo "🎉 部署成功!"
else
echo ""
echo "❌ 部署失败,请检查服务器日志"
exit 1
fi