第一个项目
This commit is contained in:
40
deploy.sh
Normal file
40
deploy.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
SERVER_IP="192.168.3.105"
|
||||
USER="xiaji"
|
||||
DEPLOY_DIR="/home/xiaji/deploy_$(date +%s)"
|
||||
LOG_FILE="$DEPLOY_DIR/deploy.log"
|
||||
|
||||
# 上传公钥
|
||||
ssh-copy-id -i ~/.ssh/id_rsa.pub $USER@$SERVER_IP
|
||||
|
||||
# 执行远程部署
|
||||
ssh $USER@$SERVER_IP << EOF
|
||||
set -e
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y python3-pip python3-venv nginx
|
||||
|
||||
mkdir -p $DEPLOY_DIR
|
||||
tar -xzvf ~/family_rpa.tar.gz -C $DEPLOY_DIR
|
||||
|
||||
python3 -m venv $DEPLOY_DIR/venv
|
||||
source $DEPLOY_DIR/venv/bin/activate
|
||||
pip install -r $DEPLOY_DIR/family_rpa/requirements.txt
|
||||
|
||||
# 生产配置检查
|
||||
if ! grep -q "DEBUG = False" $DEPLOY_DIR/family_rpa/family_rpa/settings.py; then
|
||||
echo "ERROR: 未检测到生产环境配置" | tee -a $LOG_FILE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 迁移数据库
|
||||
python $DEPLOY_DIR/family_rpa/manage.py migrate
|
||||
python $DEPLOY_DIR/family_rpa/manage.py collectstatic --noinput
|
||||
|
||||
# 切换部署版本
|
||||
sudo systemctl stop family_rpa.service
|
||||
sudo rm -rf /home/xiaji/myproject
|
||||
mv $DEPLOY_DIR/family_rpa /home/xiaji/myproject
|
||||
sudo systemctl start family_rpa.service
|
||||
|
||||
echo "部署成功!访问地址:http://$SERVER_IP" | tee -a $LOG_FILE
|
||||
EOF
|
||||
Reference in New Issue
Block a user