Files
file_lan/deploy.sh
2025-02-16 21:51:06 +08:00

41 lines
1.1 KiB
Bash
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
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