Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions recipes/nrdot/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
# Visit our schema definition for additional information on this file format.
# https://github.com/newrelic/open-install-library/blob/main/docs/recipe-spec/recipe-spec.md#schema-definition

name: nrdot-collector
displayName: NRDOT Collector
description: New Relic install recipe for the NRDOT OpenTelemetry Collector (Debian/Ubuntu)
repository: https://github.com/newrelic/nrdot-collector-releases

installTargets:
- type: host
os: linux
platformFamily: debian
platformVersion: "(10|11|12)\\.*"
- type: host
os: linux
platform: ubuntu
platformVersion: "(18|20|22|24)\\.04"

keywords:
- NRDOT
- OpenTelemetry
- OTel
- Collector
- Linux
- Debian
- Ubuntu

processMatch: []

preInstall:
discoveryMode:
- targeted

inputVars:
# TODO: Add the envar to the cli
- name: NR_CLI_CONFIG_FILE_PATH
prompt: "Path to a custom OTel collector config YAML (leave blank to use default config)"
default: ""

install:
version: "3"
silent: true

vars:
IS_SYSTEMCTL:
sh: command -v systemctl | wc -l

tasks:
default:
cmds:
- task: assert_pre_req
- task: install_collector
- task: configure_env
- task: setup_custom_config
- task: start_collector
- task: assert_collector_status_ok

assert_pre_req:
cmds:
- |
if [ "$(id -u)" != "0" ]; then
echo "This newrelic install must be run under sudo or root" >&2
exit 3
fi
- |
if ! command -v curl > /dev/null 2>&1; then
echo "curl is required to run the newrelic install. Please install curl and re-run the installation." >&2
exit 16
fi
- |
if [ "{{.IS_SYSTEMCTL}}" -eq 0 ]; then
echo "systemd is required for the nrdot-collector service configuration." >&2
exit 131
fi

install_collector:
cmds:
- |
COLLECTOR_DISTRO="nrdot-collector"

# Fetch the latest release version from GitHub (tags have no 'v' prefix, e.g. 1.11.1)
COLLECTOR_VERSION=$(curl -s https://api.github.com/repos/newrelic/nrdot-collector-releases/releases/latest \
| grep '"tag_name"' \
| sed -E 's/.*"tag_name": "([^"]+)".*/\1/')

if [ -z "$COLLECTOR_VERSION" ]; then
echo "Failed to fetch the latest release version from GitHub. Please check your internet connection." >&2
exit 1
fi

# Check if already installed at the same version
if dpkg -l | grep -q "^ii.*nrdot-collector "; then
INSTALLED_VERSION=$(dpkg -l nrdot-collector | awk '/^ii/{print $3}' | sed 's/^[0-9]*://')
if [ "$INSTALLED_VERSION" = "$COLLECTOR_VERSION" ]; then
echo "nrdot-collector ${COLLECTOR_VERSION} is already installed. Skipping download."
exit 0
else
echo "Upgrading nrdot-collector from ${INSTALLED_VERSION} to ${COLLECTOR_VERSION}"
fi
else
echo "Installing ${COLLECTOR_DISTRO} version: ${COLLECTOR_VERSION}"
fi

ARCH="amd64"
IS_ARM=$(uname -m | grep -i 'aarch64' | wc -l)
if [ $IS_ARM -gt 0 ] ; then
ARCH="arm64"
fi

DOWNLOAD_URL="https://github.com/newrelic/nrdot-collector-releases/releases/download/${COLLECTOR_VERSION}/${COLLECTOR_DISTRO}_${COLLECTOR_VERSION}_linux_${ARCH}.deb"
echo "Downloading from: ${DOWNLOAD_URL}"

curl -L --output /tmp/nrdot-collector.deb "$DOWNLOAD_URL"
if [ $? -ne 0 ]; then
echo "Failed to download the nrdot-collector package." >&2
exit 1
fi

dpkg -i /tmp/nrdot-collector.deb
if [ $? -ne 0 ]; then
echo "dpkg install failed, attempting to fix broken dependencies..." >&2
apt-get install -f -y
if [ $? -ne 0 ]; then
echo "Failed to install the nrdot-collector package." >&2
exit 1
fi
fi

rm -f /tmp/nrdot-collector.deb
echo "${COLLECTOR_DISTRO} installed successfully."
silent: true

configure_env:
cmds:
- |
COLLECTOR_DISTRO="nrdot-collector"
CONFIG_DIR="/etc/${COLLECTOR_DISTRO}"
CONFIG_FILE="${CONFIG_DIR}/${COLLECTOR_DISTRO}.conf"

mkdir -p "$CONFIG_DIR"

# Write or update the license key
if grep -q "^NEW_RELIC_LICENSE_KEY=" "$CONFIG_FILE" 2>/dev/null; then
sed -i "s|^NEW_RELIC_LICENSE_KEY=.*|NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY}|" "$CONFIG_FILE"
else
echo "NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY}" | tee -a "$CONFIG_FILE" > /dev/null
fi

# Set OTLP endpoint based on region
if [ "${NEW_RELIC_REGION}" = "EU" ]; then
OTLP_ENDPOINT="https://otlp.eu01.nr-data.net"
elif [ "${NEW_RELIC_REGION}" = "staging" ]; then
OTLP_ENDPOINT="https://staging-otlp.nr-data.net"
else
OTLP_ENDPOINT="https://otlp.nr-data.net"
fi

if grep -q "^OTEL_EXPORTER_OTLP_ENDPOINT=" "$CONFIG_FILE" 2>/dev/null; then
sed -i "s|^OTEL_EXPORTER_OTLP_ENDPOINT=.*|OTEL_EXPORTER_OTLP_ENDPOINT=${OTLP_ENDPOINT}|" "$CONFIG_FILE"
else
echo "OTEL_EXPORTER_OTLP_ENDPOINT=${OTLP_ENDPOINT}" | tee -a "$CONFIG_FILE" > /dev/null
fi

chmod 600 "$CONFIG_FILE"
echo "Configuration written to ${CONFIG_FILE}"

setup_custom_config:
cmds:
- |
OVERRIDE_DIR="/etc/systemd/system/nrdot-collector.service.d"
OVERRIDE_FILE="${OVERRIDE_DIR}/override.conf"

# If no custom config provided, remove any previous override to restore default behavior
if [ -z "{{.NR_CLI_CONFIG_FILE_PATH}}" ]; then
if [ -f "$OVERRIDE_FILE" ]; then
echo "Removing previous custom config override, reverting to default config."
rm -f "$OVERRIDE_FILE"
else
echo "No custom config provided. Using default nrdot-collector config."
fi
exit 0
fi

# Validate the file exists and is readable
if [ ! -f "{{.NR_CLI_CONFIG_FILE_PATH}}" ]; then
echo "Custom config file not found: {{.NR_CLI_CONFIG_FILE_PATH}}" >&2
exit 9
fi

# Create systemd override directory
mkdir -p "$OVERRIDE_DIR"

# Write override — empty ExecStart= clears default, second sets custom config
printf '%s\n' \
'[Service]' \
'ExecStart=' \
'ExecStart=/usr/bin/nrdot-collector --config={{.NR_CLI_CONFIG_FILE_PATH}}' \
> "$OVERRIDE_FILE"

echo "Systemd override created: ${OVERRIDE_FILE}"

start_collector:
cmds:
- |
COLLECTOR_DISTRO="nrdot-collector"
systemctl daemon-reload
systemctl enable "${COLLECTOR_DISTRO}.service"
systemctl reload-or-restart "${COLLECTOR_DISTRO}.service"
echo "${COLLECTOR_DISTRO} service started and enabled."

assert_collector_status_ok:
cmds:
- |
COLLECTOR_DISTRO="nrdot-collector"
MAX_RETRIES=30
TRIES=0
echo "Waiting for ${COLLECTOR_DISTRO} to start..."
while [ $TRIES -lt $MAX_RETRIES ]; do
TRIES=$((TRIES + 1))
if systemctl is-active --quiet "${COLLECTOR_DISTRO}.service"; then
echo "${COLLECTOR_DISTRO} is running."
HEALTH=$(curl -s http://localhost:13133 2>/dev/null || echo "")
if echo "$HEALTH" | grep -q '"status":"Server available"'; then
echo "${COLLECTOR_DISTRO} health check passed."
exit 0
fi
fi
sleep 2
done

echo "${COLLECTOR_DISTRO} has not started after installation." >&2
if [ "{{.IS_SYSTEMCTL}}" -gt 0 ]; then
journalctl -u "${COLLECTOR_DISTRO}.service" --no-pager --lines=20
fi
exit 31

postInstall:
info: |2
Env config: /etc/nrdot-collector/nrdot-collector.conf
Default OTel cfg: /etc/nrdot-collector/config.yaml
Custom override: /etc/systemd/system/nrdot-collector.service.d/override.conf (if custom config used)
Service status: systemctl status nrdot-collector
Loading
Loading