zkt26/sk1/remove-app.sh

39 lines
1.2 KiB
Bash

#!/bin/bash
# remove-app.sh — Stop and remove all ShortLink containers, networks and volumes.
# Conditions: Run from the sk1 directory on the VM where prepare-app.sh was executed.
# Docker and Docker Compose must be installed.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "======================================================"
echo " ShortLink — Removal Script"
echo "======================================================"
echo ""
echo "This will:"
echo " • Stop all ShortLink containers"
echo " • Remove containers, networks, and named volumes (database data)"
echo " • SSL certificates will NOT be removed"
echo ""
read -rp "Are you sure? [y/N] " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 0
fi
echo ""
echo "[1/2] Stopping and removing containers, networks and volumes..."
docker compose down -v --remove-orphans
echo "[2/2] Removing built images..."
docker compose images -q 2>/dev/null | xargs -r docker rmi -f 2>/dev/null || true
echo ""
echo "✅ Application removed successfully."
echo ""
echo "Note: SSL certificates in /etc/letsencrypt were NOT removed."
echo "To remove them manually:"
echo " sudo certbot delete --cert-name ${DOMAIN:-your-domain}"