You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

47 lines
1.2 KiB

#!/bin/bash
set -e
APP_NAME="your-app-name"
DEPLOY_PATH="/opt/production/$APP_NAME"
echo "🔄 Starting rollback process..."
# پیدا کردن آخرین نسخه سالم
RELEASES_DIR="$DEPLOY_PATH/releases"
CURRENT_RELEASE=$(readlink $DEPLOY_PATH/current 2>/dev/null || echo "")
if [ -z "$CURRENT_RELEASE" ]; then
echo "❌ No current release found"
exit 1
fi
# پیدا کردن نسخه قبلی
PREVIOUS_RELEASE=$(find $RELEASES_DIR -maxdepth 1 -name "release-*" -type d | grep -v "$CURRENT_RELEASE" | sort -r | head -n1)
if [ -z "$PREVIOUS_RELEASE" ]; then
echo "❌ No previous release found for rollback"
exit 1
fi
echo "📦 Rolling back from $(basename $CURRENT_RELEASE) to $(basename $PREVIOUS_RELEASE)"
# بروزرسانی symlink
sudo ln -sfn $PREVIOUS_RELEASE $DEPLOY_PATH/current
# ریاستارت PM2
cd $DEPLOY_PATH/current
pm2 restart ecosystem.config.js --env production
# بررسی سلامت
sleep 10
if ./scripts/health-check.sh; then
echo "✅ Rollback completed successfully!"
# حذف نسخه معیوب
sudo rm -rf $CURRENT_RELEASE
echo "🗑 Removed faulty release"
else
echo "❌ Rollback failed! Manual intervention required."
exit 1
fi