summaryrefslogtreecommitdiffstats
path: root/claim
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2021-03-08 08:12:22 -0500
committerGitHub <noreply@github.com>2021-03-08 08:12:22 -0500
commit0a47bbdd6f44bf56e309c96d718467ef931a0b4f (patch)
tree74d04e60f24f79aa4684546d71e0832119f93407 /claim
parent790af9620f400471d274339db4ec7dd7a9f18982 (diff)
Added support for claiming nodes as part of installation. (#10084)
* Added support for claiming nodes as part of installation. This adds four new options to the `netdata-installer.sh` script: * `--claim-token` * `--claim-rooms` * `--claim-uri` * `--claim-proxy` These directly correspond to the `-token`, `-rooms`, `-uri`, and `-proxy` options for the `netdata-claim.sh` script. They have the following associated logic: * If any are specified and the `--disable-cloud` option is also specified, we bail and tell the user to either enable the cloud or remove the claiming options. * If only some but not all of the token, rooms, and uri options are specified, we bail and tell the user that they must pass all three. * If all three of the token, rooms, and uri are specified, we invoke the `netdata-claim.sh` script for the install itself as one of the last steps in the installation process, using the values passed to these options. This allows users to directly claim the agent as part of the install, which is useful for automated installation scenarios. * Add missing space as suggested by @knatsakis * Properly handle installs in /. * Properly handle unprefixed installs. * Fix another spelling error in an option name. * Properly fix option naming. * Move claiming into kickstart script instead of netdata-installer. This makes us more future-proof. The required changes also fix some buggy behavior in the option parsing code in the kickstart scripts. * Fix checksums. * Sanely handle the daemon not running during the claiming process. * Silence incorrect shellcheck warning. * Simplify condition as suggested by @vkalintiris. * Clean up old changes that should not be here anymore. These are leftovers from an earlier revision, they are not actually needed. * Add ID generation logic to the claiming script. This lets it reliably claim nodes which have not yet had the daemon run. Also fixes a consistency issue in the claiming logic in the Docker entrypoint.
Diffstat (limited to 'claim')
-rwxr-xr-xclaim/netdata-claim.sh.in42
1 files changed, 35 insertions, 7 deletions
diff --git a/claim/netdata-claim.sh.in b/claim/netdata-claim.sh.in
index 7ac91d7fb5..c8364c1eff 100755
--- a/claim/netdata-claim.sh.in
+++ b/claim/netdata-claim.sh.in
@@ -85,15 +85,22 @@ ERROR_MESSAGES[17]="Service Unavailable"
# Exit code: 18 - Agent unique id is not generated yet.
+NETDATA_RUNNING=1
+
get_config_value() {
conf_file="${1}"
section="${2}"
key_name="${3}"
- config_result=$(@sbindir_POST@/netdatacli 2>/dev/null read-config "$conf_file|$section|$key_name"; exit $?)
- # shellcheck disable=SC2181
- if [ "$?" != "0" ]; then
- echo >&2 "cli failed, assume netdata is not running and query the on-disk config"
- config_result=$(@sbindir_POST@/netdata 2>/dev/null -W get2 "$conf_file" "$section" "$key_name" unknown_default)
+ if [ "${NETDATA_RUNNING}" -eq 1 ]; then
+ config_result=$(@sbindir_POST@/netdatacli 2>/dev/null read-config "$conf_file|$section|$key_name"; exit $?)
+ result="$?"
+ if [ "${result}" -ne 0 ]; then
+ echo >&2 "Unable to communicate with Netdata daemon, querying config from disk instead."
+ NETDATA_RUNNING=0
+ fi
+ fi
+ if [ "${NETDATA_RUNNING}" -eq 0 ]; then
+ config_result=$(@sbindir_POST@/netdata 2>/dev/null -W get2 "$conf_file" "$section" "$key_name" unknown_default)
fi
echo "$config_result"
}
@@ -141,13 +148,33 @@ NETDATA_USER=$(get_config_value netdata global "run as user")
[ -z "$EUID" ] && EUID="$(id -u)"
+gen_id() {
+ local id
+
+ id="$(uuidgen)"
+
+ if [ "${id}" = "8a795b0c-2311-11e6-8563-000c295076a6" ] || [ "${id}" = "4aed1458-1c3e-11e6-a53f-000c290fc8f5" ]; then
+ gen_id
+ else
+ echo "${id}"
+ fi
+}
+
# get the MACHINE_GUID by default
if [ -r "${MACHINE_GUID_FILE}" ]; then
ID="$(cat "${MACHINE_GUID_FILE}")"
MGUID=$ID
-else
- echo >&2 "netdata.public.unique.id is not generated yet or not readable. Please run agent at least once before attempting to claim. Agent generates this file on first startup. If the ID is generated already make sure you have rights to read it (Filename: ${MACHINE_GUID_FILE})."
+elif [ -f "${MACHINE_GUID_FILE}" ]; then
+ echo >&2 "netdata.public.unique.id is not readable. Please make sure you have rights to read it (Filename: ${MACHINE_GUID_FILE})."
exit 18
+else
+ if mkdir -p "${MACHINE_GUID_FILE%/*}" && /bin/echo -n "$(gen_id)" > "${MACHINE_GUID_FILE}"; then
+ ID="$(cat "${MACHINE_GUID_FILE}")"
+ MGUID=$ID
+ else
+ echo >&2 "Failed to write new machine GUID. Please make sure you have rights to write to ${MACHINE_GUID_FILE}."
+ exit 18
+ fi
fi
# get token from file
@@ -174,6 +201,7 @@ do
-noproxy) NOPROXY=yes ;;
-noreload) RELOAD=0 ;;
-user=*) NETDATA_USER=${arg:6} ;;
+ -daemon-not-running) NETDATA_RUNNING=0 ;;
*) echo >&2 "Unknown argument ${arg}"
exit 1 ;;
esac