uninstall.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/bin/bash
  2. # Agent Manager - Systemd Service Uninstallation Script
  3. # This script removes the agent-manager systemd service
  4. set -e # Exit on error
  5. # Colors for output
  6. RED='\033[0;31m'
  7. GREEN='\033[0;32m'
  8. YELLOW='\033[1;33m'
  9. NC='\033[0m' # No Color
  10. # Print functions
  11. print_info() {
  12. echo -e "${GREEN}[INFO]${NC} $1"
  13. }
  14. print_warning() {
  15. echo -e "${YELLOW}[WARNING]${NC} $1"
  16. }
  17. print_error() {
  18. echo -e "${RED}[ERROR]${NC} $1"
  19. }
  20. # Check if running as root
  21. if [ "$EUID" -eq 0 ]; then
  22. print_error "Please do not run this script as root or with sudo"
  23. print_info "The script will prompt for sudo password when needed"
  24. exit 1
  25. fi
  26. # Check if systemd is available
  27. if ! command -v systemctl &> /dev/null; then
  28. print_error "systemd is not available on this system"
  29. exit 1
  30. fi
  31. # Check if service file exists
  32. if [ ! -f /etc/systemd/system/agent-manager.service ]; then
  33. print_warning "Service file not found: /etc/systemd/system/agent-manager.service"
  34. print_info "The service may not be installed, or it was already removed"
  35. exit 0
  36. fi
  37. print_warning "This will remove the agent-manager systemd service"
  38. echo "The following actions will be performed:"
  39. echo " 1. Stop the agent-manager service"
  40. echo " 2. Disable the agent-manager service"
  41. echo " 3. Remove the service file from /etc/systemd/system/"
  42. echo " 4. Reload systemd daemon"
  43. echo ""
  44. print_info "Note: This will NOT remove:"
  45. echo " - The project directory and files"
  46. echo " - Configuration files (.env, commands.json)"
  47. echo " - Queue data (queue.json)"
  48. echo " - Log file (/var/log/agent-manager.log)"
  49. echo ""
  50. # Confirm uninstallation
  51. read -p "Do you want to proceed with the uninstallation? (y/N): " -n 1 -r
  52. echo
  53. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  54. print_warning "Uninstallation cancelled"
  55. exit 0
  56. fi
  57. # Check if service is running
  58. if sudo systemctl is-active --quiet agent-manager; then
  59. print_info "Stopping agent-manager service..."
  60. sudo systemctl stop agent-manager
  61. print_info "✓ Service stopped"
  62. else
  63. print_info "Service is not running"
  64. fi
  65. # Check if service is enabled
  66. if sudo systemctl is-enabled --quiet agent-manager 2>/dev/null; then
  67. print_info "Disabling agent-manager service..."
  68. sudo systemctl disable agent-manager
  69. print_info "✓ Service disabled"
  70. else
  71. print_info "Service is not enabled"
  72. fi
  73. # Remove the service file
  74. print_info "Removing service file..."
  75. sudo rm -f /etc/systemd/system/agent-manager.service
  76. print_info "✓ Service file removed"
  77. # Reload systemd
  78. print_info "Reloading systemd daemon..."
  79. sudo systemctl daemon-reload
  80. # Reset failed state if any
  81. sudo systemctl reset-failed agent-manager 2>/dev/null || true
  82. echo ""
  83. print_info "✓ Uninstallation complete!"
  84. echo ""
  85. print_info "The project files remain in place. If you want to remove them:"
  86. echo " - Configuration: .env, commands.json"
  87. echo " - Queue data: queue.json"
  88. echo " - Log file: /var/log/agent-manager.log (remove with: sudo rm /var/log/agent-manager.log)"
  89. echo " - Project directory: $PWD"
  90. echo ""
  91. print_info "To reinstall the service, run: ./install.sh"