mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
[新增] Agent 架构调整, 采用集成镜像方式
This commit is contained in:
@@ -14,6 +14,7 @@ DISCOVERY_TOKEN=""
|
||||
AGENT_TOKEN=""
|
||||
CREATE_SERVICE="true"
|
||||
SERVICE_NAME="openflare-agent"
|
||||
OPENRESTY_PATH=""
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
@@ -27,6 +28,7 @@ Options:
|
||||
--discovery-token TOKEN Discovery token for auto-registration
|
||||
--agent-token TOKEN Node-specific agent token
|
||||
--install-dir DIR Installation directory (default: /opt/openflare-agent)
|
||||
--openresty-path PATH OpenResty binary path (default: auto-detect from PATH)
|
||||
--repo REPO GitHub repository (default: Rain-kl/OpenFlare)
|
||||
--no-service Do not create systemd service
|
||||
-h, --help Show this help message
|
||||
@@ -51,6 +53,7 @@ while [[ $# -gt 0 ]]; do
|
||||
--discovery-token) DISCOVERY_TOKEN="$2"; shift 2 ;;
|
||||
--agent-token) AGENT_TOKEN="$2"; shift 2 ;;
|
||||
--install-dir) INSTALL_DIR="$2"; shift 2 ;;
|
||||
--openresty-path) OPENRESTY_PATH="$2"; shift 2 ;;
|
||||
--repo) REPO="$2"; shift 2 ;;
|
||||
--no-service) CREATE_SERVICE="false"; shift ;;
|
||||
-h|--help) usage ;;
|
||||
@@ -82,6 +85,20 @@ if [[ "$OS" != "linux" && "$OS" != "darwin" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$OPENRESTY_PATH" ]]; then
|
||||
if command -v openresty >/dev/null 2>&1; then
|
||||
OPENRESTY_PATH="$(command -v openresty)"
|
||||
else
|
||||
echo "Error: openresty was not found in PATH. Install OpenResty first or pass --openresty-path."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -x "$OPENRESTY_PATH" ]]; then
|
||||
echo "Error: OpenResty binary is not executable: ${OPENRESTY_PATH}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ASSET_NAME="openflare-agent-${OS}-${ARCH}"
|
||||
echo "Detected platform: ${OS}/${ARCH}"
|
||||
|
||||
@@ -140,9 +157,9 @@ if [[ -n "$AGENT_TOKEN" ]]; then
|
||||
{
|
||||
"server_url": "${SERVER_URL}",
|
||||
"agent_token": "${AGENT_TOKEN}",
|
||||
"openresty_path": "${OPENRESTY_PATH}",
|
||||
"data_dir": "${INSTALL_DIR}/data",
|
||||
"heartbeat_interval": 30000,
|
||||
"sync_interval": 30000,
|
||||
"request_timeout": 10000
|
||||
}
|
||||
CFGEOF
|
||||
@@ -151,9 +168,9 @@ else
|
||||
{
|
||||
"server_url": "${SERVER_URL}",
|
||||
"discovery_token": "${DISCOVERY_TOKEN}",
|
||||
"openresty_path": "${OPENRESTY_PATH}",
|
||||
"data_dir": "${INSTALL_DIR}/data",
|
||||
"heartbeat_interval": 30000,
|
||||
"sync_interval": 30000,
|
||||
"request_timeout": 10000
|
||||
}
|
||||
CFGEOF
|
||||
@@ -197,3 +214,4 @@ echo "OpenFlare Agent installed successfully!"
|
||||
echo " Binary: ${INSTALL_DIR}/openflare-agent"
|
||||
echo " Config: ${CONFIG_FILE}"
|
||||
echo " Data: ${INSTALL_DIR}/data"
|
||||
echo " OpenResty: ${OPENRESTY_PATH}"
|
||||
|
||||
@@ -19,9 +19,7 @@ Options:
|
||||
Behavior:
|
||||
1. Stop the agent service/process and remove the entire installation directory
|
||||
2. Remove the systemd service definition when present
|
||||
3. Check the saved agent config to identify the OpenResty mode
|
||||
4. If Docker mode was used, remove the OpenResty container and try to remove its image
|
||||
5. If local openresty_path mode was used, do not modify the local OpenResty install
|
||||
3. Leave the local OpenResty installation untouched
|
||||
|
||||
Examples:
|
||||
uninstall-agent.sh
|
||||
@@ -44,52 +42,9 @@ if [[ -z "$INSTALL_DIR" || "$INSTALL_DIR" == "/" || "$INSTALL_DIR" == "." ]]; th
|
||||
exit 1
|
||||
fi
|
||||
|
||||
json_get_string() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
local match
|
||||
|
||||
match=$(grep -o "\"${key}\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" "$file" 2>/dev/null | head -n 1 || true)
|
||||
if [[ -z "$match" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
printf '%s\n' "$match" | sed -E 's/.*:[[:space:]]*"([^"]*)"/\1/'
|
||||
}
|
||||
|
||||
AGENT_BINARY="${INSTALL_DIR}/openflare-agent"
|
||||
CONFIG_FILE="${INSTALL_DIR}/agent.json"
|
||||
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
|
||||
|
||||
OPENRESTY_PATH=""
|
||||
OPENRESTY_CONTAINER_NAME="openflare-openresty"
|
||||
OPENRESTY_DOCKER_IMAGE="openresty/openresty:alpine"
|
||||
DOCKER_BINARY="docker"
|
||||
OPENRESTY_MODE="unknown"
|
||||
|
||||
if [[ -f "$CONFIG_FILE" ]]; then
|
||||
OPENRESTY_PATH="$(json_get_string "$CONFIG_FILE" "openresty_path")"
|
||||
OPENRESTY_CONTAINER_NAME="$(json_get_string "$CONFIG_FILE" "openresty_container_name")"
|
||||
OPENRESTY_DOCKER_IMAGE="$(json_get_string "$CONFIG_FILE" "openresty_docker_image")"
|
||||
DOCKER_BINARY="$(json_get_string "$CONFIG_FILE" "docker_binary")"
|
||||
|
||||
if [[ -z "$OPENRESTY_CONTAINER_NAME" ]]; then
|
||||
OPENRESTY_CONTAINER_NAME="openflare-openresty"
|
||||
fi
|
||||
if [[ -z "$OPENRESTY_DOCKER_IMAGE" ]]; then
|
||||
OPENRESTY_DOCKER_IMAGE="openresty/openresty:alpine"
|
||||
fi
|
||||
if [[ -z "$DOCKER_BINARY" ]]; then
|
||||
DOCKER_BINARY="docker"
|
||||
fi
|
||||
|
||||
if [[ -n "$OPENRESTY_PATH" ]]; then
|
||||
OPENRESTY_MODE="local"
|
||||
else
|
||||
OPENRESTY_MODE="docker"
|
||||
fi
|
||||
fi
|
||||
|
||||
SYSTEMCTL_AVAILABLE="false"
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
SYSTEMCTL_AVAILABLE="true"
|
||||
@@ -143,50 +98,5 @@ fi
|
||||
|
||||
echo "Agent uninstall complete."
|
||||
echo ""
|
||||
echo "Checking OpenResty installation mode..."
|
||||
|
||||
if [[ "$OPENRESTY_MODE" == "docker" ]]; then
|
||||
echo "Detected Docker OpenResty mode."
|
||||
|
||||
if ! command -v "$DOCKER_BINARY" >/dev/null 2>&1; then
|
||||
echo "Docker binary '${DOCKER_BINARY}' was not found."
|
||||
echo "Please remove container '${OPENRESTY_CONTAINER_NAME}' and image '${OPENRESTY_DOCKER_IMAGE}' manually."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if "$DOCKER_BINARY" inspect "$OPENRESTY_CONTAINER_NAME" >/dev/null 2>&1; then
|
||||
if [[ -z "$OPENRESTY_DOCKER_IMAGE" ]]; then
|
||||
OPENRESTY_DOCKER_IMAGE="$("$DOCKER_BINARY" inspect -f '{{.Config.Image}}' "$OPENRESTY_CONTAINER_NAME" 2>/dev/null || true)"
|
||||
fi
|
||||
|
||||
echo "Removing Docker container: ${OPENRESTY_CONTAINER_NAME}"
|
||||
"$DOCKER_BINARY" rm -f "$OPENRESTY_CONTAINER_NAME"
|
||||
else
|
||||
echo "Docker container not found, skipping: ${OPENRESTY_CONTAINER_NAME}"
|
||||
fi
|
||||
|
||||
if [[ -n "$OPENRESTY_DOCKER_IMAGE" ]] && "$DOCKER_BINARY" image inspect "$OPENRESTY_DOCKER_IMAGE" >/dev/null 2>&1; then
|
||||
other_container_ids="$("$DOCKER_BINARY" ps -a --filter "ancestor=${OPENRESTY_DOCKER_IMAGE}" --format '{{.ID}}' 2>/dev/null || true)"
|
||||
if [[ -z "$other_container_ids" ]]; then
|
||||
echo "Removing Docker image: ${OPENRESTY_DOCKER_IMAGE}"
|
||||
if ! "$DOCKER_BINARY" image rm "$OPENRESTY_DOCKER_IMAGE"; then
|
||||
echo "Image removal skipped because Docker reported it is still in use."
|
||||
fi
|
||||
else
|
||||
echo "Docker image is still used by other containers, skipping image removal: ${OPENRESTY_DOCKER_IMAGE}"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Docker OpenResty cleanup complete."
|
||||
elif [[ "$OPENRESTY_MODE" == "local" ]]; then
|
||||
echo "Detected local OpenResty mode via openresty_path:"
|
||||
echo " ${OPENRESTY_PATH}"
|
||||
echo "Agent has been removed, but the local OpenResty installation was not modified."
|
||||
echo "Please uninstall the local OpenResty manually if you no longer need it."
|
||||
else
|
||||
echo "OpenResty mode could not be determined because ${CONFIG_FILE} was not found before uninstall."
|
||||
echo "If you were using Docker OpenResty, please remove its container and image manually if needed."
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Local OpenResty was not modified. Remove it manually if you no longer need it."
|
||||
echo "OpenFlare Agent uninstall finished."
|
||||
|
||||
Reference in New Issue
Block a user