Skip to content

Commit e30c6af

Browse files
committed
upgrade(fleet): Use installer install script to install APM SSI
1 parent 1183bab commit e30c6af

File tree

1 file changed

+38
-110
lines changed

1 file changed

+38
-110
lines changed

install_script.sh.template

Lines changed: 38 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -507,30 +507,6 @@ END
507507
echo "$telemetry_trace" | $sudo_cmd tee /tmp/datadog-installer-trace.json > /dev/null
508508
}
509509

510-
function _install_installer() {
511-
local sudo_cmd="$1"
512-
local os="$2"
513-
local distribution="$3"
514-
515-
local command_prefix
516-
517-
if [ "$os" == "Debian" ]; then
518-
echo -e "\033[34m\n* Installing the Datadog installer\n\033[0m"
519-
$sudo_cmd apt-get install -o Acquire::Retries="5" -y --force-yes "datadog-installer" || return $?
520-
elif [ "$os" == "Red Hat" ]; then
521-
echo -e "\033[34m\n* Installing the Datadog installer\n\033[0m"
522-
$sudo_cmd yum -y --disablerepo='*' --enablerepo='datadog' install "datadog-installer" || $sudo_cmd yum -y install "datadog-installer" || return $?
523-
elif [ "$os" == "SUSE" ]; then
524-
echo -e "\033[34m\n* Installing the Datadog installer\n\033[0m"
525-
$sudo_cmd zypper --non-interactive --no-refresh install "datadog-installer" || return $?
526-
else
527-
return 0
528-
fi
529-
command_prefix="${sudo_cmd:+$sudo_cmd -E}"
530-
$command_prefix sh -c "DD_API_KEY=\"${apikey}\" DD_SITE=\"${site}\" DATADOG_TRACE_ID=\"${DATADOG_TRACE_ID}\" DATADOG_PARENT_ID=\"${DATADOG_TRACE_ID}\" /usr/bin/datadog-bootstrap bootstrap"
531-
return $?
532-
}
533-
534510
function is_installed_by_installer() {
535511
local sudo_cmd="$1"
536512
local package="$2"
@@ -568,39 +544,6 @@ function filter_packages_installed_by_installer() {
568544
eval "$pkg_array_name=(\"\${not_installed_packages[@]}\")"
569545
}
570546

571-
# Install the Datadog installer package
572-
function install_installer() {
573-
local sudo_cmd="$1"
574-
local os="$2"
575-
local distribution="$3"
576-
local datadog_installer="$4"
577-
local remote_updates="$5"
578-
local apm_instrumentation_enabled="$6"
579-
local pkg_array_name="$7"
580-
581-
local trace_id
582-
local start_time
583-
local exit_status
584-
585-
# The installer is currently only being rolled out to APM instrumentation users
586-
if [ -z "$apm_instrumentation_enabled" ] && [ -z "$datadog_installer" ] && [ -z "$remote_updates" ]; then
587-
return 0
588-
fi
589-
590-
start_time=$(date +%s%N)
591-
592-
(_install_installer "$sudo_cmd" "$os" "$distribution" > /tmp/datadog-installer-stdout.log 2> /tmp/datadog-installer-stderr.log) || exit_status=$?
593-
exit_status=${exit_status:-0}
594-
595-
filter_packages_installed_by_installer "$sudo_cmd" "$pkg_array_name"
596-
597-
if [ "$exit_status" -ne 0 ] && { [ -n "$datadog_installer" ] || [ -n "$remote_updates" ]; } then
598-
echo -e "\033[31m\n* Failed to install the Datadog installer\n\033[0m"
599-
exit "$exit_status"
600-
fi
601-
return "$exit_status"
602-
}
603-
604547
function remove_existing_packages_for_fips_flavor() {
605548
local sudo_cmd="$1"
606549
local os="$2"
@@ -640,37 +583,58 @@ function remove_existing_packages_for_fips_flavor() {
640583
return "$exit_status"
641584
}
642585

643-
# install_managed_agent installs the agent with Fleet Automation's agent management (preview feature).
644-
function install_managed_agent() {
645-
echo "Installing the Datadog Agent with Remote Agent Management"
646-
installer_domain=${DD_INSTALLER_REGISTRY_URL_INSTALLER_PACKAGE:-$([[ "$DD_SITE" == "datad0g.com" ]] && echo "install.datad0g.com" || echo "install.datadoghq.com")}
647-
installer_url="https://${installer_domain}/scripts/install.sh"
648-
if [ -n "$DD_AGENT_MINOR_VERSION" ]; then
649-
installer_url="https://${installer_domain}/scripts/install-7.${DD_AGENT_MINOR_VERSION}.sh"
650-
fi
586+
function _install_installer_script() {
587+
local installer_url="$1"
588+
651589
if command -v curl >/dev/null; then
652590
http_code=$(curl -ILsf --retry 3 -w "%{http_code}" -o /dev/null "$installer_url" || true)
653591
if [ "$http_code" -ne "200" ]; then
654592
echo "Error: Unable to download the installer script from $installer_url. HTTP status code: $http_code"
655-
exit 1
593+
return 1
656594
fi
657595
if ! bash <(curl -L -s -f --retry 3 "$installer_url"); then
658-
exit 1
596+
return 1
659597
fi
660598
elif command -v wget >/dev/null; then
661599
http_code=$(wget -q --tries=3 --server-response --spider --tries=3 "$installer_url" 2>&1 | awk '/^ HTTP/{print $2}' | tail -n1 | tr -d '\n')
662600
if [ "$http_code" -ne 200 ]; then
663601
echo "Error: Unable to download the installer script from $installer_url. HTTP status code: $http_code"
664-
exit 1
602+
return 1
665603
fi
666604
if ! bash <(wget -q --tries=3 -O - "$installer_url"); then
667-
exit 1
605+
return 1
668606
fi
669607
else
670608
echo "Error: Curl or wget is required to install the agent with Remote Agent Management."
671-
exit 1
609+
return 1
672610
fi
673-
exit 0
611+
return 0
612+
}
613+
614+
# install_managed_agent installs the agent with Fleet Automation's agent management (preview feature).
615+
function install_managed_agent() {
616+
echo "Installing the Datadog Agent with Remote Agent Management"
617+
installer_domain=${DD_INSTALLER_REGISTRY_URL_INSTALLER_PACKAGE:-$([[ "$DD_SITE" == "datad0g.com" ]] && echo "install.datad0g.com" || echo "install.datadoghq.com")}
618+
installer_url="https://${installer_domain}/scripts/install.sh"
619+
if [ -n "$DD_AGENT_MINOR_VERSION" ]; then
620+
installer_url="https://${installer_domain}/scripts/install-7.${DD_AGENT_MINOR_VERSION}.sh"
621+
fi
622+
623+
_install_installer_script "$installer_url"
624+
exit $?
625+
}
626+
627+
# install_apm_ssi installs APM Single Step Instrumentation.
628+
function install_apm_ssi() {
629+
local sudo_cmd="$1"
630+
local pkg_array_name="$2"
631+
632+
installer_domain=${DD_INSTALLER_REGISTRY_URL_INSTALLER_PACKAGE:-$([[ "$DD_SITE" == "datad0g.com" ]] && echo "install.datad0g.com" || echo "install.datadoghq.com")}
633+
installer_url="https://${installer_domain}/scripts/install-ssi.sh" # TODO: support pinning?
634+
635+
_install_installer_script "$installer_url"
636+
637+
filter_packages_installed_by_installer "$sudo_cmd" "$pkg_array_name"
674638
}
675639

676640
##
@@ -762,22 +726,6 @@ if [ -n "$DD_AGENT_FLAVOR" ]; then
762726
agent_flavor=$DD_AGENT_FLAVOR #Eg: datadog-iot-agent
763727
fi
764728

765-
datadog_installer=
766-
if [ -n "$DD_INSTALLER" ]; then
767-
datadog_installer=true
768-
fi
769-
770-
771-
installer_registry_url=
772-
if [ -n "$DD_INSTALLER_REGISTRY_URL" ]; then
773-
installer_registry_url=$DD_INSTALLER_REGISTRY_URL
774-
fi
775-
776-
installer_registry_auth=
777-
if [ -n "$DD_INSTALLER_REGISTRY_AUTH" ]; then
778-
installer_registry_auth=$DD_INSTALLER_REGISTRY_AUTH
779-
fi
780-
781729
##
782730
# INSTALL SCRIPT CONFIGURATION OPTIONS
783731
# Technical options to test with non-production values for signature keys, packages or reporting telemetry.
@@ -869,10 +817,6 @@ if [ -n "$fips_mode" ]; then
869817
services+=("datadog-fips-proxy")
870818
fi
871819

872-
if [ -n "$remote_updates" ]; then
873-
services+=("datadog-installer")
874-
fi
875-
876820
# Track running services to avoid stopping them if they were already running
877821
if [[ $($sudo_cmd ps --no-headers -o comm 1 2>&1) == "systemd" ]] && command -v systemctl 2>&1; then
878822
# Check with services are already running
@@ -1175,7 +1119,7 @@ if [ "$OS" == "Red Hat" ]; then
11751119

11761120
# Install the installer
11771121
# Note: this function will remove installed packages from the "packages" array
1178-
install_installer "$sudo_cmd" "$OS" "$DISTRIBUTION" "$DD_INSTALLER" "$DD_REMOTE_UPDATES" "$DD_APM_INSTRUMENTATION_ENABLED" "packages" || true
1122+
install_apm_ssi "$sudo_cmd" "packages" || true
11791123

11801124
if [ "$agent_flavor" == "datadog-fips-agent" ]; then
11811125
remove_existing_packages_for_fips_flavor "$sudo_cmd" "$OS"
@@ -1322,7 +1266,7 @@ If the cause is unclear, please contact Datadog support.
13221266

13231267
# Install the installer
13241268
# Note: this function will remove installed packages from the "packages" array
1325-
install_installer "$sudo_cmd" "$OS" "$DISTRIBUTION" "$DD_INSTALLER" "$DD_REMOTE_UPDATES" "$DD_APM_INSTRUMENTATION_ENABLED" "packages" || true
1269+
install_apm_ssi "$sudo_cmd" "packages" || true
13261270

13271271
if [ "$agent_flavor" == "datadog-fips-agent" ]; then
13281272
remove_existing_packages_for_fips_flavor "$sudo_cmd" "$OS"
@@ -1476,7 +1420,7 @@ elif [ "$OS" == "SUSE" ]; then
14761420

14771421
# Install the installer
14781422
# Note: this function will remove installed packages from the "packages" array
1479-
install_installer "$sudo_cmd" "$OS" "$DISTRIBUTION" "$DD_INSTALLER" "$DD_REMOTE_UPDATES" "$DD_APM_INSTRUMENTATION_ENABLED" "packages" || true
1423+
install_apm_ssi "$sudo_cmd" "packages" || true
14801424

14811425
if [ "$agent_flavor" == "datadog-fips-agent" ]; then
14821426
remove_existing_packages_for_fips_flavor "$sudo_cmd" "$OS"
@@ -1617,20 +1561,6 @@ function update_env(){
16171561
$sudo_cmd sh -c "sed -i 's|^# env:.*|env: $dd_env|' $config_file"
16181562
fi
16191563
}
1620-
function update_installer_registry(){
1621-
local sudo_cmd="$1"
1622-
local registry_url="$2"
1623-
local registry_auth="$3"
1624-
local config_file="$4"
1625-
if [ -n "$registry_url" ] || [ -n "$registry_auth" ]; then
1626-
printf "\033[34m\n* Adding your DD_INSTALLER_REGISTRY_URL and DD_INSTALLER_REGISTRY_AUTH to the $nice_flavor configuration: $config_file\n\033[0m\n"
1627-
if ! $sudo_cmd grep -q "^installer:" "$config_file"; then
1628-
$sudo_cmd sh -c "echo 'installer: {registry: {url: \"$registry_url\", auth: \"$registry_auth\" }}' >> $config_file"
1629-
else
1630-
printf "\033[31mInstaller configuration already exists in $config_file, skipping the update.\033[0m\n"
1631-
fi
1632-
fi
1633-
}
16341564
function update_security_and_or_compliance(){
16351565
local sudo_cmd="$1"
16361566
local local_config_file="$2"
@@ -1768,8 +1698,6 @@ if [ -e "$(dirname $dd_environment_file)" ]; then
17681698
fi
17691699
manage_error_tracking_standalone_config "$sudo_cmd" "$environment_file"
17701700

1771-
update_installer_registry "$sudo_cmd" "$installer_registry_url" "$installer_registry_auth" "$config_file"
1772-
17731701
if [ ! "$no_agent" ]; then
17741702
$sudo_cmd chown dd-agent:dd-agent "$config_file"
17751703
$sudo_cmd chmod 640 "$config_file"

0 commit comments

Comments
 (0)