Skip to content

Commit

Permalink
Update elastic agent installation script (#161104)
Browse files Browse the repository at this point in the history
* require bash and curl
* support arm/aarch
* support macOS
* disable resuming elastic agent download
  • Loading branch information
graphaelli authored Jul 8, 2023
1 parent 7aa8d71 commit 7321249
Showing 1 changed file with 58 additions and 20 deletions.
78 changes: 58 additions & 20 deletions x-pack/plugins/observability_onboarding/public/assets/standalone_agent_setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
#!/bin/bash

set -u

fail() {
printf "%s\n" "$@" >&2
exit 1
}

# require bash
if [ -z "${BASH_VERSION:-}" ]; then
fail "bash required"
fi

if [ $# -lt 4 ]; then
fail "usage: $0 api_key api_endpoint agent_version onboarding_id [autoDownloadConfig=1]"
fi

API_KEY_ENCODED=$1
API_ENDPOINT=$2
ELASTIC_AGENT_VERSION=$3
ONBOARDING_ID=$4
AUTO_DOWNLOAD_CONFIG=$5
AUTO_DOWNLOAD_CONFIG=${5:-}

# require curl
[ $(builtin type -P curl) ] || fail "curl required"

# check OS
OS="$(uname)"
ARCH="$(uname -m)"
os=linux
arch=x86_64
if [ "${OS}" == "Linux" ]; then
if [ "${ARCH}" == "aarch64" ]; then
arch=arm64
fi
elif [ "${OS}" == "Darwin" ]; then
os=darwin
if [ "${ARCH}" == "arm64" ]; then
arch=aarch64
fi
else
fail "this script is only supported on linux and macOS"
fi

artifact=elastic-agent-${ELASTIC_AGENT_VERSION}-${os}-${arch}

# https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.8.2-darwin-x86_64.tar.gz
# https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.8.2-darwin-aarch64.tar.gz
# https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.8.2-linux-x86_64.tar.gz
# https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.8.2-linux-arm64.tar.gz

updateStepProgress() {
local STEPNAME="$1"
Expand All @@ -19,41 +63,40 @@ updateStepProgress() {
--no-progress-meter
}

echo "Downloading Elastic Agent archive"
ELASTIC_AGENT_DOWNLOAD_URL="https://artifacts.elastic.co/downloads/beats/elastic-agent/${artifact}.tar.gz"
echo "Downloading Elastic Agent archive from ${ELASTIC_AGENT_DOWNLOAD_URL}"
updateStepProgress "ea-download" "loading"
ELASTIC_AGENT_DOWNLOAD_URL="https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-${ELASTIC_AGENT_VERSION}-linux-x86_64.tar.gz"
curl -L -O $ELASTIC_AGENT_DOWNLOAD_URL --fail --continue-at -
curl -L -O $ELASTIC_AGENT_DOWNLOAD_URL --fail
if [ "$?" -eq 0 ]; then
echo "Downloaded Elastic Agent"
updateStepProgress "ea-download" "complete"
else
updateStepProgress "ea-download" "danger"
echo "Failed to download Elastic Agent"
exit 1
fail "Failed to download Elastic Agent"
fi

echo "Extracting Elastic Agent"
updateStepProgress "ea-extract" "loading"
tar -xzf elastic-agent-${ELASTIC_AGENT_VERSION}-linux-x86_64.tar.gz --checkpoint=.1000
tar -xzf ${artifact}.tar.gz
echo ""
if [ "$?" -eq 0 ]; then
echo "Elastic Agent extracted"
updateStepProgress "ea-extract" "complete"
else
updateStepProgress "ea-extract" "danger"
exit 1
fail "Failed to extract Elastic Agent"
fi

echo "Installing Elastic Agent"
updateStepProgress "ea-install" "loading"
cd elastic-agent-${ELASTIC_AGENT_VERSION}-linux-x86_64
cd ${artifact}
./elastic-agent install -f
if [ "$?" -eq 0 ]; then
echo "Elastic Agent installed"
updateStepProgress "ea-install" "complete"
else
updateStepProgress "ea-install" "danger"
exit 1
fail "Failed to install Elastic Agent"
fi

waitForElasticAgentStatus() {
Expand All @@ -76,7 +119,7 @@ waitForElasticAgentStatus() {
echo "Checking Elastic Agent status"
updateStepProgress "ea-status" "loading"
waitForElasticAgentStatus
if [[ "$?" -ne 0 ]]; then
if [ "$?" -ne 0 ]; then
updateStepProgress "ea-status" "warning"
exit 1
fi
Expand Down Expand Up @@ -107,18 +150,13 @@ downloadElasticAgentConfig() {
updateStepProgress "ea-config" "complete"
else
updateStepProgress "ea-config" "warning"
echo "Failed to download elastic-agent.yml"
exit 1
fail "Failed to download elastic-agent.yml"
fi

}

if [[ "${AUTO_DOWNLOAD_CONFIG}" == *"autoDownloadConfig=1"* ]]; then
if [ "${AUTO_DOWNLOAD_CONFIG}" == *"autoDownloadConfig=1"* ]; then
downloadElasticAgentConfig
echo "Done with standalone Elastic Agent setup for custom logs. Look for streaming logs to arrive in Kibana."
echo "Done with standalone Elastic Agent setup for custom logs. Look for streaming logs to arrive in Kibana"
else
echo "Done with standalone Elastic Agent setup for custom logs. Make sure to add your configuration to /opt/Elastic/Agent/elastic-agent.yml, then look for streaming logs to arrive in Kibana."
echo "Done with standalone Elastic Agent setup for custom logs. Make sure to add your configuration to /opt/Elastic/Agent/elastic-agent.yml, then look for streaming logs to arrive in Kibana"
fi

echo "Exit"
exit 0

0 comments on commit 7321249

Please sign in to comment.