#!/bin/bash # Uninstall DeployZap — reverses what install.sh created. # # Usage: # bash uninstall.sh Remove DeployZap app components; KEEP data # bash uninstall.sh --purge Also delete data volumes and /etc/deployzap # bash uninstall.sh --leave-swarm Also leave the Docker Swarm # bash uninstall.sh --purge --leave-swarm --yes # # Flags: # --purge Delete Postgres/Redis data volumes and /etc/deployzap # (Traefik config + TLS certificates). IRREVERSIBLE. # --leave-swarm Run `docker swarm leave --force` at the end. Only do this # if the node is dedicated to DeployZap — it tears down ALL # swarm services on the node, including apps you deployed. # --yes Skip the confirmation prompt (non-interactive). # # NOTE: This removes DeployZap itself. Applications, databases and stacks you # deployed THROUGH DeployZap are separate Docker services and are left running. # Remove those from the DeployZap UI before uninstalling, or delete them # manually afterwards (see the note printed at the end). set -u PURGE=false LEAVE_SWARM=false ASSUME_YES=false for arg in "$@"; do case "$arg" in --purge) PURGE=true ;; --leave-swarm) LEAVE_SWARM=true ;; --yes|-y) ASSUME_YES=true ;; *) echo "Unknown option: $arg" >&2; exit 1 ;; esac done RED="\033[0;31m" GREEN="\033[0;32m" YELLOW="\033[1;33m" NC="\033[0m" if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" >&2 exit 1 fi if ! command -v docker >/dev/null 2>&1; then echo "Docker is not installed; nothing to uninstall." >&2 exit 1 fi echo "This will remove the following DeployZap components:" echo " - services: deployzap, deployzap-postgres, deployzap-redis" echo " - container: deployzap-traefik" echo " - network: deployzap-network" echo " - secrets: deployzap_postgres_password, deployzap_auth_secret" if [ "$PURGE" = true ]; then printf "${RED} - volumes: deployzap-postgres, deployzap-redis, deployzap (ALL DATA)${NC}\n" printf "${RED} - directory: /etc/deployzap (Traefik config + TLS certificates)${NC}\n" else printf "${YELLOW} - volumes and /etc/deployzap are KEPT (use --purge to delete them)${NC}\n" fi if [ "$LEAVE_SWARM" = true ]; then printf "${RED} - the node will LEAVE the Docker Swarm${NC}\n" fi echo "" if [ "$ASSUME_YES" != true ]; then printf "Continue? [y/N] " read -r reply case "$reply" in [yY]|[yY][eE][sS]) ;; *) echo "Aborted."; exit 0 ;; esac fi echo "" echo "Removing DeployZap services..." docker service rm deployzap deployzap-postgres deployzap-redis 2>/dev/null || true echo "Removing Traefik container..." docker rm -f deployzap-traefik 2>/dev/null || true # Give the swarm a moment to release the overlay network endpoints. sleep 3 echo "Removing Docker secrets..." docker secret rm deployzap_postgres_password deployzap_auth_secret 2>/dev/null || true echo "Removing network..." docker network rm deployzap-network 2>/dev/null || true if [ "$PURGE" = true ]; then echo "Removing data volumes..." # `docker service rm` is asynchronous: the containers keep running for a # few seconds and volumes cannot be removed while in use. Retry until the # containers have released them (up to ~30s). list_volumes() { docker volume ls -q \ --filter 'name=^deployzap$' \ --filter 'name=^deployzap-postgres$' \ --filter 'name=^deployzap-redis$' } for _ in $(seq 1 30); do remaining=$(list_volumes) [ -z "$remaining" ] && break # shellcheck disable=SC2086 docker volume rm $remaining >/dev/null 2>&1 || true sleep 1 done remaining=$(list_volumes) if [ -n "$remaining" ]; then printf "${YELLOW}Warning: could not remove volumes (containers may still be stopping):${NC}\n" echo "$remaining" | sed 's/^/ /' echo "Remove them once the containers have exited:" echo " docker volume rm $(echo "$remaining" | tr '\n' ' ')" fi echo "Removing /etc/deployzap..." rm -rf /etc/deployzap fi if [ "$LEAVE_SWARM" = true ]; then echo "Leaving Docker Swarm..." docker swarm leave --force 2>/dev/null || true fi printf "${GREEN}DeployZap has been uninstalled.${NC}\n" if [ "$PURGE" != true ]; then echo "" printf "${YELLOW}Data was preserved.${NC} To delete it later:\n" echo " docker volume rm deployzap-postgres deployzap-redis deployzap" echo " rm -rf /etc/deployzap" fi echo "" echo "Note: applications you deployed through DeployZap are separate Docker" echo "services and may still be running. List and remove them with:" echo " docker service ls" echo " docker stack ls" echo " docker service rm # or: docker stack rm "