Files
docker-nest-js/host-remove.sh

51 lines
1.7 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 "================================================"
echo "→ Removendo do PM2..."
docker exec nestjs-stack pm2 delete "$TARGET" 2>/dev/null && echo " ✓ PM2 removido" || echo " ⚠ Não estava no PM2"
echo "→ Removendo config do Nginx..."
docker exec nestjs-stack rm -f "/etc/nginx/sites-dynamic/${TARGET}.conf" && echo " ✓ Config nginx removida"
echo "→ Recarregando Nginx..."
docker exec nestjs-stack nginx -s reload && echo " ✓ Nginx recarregado"
docker exec nestjs-stack pm2 save
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!"
if [ "$KEEP_FILES" = "--keep-files" ]; then
echo " Arquivos mantidos em $PROJECTS_DIR/$TARGET"
fi
echo "================================================"