Files
docker-nest-js/scripts/hot-remove.sh

55 lines
1.8 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
# host-remove.sh — remove um projeto completamente
# Uso: ./host-remove.sh meu-projeto
# Uso: ./host-remove.sh meu-projeto --keep-files (mantém os arquivos no host)
TARGET="${1:-}"
KEEP_FILES="${2:-}"
PROJECTS_DIR="/home/deploy/projects"
if [ -z "$TARGET" ]; then
echo "❌ Informe o nome do projeto."
echo " Uso: ./host-remove.sh meu-projeto"
echo " Uso: ./host-remove.sh meu-projeto --keep-files"
exit 1
fi
echo "================================================"
echo " Removendo projeto: $TARGET"
echo "================================================"
# 1. Para e remove do PM2
echo "→ Removendo do PM2..."
docker exec nestjs-stack pm2 delete "$TARGET" 2>/dev/null && echo " ✓ PM2 removido" || echo " ⚠ Não estava no PM2"
# 2. Remove config do nginx
echo "→ Removendo config do Nginx..."
docker exec nestjs-stack rm -f "/etc/nginx/sites-dynamic/${TARGET}.conf" && echo " ✓ Config nginx removida"
# 3. Recarrega nginx
echo "→ Recarregando Nginx..."
docker exec nestjs-stack nginx -s reload && echo " ✓ Nginx recarregado"
# 4. Salva estado do PM2
docker exec nestjs-stack pm2 save
# 5. Remove arquivos do host (opcional)
if [ "$KEEP_FILES" = "--keep-files" ]; then
echo " → Arquivos mantidos em $PROJECTS_DIR/$TARGET"
else
if [ -d "$PROJECTS_DIR/$TARGET" ]; then
echo "→ Removendo arquivos do projeto..."
rm -rf "$PROJECTS_DIR/$TARGET"
echo " ✓ Pasta $PROJECTS_DIR/$TARGET removida"
else
echo " ⚠ Pasta $PROJECTS_DIR/$TARGET não encontrada"
fi
fi
echo ""
echo "================================================"
echo " ✓ Projeto $TARGET removido com sucesso!"
if [ "$KEEP_FILES" = "--keep-files" ]; then
echo " Arquivos mantidos em $PROJECTS_DIR/$TARGET"
fi
echo "================================================"