Skip to content

Commit

Permalink
Move claiming into kickstart script instead of netdata-installer.
Browse files Browse the repository at this point in the history
This makes us more future-proof.

The required changes also fix some buggy behavior in the option parsing
code in the kickstart scripts.
  • Loading branch information
Ferroin committed Oct 28, 2020
1 parent 08beb2b commit 162efc1
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 150 deletions.
50 changes: 0 additions & 50 deletions netdata-installer.sh
Expand Up @@ -233,10 +233,6 @@ USAGE: ${PROGRAM} [options]
--libs-are-really-here If you get errors about missing zlib or libuuid but you know it is available, you might
have a broken pkg-config. Use this option to proceed without checking pkg-config.
--disable-telemetry Use this flag to opt-out from our anonymous telemetry progam. (DO_NOT_TRACK=1)
--claim-token Provide a Netdata Cloud claiming token to directly claim the agent during the install.
--claim-rooms Provide a list of Netdata Cloud rooms to claim the agent to during the install.
--claim-url Provide a Netdata Cloud instance URI to use for claiming during the install.
--claim-proxy Specify a proxy to use for claiming using the other claim options.
Netdata will by default be compiled with gcc optimization -O2
If you need to pass different CFLAGS, use something like this:
Expand Down Expand Up @@ -343,22 +339,6 @@ while [ -n "${1}" ]; do
REINSTALL_OPTIONS="${REINSTALL_OPTIONS} ${1} ${2}"
shift 1
;;
"--claim-token")
NETDATA_CLAIM_TOKEN="${2}"
shift 1
;;
"--claim-rooms")
NETDATA_CLAIM_ROOMS="${2}"
shift 1
;;
"--claim-url")
NETDATA_CLAIM_URL="${2}"
shift 1
;;
"--claim-proxy")
NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -proxy ${2}"
shift 1
;;
"--help" | "-h")
usage
exit 1
Expand All @@ -372,19 +352,6 @@ while [ -n "${1}" ]; do
shift 1
done

if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
if [ -n "${NETDATA_CLAIM_TOKEN}" ] || [ -n "${NETDATA_CLAIM_ROOMS}" ] || [ -n "${NETDATA_CLAIM_URL}" ]; then
run_failed "Cloud explicitly disabled but automatic claiming requested."
run_failed "Either enable Netdata Cloud, or remove the --claim-* options."
exit 1
fi
fi

if invalid_claim_args ${NETDATA_CLAIM_TOKEN} ${NETDATA_CLAIM_ROOMS} ${NETDATA_CLAIM_URL}; then
run_failed "Invalid claiming options, either all or none must be specified."
exit 1
fi

make="make"
# See: https://github.com/netdata/netdata/issues/9163
if [ "$(uname -s)" = "FreeBSD" ]; then
Expand Down Expand Up @@ -1844,23 +1811,6 @@ else
disable_netdata_updater || run_failed "Cannot disable netdata updater tool"
fi

# -----------------------------------------------------------------------------
if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}"
if [ -z "${NETDATA_PREFIX}" ] ; then
NETDATA_CLAIM_PATH=/usr/sbin/netdata-claim.sh
else
NETDATA_CLAIM_PATH="${NETDATA_PREFIX}/bin/netdata-claim.sh"
fi

if "${NETDATA_CLAIM_PATH}" -token=${NETDATA_CLAIM_TOKEN} -rooms=${NETDATA_CLAIM_ROOMS} -url=${NETDATA_CLAIM_URL} ${NETDATA_CLAIM_EXTRA}; then
progress "Successfully claimed node"
else
run_failed "Unable to claim node, you must do so manually."
defer_error "Unable to claim node, you must do so manually."
fi
fi

# -----------------------------------------------------------------------------
progress "Wrap up environment set up"

Expand Down
8 changes: 0 additions & 8 deletions packaging/installer/functions.sh
Expand Up @@ -1052,11 +1052,3 @@ disable_netdata_updater() {
set_netdata_updater_channel() {
sed -i -e "s/^RELEASE_CHANNEL=.*/RELEASE_CHANNEL=\"${RELEASE_CHANNEL}\"/" "${NETDATA_USER_CONFIG_DIR}/.environment"
}

invalid_claim_args() {
if [ $# -eq 3 ] || [ $# -eq 0 ]; then
return 1
else
return 0
fi
}
124 changes: 82 additions & 42 deletions packaging/installer/kickstart-static64.sh
Expand Up @@ -12,6 +12,10 @@
# --local-files Use a manually provided tarball for the installation
# --allow-duplicate-install do not bail if we detect a duplicate install
# --reinstall if an existing install would be updated, reinstall instead
# --claim-token specify a token to use for claiming the newly installed instance
# --claim-url specify a URL to use for claiming the newly installed isntance
# --claim-rooms specify a list of rooms to claim the newly installed instance to
# --claim-proxy specify a proxy to use while claiming the newly installed instance
#
# Environment options:
#
Expand Down Expand Up @@ -224,56 +228,78 @@ NETDATA_INSTALLER_OPTIONS=""
NETDATA_UPDATES="--auto-update"
RELEASE_CHANNEL="nightly"
while [ -n "${1}" ]; do
if [ "${1}" = "--dont-wait" ] || [ "${1}" = "--non-interactive" ] || [ "${1}" = "--accept" ]; then
opts="${opts} --accept"
shift 1
elif [ "${1}" = "--dont-start-it" ]; then
NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}"
shift 1
elif [ "${1}" = "--no-updates" ]; then
NETDATA_UPDATES=""
shift 1
elif [ "${1}" = "--auto-update" ]; then
true # This is the default behaviour, so ignore it.
shift 1
elif [ "${1}" = "--stable-channel" ]; then
RELEASE_CHANNEL="stable"
NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}"
shift 1
elif [ "${1}" = "--disable-telemetry" ]; then
NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}"
shift 1
elif [ "${1}" = "--local-files" ]; then
NETDATA_UPDATES="" # Disable autoupdates if using pre-downloaded files.
shift 1
if [ -z "${1}" ]; then
fatal "Option --local-files requires extra information. The desired tarball full filename is needed"
fi
case "${1}" in
"--dont-wait") opts="${opts} --accept" ;;
"--non-interactive") opts="${opts} --accept" ;;
"--accept") opts="${opts} --accept" ;;
"--dont-start-it") NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}" ;;
"--no-updates") NETDATA_UPDATES="" ;;
"--stable-channel")
RELEASE_CHANNEL="stable"
NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}"
;;
"--disable-telemetry") NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}";;
"--local-files")
NETDATA_UPDATES="" # Disable autoupdates if using pre-downloaded files.
if [ -z "${2}" ]; then
fatal "Option --local-files requires extra information. The desired tarball full filename is needed"
fi

NETDATA_LOCAL_TARBALL_OVERRIDE="${1}"
shift 1
if [ -z "${1}" ]; then
fatal "Option --local-files requires a pair of the tarball source and the checksum file"
fi
NETDATA_LOCAL_TARBALL_OVERRIDE="${2}"

NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM="${1}"
shift 1
elif [ "${1}" = "--allow-duplicate-install" ]; then
NETDATA_ALLOW_DUPLICATE_INSTALL=1
shift 1
elif [ "${1}" = "--reinstall" ]; then
NETDATA_REINSTALL=1
shift 1
else
echo >&2 "Unknown option '${1}' or invalid number of arguments. Please check the README for the available arguments of ${0} and try again"
exit 1
fi
if [ -z "${3}" ]; then
fatal "Option --local-files requires a pair of the tarball source and the checksum file"
fi

NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM="${3}"
shift 2
;;
"--allow-duplicate-install") NETDATA_ALLOW_DUPLICATE_INSTALL=1 ;;
"--reinstall") NETDATA_REINSTALL=1 ;;
"--claim-token")
NETDATA_CLAIM_TOKEN="${2}"
shift 1
;;
"--claim-rooms")
NETDATA_CLAIM_ROOMS="${2}"
shift 1
;;
"--claim-url")
NETDATA_CLAIM_URL="${2}"
shift 1
;;
"--claim-proxy")
NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -proxy ${2}"
shift 1
;;
*)
echo >&2 "Unknown option '${1}' or invalid number of arguments. Please check the README for the available arguments of ${0} and try again"
exit 1
esac
shift 1
done

if [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] || [ -n "$DO_NOT_TRACK" ]; then
NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }--disable-telemtry"
fi

if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
if [ -n "${NETDATA_CLAIM_TOKEN}" ] || [ -n "${NETDATA_CLAIM_ROOMS}" ] || [ -n "${NETDATA_CLAIM_URL}" ]; then
run_failed "Cloud explicitly disabled but automatic claiming requested."
run_failed "Either enable Netdata Cloud, or remove the --claim-* options."
exit 1
fi
fi

# shellcheck disable=SC2235
if ( [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_URL}" ] ) || ( [ -n "${NETDATA_CLAIM_TOKEN}" ] && [ -z "${NETDATA_CLAIM_URL}" ] ); then
run_failed "Invalid claiming options, both a claiming token and URL must be specified."
exit 1
elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then
run_failed "Invalid claiming options, claim rooms may only be specified when a token and URL are specified."
exit 1
fi

# Netdata Tarball Base URL (defaults to our Google Storage Bucket)
[ -z "$NETDATA_TARBALL_BASEURL" ] && NETDATA_TARBALL_BASEURL=https://storage.googleapis.com/netdata-nightlies

Expand Down Expand Up @@ -365,4 +391,18 @@ if [ $? -eq 0 ]; then
fi
else
echo >&2 "NOTE: did not remove: ${TMPDIR}/netdata-latest.gz.run"
exit 1
fi

# --------------------------------------------------------------------------------------------------------------------

if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}"
NETDATA_CLAIM_PATH=/opt/netdata/bin/netdata-claim.sh

if "${NETDATA_CLAIM_PATH}" -token=${NETDATA_CLAIM_TOKEN} -rooms=${NETDATA_CLAIM_ROOMS} -url=${NETDATA_CLAIM_URL} ${NETDATA_CLAIM_EXTRA}; then
progress "Successfully claimed node"
else
run_failed "Unable to claim node, you must do so manually."
fi
fi

0 comments on commit 162efc1

Please sign in to comment.