#!/bin/bash # Agent Manager - Systemd Service Uninstallation Script # This script removes the agent-manager systemd service set -e # Exit on error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Print functions print_info() { echo -e "${GREEN}[INFO]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if running as root if [ "$EUID" -eq 0 ]; then print_error "Please do not run this script as root or with sudo" print_info "The script will prompt for sudo password when needed" exit 1 fi # Check if systemd is available if ! command -v systemctl &> /dev/null; then print_error "systemd is not available on this system" exit 1 fi # Check if service file exists if [ ! -f /etc/systemd/system/agent-manager.service ]; then print_warning "Service file not found: /etc/systemd/system/agent-manager.service" print_info "The service may not be installed, or it was already removed" exit 0 fi print_warning "This will remove the agent-manager systemd service" echo "The following actions will be performed:" echo " 1. Stop the agent-manager service" echo " 2. Disable the agent-manager service" echo " 3. Remove the service file from /etc/systemd/system/" echo " 4. Reload systemd daemon" echo "" print_info "Note: This will NOT remove:" echo " - The project directory and files" echo " - Configuration files (.env, commands.json)" echo " - Queue data (queue.json)" echo " - Log file (/var/log/agent-manager.log)" echo "" # Confirm uninstallation read -p "Do you want to proceed with the uninstallation? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then print_warning "Uninstallation cancelled" exit 0 fi # Check if service is running if sudo systemctl is-active --quiet agent-manager; then print_info "Stopping agent-manager service..." sudo systemctl stop agent-manager print_info "✓ Service stopped" else print_info "Service is not running" fi # Check if service is enabled if sudo systemctl is-enabled --quiet agent-manager 2>/dev/null; then print_info "Disabling agent-manager service..." sudo systemctl disable agent-manager print_info "✓ Service disabled" else print_info "Service is not enabled" fi # Remove the service file print_info "Removing service file..." sudo rm -f /etc/systemd/system/agent-manager.service print_info "✓ Service file removed" # Reload systemd print_info "Reloading systemd daemon..." sudo systemctl daemon-reload # Reset failed state if any sudo systemctl reset-failed agent-manager 2>/dev/null || true echo "" print_info "✓ Uninstallation complete!" echo "" print_info "The project files remain in place. If you want to remove them:" echo " - Configuration: .env, commands.json" echo " - Queue data: queue.json" echo " - Log file: /var/log/agent-manager.log (remove with: sudo rm /var/log/agent-manager.log)" echo " - Project directory: $PWD" echo "" print_info "To reinstall the service, run: ./install.sh"