foxy-dev-team/scripts/uninstall-services.sh

74 lines
2.8 KiB
Bash

#!/usr/bin/env bash
# ═══════════════════════════════════════════════════════════════════════════════
# 🦊 Foxy Dev Team — Service Uninstaller
# ═══════════════════════════════════════════════════════════════════════════════
# Stops, disables, and removes systemd user services for:
# - foxy-api (FastAPI backend)
# - foxy-telegram (Telegram bot v3)
#
# Usage:
# chmod +x uninstall-services.sh
# ./uninstall-services.sh
# ═══════════════════════════════════════════════════════════════════════════════
set -euo pipefail
SERVICE_DIR="$HOME/.config/systemd/user"
SERVICES=("foxy-api" "foxy-telegram")
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
log() { echo -e "${CYAN}[UNINSTALL]${NC} $1"; }
ok() { echo -e "${GREEN}${NC} $1"; }
warn() { echo -e "${YELLOW} ⚠️${NC} $1"; }
log "🦊 Foxy Dev Team — Désinstallation des services"
echo ""
for svc in "${SERVICES[@]}"; do
UNIT="${svc}.service"
log "Traitement de $svc..."
# Stop if running
if systemctl --user is-active --quiet "$UNIT" 2>/dev/null; then
systemctl --user stop "$UNIT"
ok "$svc arrêté"
else
warn "$svc n'était pas en cours d'exécution"
fi
# Disable
if systemctl --user is-enabled --quiet "$UNIT" 2>/dev/null; then
systemctl --user disable "$UNIT"
ok "$svc désactivé"
else
warn "$svc n'était pas activé"
fi
# Remove unit file
if [ -f "$SERVICE_DIR/$UNIT" ]; then
rm -f "$SERVICE_DIR/$UNIT"
ok "Fichier $UNIT supprimé"
else
warn "Fichier $UNIT non trouvé"
fi
echo ""
done
# Reload systemd
log "Rechargement de systemd..."
systemctl --user daemon-reload
ok "daemon-reload OK"
# Reset failed state
systemctl --user reset-failed 2>/dev/null || true
echo ""
log "═══════════════════════════════════════════════════════════"
log "🦊 Désinstallation terminée !"
log " Les services foxy-api et foxy-telegram ont été supprimés."
log " Le fichier .env et les données ne sont PAS supprimés."
log "═══════════════════════════════════════════════════════════"