Add handling for claiming non-standard install types with kickstart. (#12064)
* Add handling for claiming non-standard install types with kickstart. Also adds a check to verify that there is a usable claiming script before attempting to claim. * Fix handling for claiming native installs. * Make claim script search code more robust.
Austin S. Hemmelgarn committed
Apr 11, 2022 at 07:04 UTC
0fcf54e0c998d249b682f5dace6458cf64dc0842
1 file changed
+28
-3
packaging/installer/kickstart.sh
+28
-3
@@ -662,7 +662,7 @@ detect_existing_install() {
662
ndprefix="$(dirname "$(dirname "${ndpath}")")"
663
fi
664
665
- if echo "${ndprefix}" | grep -Eq '/usr$'; then
665
+ if echo "${ndprefix}" | grep -Eq '^/usr$'; then
666
ndprefix="$(dirname "${ndprefix}")"
667
fi
668
fi
@@ -784,7 +784,20 @@ handle_existing_install() {
784
fi
785
fi
786
else
787
- fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed." F0103
787
+ if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
788
+ progress "Attempting to claim existing install at ${ndprefix}."
789
+ INSTALL_PREFIX="${ndprefix}"
790
+ claim
791
+ ret=$?
792
+
793
+ cleanup
794
+ trap - EXIT
795
+ exit $ret
796
+ elif [ "${NETDATA_CLAIM_ONLY}" -eq 1 ]; then
797
+ fatal "User asked to claim, but did not proide a claiming token." F0202
798
+ else
799
+ fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed." F0103
800
+ fi
801
fi
802
;;
803
esac
@@ -890,14 +903,26 @@ claim() {
903
fi
904
905
progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}"
893
- if [ -z "${INSTALL_PREFIX}" ] || [ "${INSTALL_PREFIX}" = "/" ]; then
906
+ if command -v netdata-claim.sh > /dev/null 2>&1; then
907
+ NETDATA_CLAIM_PATH="$(command -v netdata-claim.sh)"
908
+ elif [ -z "${INSTALL_PREFIX}" ] || [ "${INSTALL_PREFIX}" = "/" ]; then
909
NETDATA_CLAIM_PATH=/usr/sbin/netdata-claim.sh
910
elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
911
NETDATA_CLAIM_PATH="/opt/netdata/bin/netdata-claim.sh"
912
+ elif [ ! -d "${INSTALL_PREFIX}/netdata" ]; then
913
+ if [ -d "${INSTALL_PREFIX}/usr" ]; then
914
+ NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/usr/sbin/netdata-claim.sh"
915
+ else
916
+ NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/sbin/netdata-claim.sh"
917
+ fi
918
else
919
NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdata-claim.sh"
920
fi
921
922
+ if [ ! -x "${NETDATA_CLAIM_PATH}" ]; then
923
+ fatal "Unable to find usable claiming script." F0106
924
+ fi
925
+
926
if ! is_netdata_running; then
927
NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running"
928
fi