@cryptotaxi247 / netdata-1 / commits / b1505b45f

Fixed numerous bugs in duplicate install handling. (#9769)

* Added an option to explicitly allow a reinstall over an existing install that would normally be updated. * Fixed the duplicate install handling code to run after the option parsing code. Previously it ran before it, and thus some cases did not work at all. * Added more robust handling of the case of attempting to do a duplicate install with a different install type than the original install.

Austin S. Hemmelgarn committed Aug 19, 2020 at 07:39 UTC b1505b45f87de267f7a374f5c4a2dee33056a5b8
4 files changed +131 -97
packaging/installer/kickstart-static64.sh
+60 -46
@@ -11,6 +11,7 @@
11 # --disable-telemetry Opt-out of anonymous telemetry program (DO_NOT_TRACK=1)
12 # --local-files Use a manually provided tarball for the installation
13 # --allow-duplicate-install do not bail if we detect a duplicate install
14 +# --reinstall if an existing install would be updated, reinstall instead
15 #
16 # Environment options:
17 #
@@ -180,52 +181,6 @@ sudo=""
181 [ -z "${UID}" ] && UID="$(id -u)"
182 [ "${UID}" -ne "0" ] && sudo="sudo"
183
183 -# ---------------------------------------------------------------------------------------------------------------------
184 -# look for an existing install and try to update that instead if it exists
185 -
186 -ndpath="$(command -v netdata 2>/dev/null)"
187 -if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then
188 - ndpath="/opt/netdata/bin/netdata"
189 -fi
190 -
191 -if [ -n "$ndpath" ] ; then
192 - ndprefix="$(dirname "$(dirname "${ndpath}")")"
193 -
194 - if [ "${ndprefix}" = /usr ] ; then
195 - ndprefix="/"
196 - fi
197 -
198 - progress "Found existing install of Netdata under: ${ndprefix}"
199 -
200 - if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then
201 - if [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then
202 - progress "Attempting to update existing install instead of creating a new one"
203 - if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" --not-running-from-cron ; then
204 - progress "Updated existing install at ${ndpath}"
205 - exit 0
206 - else
207 - fatal "Failed to update existing Netdata install"
208 - exit 1
209 - fi
210 - else
211 - if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
212 - fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
213 - exit 1
214 - else
215 - progress "User explicitly requested duplicate install, proceeding."
216 - fi
217 - fi
218 - else
219 - progress "Existing install appears to be handled manually or through the system package manager."
220 - if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
221 - fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
222 - exit 1
223 - else
224 - progress "User explicitly requested duplicate install, proceeding."
225 - fi
226 - fi
227 -fi
228 -
184 # ----------------------------------------------------------------------------
185 if [ "$(uname -m)" != "x86_64" ]; then
186 fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
@@ -278,6 +233,9 @@ while [ -n "${1}" ]; do
233 elif [ "${1}" = "--allow-duplicate-install" ]; then
234 NETDATA_ALLOW_DUPLICATE_INSTALL=1
235 shift 1
236 + elif [ "${1}" = "--reinstall" ]; then
237 + NETDATA_REINSTALL=1
238 + shift 1
239 else
240 echo >&2 "Unknown option '${1}' or invalid number of arguments. Please check the README for the available arguments of ${0} and try again"
241 exit 1
@@ -291,6 +249,62 @@ fi
249 # Netdata Tarball Base URL (defaults to our Google Storage Bucket)
250 [ -z "$NETDATA_TARBALL_BASEURL" ] && NETDATA_TARBALL_BASEURL=https://storage.googleapis.com/netdata-nightlies
251
252 +# ---------------------------------------------------------------------------------------------------------------------
253 +# look for an existing install and try to update that instead if it exists
254 +
255 +ndpath="$(command -v netdata 2>/dev/null)"
256 +if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then
257 + ndpath="/opt/netdata/bin/netdata"
258 +fi
259 +
260 +if [ -n "$ndpath" ] ; then
261 + ndprefix="$(dirname "$(dirname "${ndpath}")")"
262 +
263 + if [ "${ndprefix}" = /usr ] ; then
264 + ndprefix="/"
265 + fi
266 +
267 + progress "Found existing install of Netdata under: ${ndprefix}"
268 +
269 + if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then
270 + ndstatic="$(grep IS_NETDATA_STATIC_BINARY "${ndprefix}/etc/netdata/.environment" | cut -d "=" -f 2 | tr -d \")"
271 + if [ -z "${NETDATA_REINSTALL}" ] ; then
272 + if [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then
273 + progress "Attempting to update existing install instead of creating a new one"
274 + if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" --not-running-from-cron ; then
275 + progress "Updated existing install at ${ndpath}"
276 + exit 0
277 + else
278 + fatal "Failed to update existing Netdata install"
279 + exit 1
280 + fi
281 + else
282 + if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] || [ "${ndstatic}" = "no" ] ; then
283 + fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
284 + exit 1
285 + else
286 + progress "User explicitly requested duplicate install, proceeding."
287 + fi
288 + fi
289 + else
290 + if [ "${ndstatic}" = "yes" ] ; then
291 + progress "User requested reinstall instead of update, proceeding."
292 + else
293 + fatal "Existing install is not a static install, please use kickstart.sh instead."
294 + exit 1
295 + fi
296 + fi
297 + else
298 + progress "Existing install appears to be handled manually or through the system package manager."
299 + if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
300 + fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
301 + exit 1
302 + else
303 + progress "User explicitly requested duplicate install, proceeding."
304 + fi
305 + fi
306 +fi
307 +
308 # ----------------------------------------------------------------------------
309 TMPDIR=$(create_tmp_directory)
310 cd "${TMPDIR}" || exit 1
packaging/installer/kickstart.sh
+63 -47
@@ -15,6 +15,7 @@
15 # --no-updates do not install script for daily updates
16 # --local-files set the full path of the desired tarball to run install with
17 # --allow-duplicate-install do not bail if we detect a duplicate install
18 +# --reinstall if an existing install would be updated, reinstall instead
19 #
20 # Environment options:
21 #
@@ -279,53 +280,6 @@ sudo=""
280 export PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
281
282 # ---------------------------------------------------------------------------------------------------------------------
282 -# look for an existing install and try to update that instead if it exists
283 -
284 -ndpath="$(command -v netdata 2>/dev/null)"
285 -if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then
286 - ndpath="/opt/netdata/bin/netdata"
287 -fi
288 -
289 -if [ -n "$ndpath" ] ; then
290 - ndprefix="$(dirname "$(dirname "${ndpath}")")"
291 -
292 - if [ "${ndprefix}" = /usr ] ; then
293 - ndprefix="/"
294 - fi
295 -
296 - progress "Found existing install of Netdata under: ${ndprefix}"
297 -
298 - if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then
299 - if [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then
300 - progress "Attempting to update existing install instead of creating a new one"
301 - if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" --not-running-from-cron ; then
302 - progress "Updated existing install at ${ndpath}"
303 - exit 0
304 - else
305 - fatal "Failed to update existing Netdata install"
306 - exit 1
307 - fi
308 - else
309 - if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
310 - fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
311 - exit 1
312 - else
313 - progress "User explicitly requested duplicate install, proceeding."
314 - fi
315 - fi
316 - else
317 - progress "Existing install appears to be handled manually or through the system package manager."
318 - if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
319 - fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
320 - exit 1
321 - else
322 - progress "User explicitly requested duplicate install, proceeding."
323 - fi
324 - fi
325 -fi
326 -
327 -# ---------------------------------------------------------------------------------------------------------------------
328 -# install required system packages
283
284 INTERACTIVE=1
285 PACKAGES_INSTALLER_OPTIONS="netdata"
@@ -350,6 +304,9 @@ while [ -n "${1}" ]; do
304 elif [ "${1}" = "--allow-duplicate-install" ]; then
305 NETDATA_ALLOW_DUPLICATE_INSTALL=1
306 shift 1
307 + elif [ "${1}" = "--reinstall" ]; then
308 + NETDATA_REINSTALL=1
309 + shift 1
310 elif [ "${1}" = "--local-files" ]; then
311 shift 1
312 if [ -z "${1}" ]; then
@@ -396,6 +353,65 @@ if [ "${INTERACTIVE}" = "0" ]; then
353 NETDATA_INSTALLER_OPTIONS="$NETDATA_INSTALLER_OPTIONS --dont-wait"
354 fi
355
356 +# ---------------------------------------------------------------------------------------------------------------------
357 +# look for an existing install and try to update that instead if it exists
358 +
359 +ndpath="$(command -v netdata 2>/dev/null)"
360 +if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then
361 + ndpath="/opt/netdata/bin/netdata"
362 +fi
363 +
364 +if [ -n "$ndpath" ] ; then
365 + ndprefix="$(dirname "$(dirname "${ndpath}")")"
366 +
367 + if [ "${ndprefix}" = /usr ] ; then
368 + ndprefix="/"
369 + fi
370 +
371 + progress "Found existing install of Netdata under: ${ndprefix}"
372 +
373 + if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then
374 + ndstatic="$(grep IS_NETDATA_STATIC_BINARY "${ndprefix}/etc/netdata/.environment" | cut -d "=" -f 2 | tr -d \")"
375 + if [ -z "${NETDATA_REINSTALL}" ] ; then
376 + if [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then
377 + progress "Attempting to update existing install instead of creating a new one"
378 + if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" --not-running-from-cron ; then
379 + progress "Updated existing install at ${ndpath}"
380 + exit 0
381 + else
382 + fatal "Failed to update existing Netdata install"
383 + exit 1
384 + fi
385 + else
386 + if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] || [ "${ndstatic}" = "yes" ] ; then
387 + fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
388 + exit 1
389 + else
390 + progress "User explicitly requested duplicate install, proceeding."
391 + fi
392 + fi
393 + else
394 + if [ "${ndstatic}" = "no" ] ; then
395 + progress "User requested reinstall instead of update, proceeding."
396 + else
397 + fatal "Existing install is a static install, please use kickstart-static64.sh instead."
398 + exit 1
399 + fi
400 + fi
401 + else
402 + progress "Existing install appears to be handled manually or through the system package manager."
403 + if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
404 + fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
405 + exit 1
406 + else
407 + progress "User explicitly requested duplicate install, proceeding."
408 + fi
409 + fi
410 +fi
411 +
412 +# ---------------------------------------------------------------------------------------------------------------------
413 +# install required system packages
414 +
415 TMPDIR=$(create_tmp_directory)
416 cd "${TMPDIR}" || exit 1
417
packaging/installer/methods/kickstart-64.md
+4 -3
@@ -31,8 +31,7 @@ bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh)
31
32 The `kickstart.sh` script does the following after being downloaded and run:
33
34 -- Detects the Linux distribution and **installs the required system packages** for building Netdata. Unless you added
35 - the `--dont-wait` option, it will ask for your permission first.
34 +- Checks to see if there is an existing installation, and if there is updates that in preference to reinstalling.
35 - Downloads the latest Netdata binary from the [binary-packages](https://github.com/netdata/binary-packages)
36 repository. You can also run any of these `.run` files with [makeself](https://github.com/megastep/makeself).
37 - Installs Netdata by running `./netdata-installer.sh` from the source tree, including any options you might have
@@ -66,6 +65,8 @@ your installation. Here are a few important parameters:
65 - `--disable-telemetry`: Opt-out of [anonymous statistics](/docs/anonymous-statistics.md) we use to make
66 Netdata better.
67 - `--no-updates`: Prevent automatic updates of any kind.
68 +- `--reinstall`: If an existing installation is detected, reinstall instead of attempting to update it. Note
69 + that this cannot be used to switch betwen installation types.
70 - `--local-files`: Used for [offline installations](/packaging/installer/methods/offline.md). Pass four file paths:
71 the Netdata tarball, the checksum file, the go.d plugin tarball, and the go.d plugin config tarball, to force
72 kickstart run the process using those files. This option conflicts with the `--stable-channel` option. If you set
@@ -77,7 +78,7 @@ To use `md5sum` to verify the intregity of the `kickstart-static64.sh` script yo
78 command above, run the following:
79
80 ```bash
80 -[ "6c3c2957caeeeb1decaf6b6178a3a3cd" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
81 +[ "e06b4ecd791bc50c93d6c71839b53c41" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
82 ```
83
84 If the script is valid, this command will return `OK, VALID`.
packaging/installer/methods/kickstart.md
+4 -1
@@ -28,6 +28,7 @@ The `kickstart.sh` script does the following after being downloaded and run usin
28
29 - Detects the Linux distribution and **installs the required system packages** for building Netdata. Unless you added
30 the `--dont-wait` option, it will ask for your permission first.
31 +- Checks for an existing installation, and if found updates that instead of creating a new install.
32 - Downloads the latest Netdata source tree to `/usr/src/netdata.git`.
33 - Installs Netdata by running `./netdata-installer.sh` from the source tree, using any [optional
34 parameters](#optional-parameters-to-alter-your-installation) you have specified.
@@ -47,6 +48,8 @@ installation. Here are a few important parameters:
48 - `--disable-telemetry`: Opt-out of [anonymous statistics](/docs/anonymous-statistics.md) we use to make
49 Netdata better.
50 - `--no-updates`: Prevent automatic updates of any kind.
51 +- `--reinstall`: If an existing install is detected, reinstall instead of trying to update it. Note that this
52 + cannot be used to change installation types.
53 - `--local-files`: Used for [offline installations](offline.md). Pass four file paths: the Netdata
54 tarball, the checksum file, the go.d plugin tarball, and the go.d plugin config tarball, to force kickstart run the
55 process using those files. This option conflicts with the `--stable-channel` option. If you set this _and_
@@ -58,7 +61,7 @@ To use `md5sum` to verify the intregity of the `kickstart.sh` script you will do
61 run the following:
62
63 ```bash
61 -[ "86abaea95a24df12fe444c1b3e5cfa33" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
64 +[ "15420d0d5bd61fe4027c20d9276a696e" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
65 ```
66
67 If the script is valid, this command will return `OK, VALID`.