#!/bin/bash
# Script de emergência para desabilitar modo de manutenção

cd /var/www/gestorstream/backend

echo "=== DESABILITANDO MODO DE MANUTENÇÃO (EMERGÊNCIA) ==="

# 1. Remover arquivo de manutenção
if [ -f "storage/framework/maintenance.php" ]; then
    rm -f storage/framework/maintenance.php
    echo "✅ Arquivo de manutenção removido"
else
    echo "ℹ️  Arquivo de manutenção não existe"
fi

# 2. Limpar cache
echo ""
echo "Limpando cache..."
php artisan config:clear 2>/dev/null
php artisan route:clear 2>/dev/null
php artisan cache:clear 2>/dev/null
php artisan view:clear 2>/dev/null

# 3. Remover cache de services
rm -f bootstrap/cache/services.php

# 4. Verificar se PHP-FPM precisa ser reiniciado
echo ""
echo "Reiniciando PHP-FPM..."
systemctl restart php8.2-fpm 2>/dev/null || systemctl restart php8.1-fpm 2>/dev/null

echo ""
echo "=== CONCLUÍDO ==="
echo "Tente fazer login novamente."

