#!/usr/bin/env bash set -euo pipefail INSTALL_DIR="/opt/openflare-agent" SERVICE_NAME="openflare-agent" usage() { cat </dev/null 2>&1; then SYSTEMCTL_AVAILABLE="true" fi echo "Uninstalling OpenFlare Agent from ${INSTALL_DIR}..." if [[ "$SYSTEMCTL_AVAILABLE" == "true" ]]; then if systemctl is-active --quiet "$SERVICE_NAME"; then echo "Stopping service: ${SERVICE_NAME}" systemctl stop "$SERVICE_NAME" fi if systemctl is-enabled --quiet "$SERVICE_NAME" >/dev/null 2>&1; then echo "Disabling service: ${SERVICE_NAME}" systemctl disable "$SERVICE_NAME" >/dev/null 2>&1 || true fi fi if command -v pgrep >/dev/null 2>&1; then mapfile -t agent_pids < <(pgrep -f "$AGENT_BINARY" || true) if (( ${#agent_pids[@]} > 0 )); then echo "Stopping agent process: ${agent_pids[*]}" kill "${agent_pids[@]}" || true sleep 1 mapfile -t remaining_agent_pids < <(pgrep -f "$AGENT_BINARY" || true) if (( ${#remaining_agent_pids[@]} > 0 )); then echo "Force stopping remaining agent process: ${remaining_agent_pids[*]}" kill -9 "${remaining_agent_pids[@]}" || true fi fi fi if [[ -f "$SERVICE_FILE" ]]; then echo "Removing service file: ${SERVICE_FILE}" rm -f "$SERVICE_FILE" fi if [[ "$SYSTEMCTL_AVAILABLE" == "true" ]]; then systemctl daemon-reload || true systemctl reset-failed "$SERVICE_NAME" >/dev/null 2>&1 || true fi if [[ -d "$INSTALL_DIR" ]]; then echo "Removing installation directory: ${INSTALL_DIR}" rm -rf "$INSTALL_DIR" else echo "Installation directory not found, skipping: ${INSTALL_DIR}" fi echo "Agent uninstall complete." echo "" echo "Local OpenResty was not modified. Remove it manually if you no longer need it." echo "OpenFlare Agent uninstall finished."