81 lines
2.6 KiB
Bash
81 lines
2.6 KiB
Bash
#!/bin/bash
|
|
# بازگردانی سرور به حالت قبل از CDN — بدون ParsPack
|
|
# اجرا: bash /root/modstagram-back/scripts/revert-cdn-server.sh
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
SERVER_IP="${SERVER_IP:-185.164.73.197}"
|
|
|
|
echo "=========================================="
|
|
echo " Revert CDN / restore direct API storage"
|
|
echo " Server IP: $SERVER_IP"
|
|
echo "=========================================="
|
|
|
|
echo ""
|
|
echo ">>> [1/5] Disable CDN nginx site..."
|
|
rm -f /etc/nginx/sites-enabled/cdn.modstagram.com.conf
|
|
rm -f /etc/nginx/sites-enabled/cdn.modstagram.com.http.conf 2>/dev/null || true
|
|
|
|
echo ""
|
|
echo ">>> [2/5] Restore API nginx (proxy to Node 3002)..."
|
|
if [ -f "$SCRIPT_DIR/nginx/api.modstagram.com.conf" ]; then
|
|
cp "$SCRIPT_DIR/nginx/api.modstagram.com.conf" /etc/nginx/sites-available/api.modstagram.com.conf
|
|
ln -sf /etc/nginx/sites-available/api.modstagram.com.conf /etc/nginx/sites-enabled/api.modstagram.com.conf
|
|
fi
|
|
|
|
echo ""
|
|
echo ">>> [3/5] Stop local BIND9 (optional — if it conflicts with registrar DNS)..."
|
|
if systemctl is-active --quiet bind9 2>/dev/null; then
|
|
systemctl stop bind9 2>/dev/null || true
|
|
systemctl disable bind9 2>/dev/null || true
|
|
echo " BIND9 stopped (DNS now from registrar only)"
|
|
else
|
|
echo " BIND9 not running"
|
|
fi
|
|
|
|
echo ""
|
|
echo ">>> [4/5] Test nginx and reload..."
|
|
nginx -t
|
|
systemctl reload nginx
|
|
|
|
echo ""
|
|
echo ">>> [5/5] Restart backend + check local storage..."
|
|
if command -v pm2 >/dev/null 2>&1; then
|
|
pm2 restart modstagram-back || pm2 restart all || true
|
|
fi
|
|
|
|
sleep 2
|
|
|
|
echo ""
|
|
echo "--- Local diagnostics (no curl needed) ---"
|
|
echo -n "API version: "
|
|
wget -qO- --timeout=5 http://127.0.0.1:3002/api/v1/version 2>/dev/null || echo "FAILED"
|
|
|
|
SAMPLE_IMG=$(find /root/modstagram-back/storage/posts/images -type f 2>/dev/null | head -1)
|
|
if [ -n "$SAMPLE_IMG" ]; then
|
|
REL="/storage/posts/images/$(basename "$SAMPLE_IMG")"
|
|
echo "Sample file: $SAMPLE_IMG"
|
|
echo "Testing: http://127.0.0.1:3002$REL"
|
|
wget -S --spider --timeout=5 "http://127.0.0.1:3002$REL" 2>&1 | head -8
|
|
else
|
|
echo "WARN: no images in storage/posts/images"
|
|
fi
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo " DONE"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo " Apps must use:"
|
|
echo " NEXT_PUBLIC_IMAGE_BASE_URL=https://api.modstagram.com/storage"
|
|
echo ""
|
|
echo " In ParsPack panel (when ready):"
|
|
echo " - Disable WCDN for api.modstagram.com"
|
|
echo " - A record api -> $SERVER_IP"
|
|
echo ""
|
|
echo " Rebuild frontends:"
|
|
echo " cd /root/modstagram-next && npm run build && pm2 restart modstagram-next"
|
|
echo " cd /root/modstagram_panel && npm run build && pm2 restart modstagram_panel"
|
|
echo ""
|