master
sh 1,253 lines 47.1 KB
Raw
1 #!/bin/sh
2
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # Next unused error code: I0012
6
7 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
8 uniquepath() {
9 path=""
10 tmp="$(mktemp)"
11 (echo "${PATH}" | tr ":" "\n") > "$tmp"
12 while read -r REPLY;
13 do
14 if echo "${path}" | grep -v "(^|:)${REPLY}(:|$)"; then
15 [ -n "${path}" ] && path="${path}:"
16 path="${path}${REPLY}"
17 fi
18 done < "$tmp"
19 rm "$tmp"
20 [ -n "${path}" ]
21 export PATH="${path%:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin}"
22 } > /dev/null
23 uniquepath
24
25 PROGRAM="$0"
26 NETDATA_SOURCE_DIR="$(pwd)"
27 INSTALLER_DIR="$(dirname "${PROGRAM}")"
28
29 if [ "${NETDATA_SOURCE_DIR}" != "${INSTALLER_DIR}" ] && [ "${INSTALLER_DIR}" != "." ]; then
30 echo >&2 "Warning: you are currently in '${NETDATA_SOURCE_DIR}' but the installer is in '${INSTALLER_DIR}'."
31 fi
32
33 # -----------------------------------------------------------------------------
34 # reload the user profile
35
36 # shellcheck source=/dev/null
37 [ -f /etc/profile ] && . /etc/profile
38
39 # make sure /etc/profile does not change our current directory
40 cd "${NETDATA_SOURCE_DIR}" || exit 1
41
42 # -----------------------------------------------------------------------------
43 # load the required functions
44
45 if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
46 # shellcheck source=packaging/installer/functions.sh
47 . "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
48 else
49 # shellcheck source=packaging/installer/functions.sh
50 . "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
51 fi
52
53 # Used to enable saved warnings support in functions.sh
54 # shellcheck disable=SC2034
55 NETDATA_SAVE_WARNINGS=1
56
57 # -----------------------------------------------------------------------------
58 # figure out an appropriate temporary directory
59 _cannot_use_tmpdir() {
60 testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
61 ret=0
62
63 if [ -z "${testfile}" ]; then
64 return "${ret}"
65 fi
66
67 if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then
68 if chmod +x "${testfile}"; then
69 if [ "$("${testfile}")" = "SUCCESS" ]; then
70 ret=1
71 fi
72 fi
73 fi
74
75 rm -f "${testfile}"
76 return "${ret}"
77 }
78
79 if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
80 if _cannot_use_tmpdir /tmp; then
81 if _cannot_use_tmpdir "${PWD}"; then
82 fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." I0000
83 else
84 TMPDIR="${PWD}"
85 fi
86 else
87 TMPDIR="/tmp"
88 fi
89 fi
90
91 # -----------------------------------------------------------------------------
92 # set up handling for deferred error messages
93 #
94 # This leverages the saved warnings functionality shared with some functions from functions.sh
95
96 print_deferred_errors() {
97 if [ -n "${SAVED_WARNINGS}" ]; then
98 printf >&2 "\n"
99 printf >&2 "%b\n" "The following warnings and non-fatal errors were encountered during the installation process:"
100 printf >&2 "%b\n" "${SAVED_WARNINGS}"
101 printf >&2 "\n"
102 fi
103 }
104
105 # make sure we save all commands we run
106 # Variable is used by code in the packaging/installer/functions.sh
107 # shellcheck disable=SC2034
108 run_logfile="netdata-installer.log"
109
110
111 # -----------------------------------------------------------------------------
112 # fix PKG_CHECK_MODULES error
113
114 if [ -d /usr/share/aclocal ]; then
115 ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
116 export ACLOCAL_PATH
117 fi
118
119 export LC_ALL=C
120 umask 002
121
122 # Be nice on production environments
123 renice 19 $$ > /dev/null 2> /dev/null
124
125 # you can set CFLAGS before running installer
126 # shellcheck disable=SC2269
127 LDFLAGS="${LDFLAGS}"
128 CFLAGS="${CFLAGS-"-O2 -pipe"}"
129 [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
130 # shellcheck disable=SC2269
131 ACLK="${ACLK}"
132
133 # keep a log of this command
134 {
135 printf "\n# "
136 date
137 printf 'CFLAGS="%s" ' "${CFLAGS}"
138 printf 'LDFLAGS="%s" ' "${LDFLAGS}"
139 printf "%s" "${PROGRAM}" "${@}"
140 printf "\n"
141 } >> netdata-installer.log
142
143 REINSTALL_OPTIONS="$(
144 printf "%s" "${*}"
145 printf "\n"
146 )"
147 # remove options that shown not be inherited by netdata-updater.sh
148 REINSTALL_OPTIONS="$(echo "${REINSTALL_OPTIONS}" | sed 's/--dont-wait//g' | sed 's/--dont-start-it//g')"
149
150 banner_nonroot_install() {
151 cat << NONROOTNOPREFIX
152
153 ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
154
155 You are attempting to install netdata as a non-root user, but you plan
156 to install it in system paths.
157
158 Please set an installation prefix, like this:
159
160 $PROGRAM ${@} --install-prefix /tmp
161
162 or, run the installer as root:
163
164 sudo $PROGRAM ${@}
165
166 We suggest to install it as root, or certain data collectors will
167 not be able to work. Netdata drops root privileges when running.
168 So, if you plan to keep it, install it as root to get the full
169 functionality.
170
171 NONROOTNOPREFIX
172 }
173
174 banner_root_notify() {
175 cat << NONROOT
176
177 ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
178 You are about to install netdata as a non-root user.
179 Netdata will work, but a few data collection modules that
180 require root access will fail.
181
182 If you are installing netdata permanently on your system, run
183 the installer like this:
184
185 ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
186
187 NONROOT
188 }
189
190 usage() {
191 netdata_banner
192 progress "installer command line options"
193 cat << HEREDOC
194 USAGE: ${PROGRAM} [options]
195 where options include:
196
197 --install-prefix <path> Install netdata in <path>. Ex. --install-prefix /opt will put netdata in /opt/netdata.
198 --windows-path-prefix <path> Override NETDATA_WINDOWS_PATH_PREFIX for the CMake build.
199 --dont-start-it Do not (re)start netdata after installation.
200 --dont-wait Run installation in non-interactive mode.
201 --stable-channel Use packages from GitHub release pages instead of nightly updates.
202 This results in less frequent updates.
203 --nightly-channel Use most recent nightly updates instead of GitHub releases.
204 This results in more frequent updates.
205 --disable-ebpf Disable eBPF Kernel plugin. Default: enabled.
206 --force-legacy-cxx Force usage of an older C++ standard to allow building on older systems. This will usually be autodetected.
207 --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
208 --disable-plugin-freeipmi Explicitly disable the FreeIPMI plugin.
209 --disable-dbengine Explicitly disable DB engine support.
210 --enable-plugin-go Enable the Go plugin. Default: Enabled when possible.
211 --disable-plugin-go Disable the Go plugin.
212 --disable-go Disable all Go components.
213 --enable-plugin-nfacct Enable nfacct plugin. Default: enable it when libmnl and libnetfilter_acct are available.
214 --disable-plugin-nfacct Explicitly disable the nfacct plugin.
215 --enable-plugin-xenstat Enable the xenstat plugin. Default: enable it when libxenstat and libyajl are available.
216 --disable-plugin-xenstat Explicitly disable the xenstat plugin.
217 --enable-plugin-systemd-journal Enable the systemd journal plugin. Default: enable it when libsystemd is available.
218 --disable-plugin-systemd-journal Explicitly disable the systemd journal plugin.
219 --internal-systemd-journal Enable the internal journal file reader instead of using libsystemd
220 --enable-plugin-otel Enable the Netdata OpenTelemetry plugin. Default: disabled
221 --disable-plugin-otel Explicitly disable the Netdata OpenTelemetry plugin.
222 --enable-plugin-otel-signal-viewer Enable the OTel signal viewer plugin. Default: disabled
223 --disable-plugin-otel-signal-viewer Explicitly disable the OTel signal viewer plugin.
224 --enable-plugin-netflow Enable the NetFlow/IPFIX/sFlow flow analysis plugin. Default: disabled.
225 --disable-plugin-netflow Explicitly disable the NetFlow/IPFIX/sFlow flow analysis plugin.
226 --enable-plugin-ibm Enable the IBM ecosystem monitoring plugin. Default: disabled
227 --disable-plugin-ibm Explicitly disable the IBM ecosystem monitoring plugin.
228 --enable-exporting-kinesis Enable AWS Kinesis exporting connector. Default: enable it when libaws_cpp_sdk_kinesis
229 and its dependencies are available.
230 --disable-exporting-kinesis Explicitly disable AWS Kinesis exporting connector.
231 --enable-exporting-prometheus-remote-write Enable Prometheus remote write exporting connector. Default: enable it
232 when libprotobuf and libsnappy are available.
233 --disable-exporting-prometheus-remote-write Explicitly disable Prometheus remote write exporting connector.
234 --enable-exporting-mongodb Enable MongoDB exporting connector. Default: enable it when libmongoc is available.
235 --disable-exporting-mongodb Explicitly disable MongoDB exporting connector.
236 --enable-exporting-pubsub Enable Google Cloud PubSub exporting connector. Default: enable it when
237 libgoogle_cloud_cpp_pubsub_protos and its dependencies are available.
238 --disable-exporting-pubsub Explicitly disable Google Cloud PubSub exporting connector.
239 --enable-lto Enable link-time optimization. Default: disabled.
240 --disable-lto Explicitly disable link-time optimization.
241 --enable-ml Enable anomaly detection with machine learning. Default: autodetect.
242 --disable-ml Explicitly disable anomaly detection with machine learning.
243 --disable-x86-sse Disable SSE instructions & optimizations. Default: enabled.
244 --use-system-protobuf Use a system copy of libprotobuf instead of bundled copy. Default: bundled.
245 --zlib-is-really-here
246 --libs-are-really-here If you see errors about missing zlib or libuuid but you know it is available, you might
247 have a broken pkg-config. Use this option to proceed without checking pkg-config.
248 --disable-telemetry Opt-out from our anonymous telemetry program. (DISABLE_TELEMETRY=1)
249 --skip-available-ram-check Skip checking the amount of RAM the system has and pretend it has enough to build safely.
250 --dev Do not remove the build directory - speeds up rebuilds
251 HEREDOC
252 }
253
254 if [ "$(uname -s)" = "Linux" ]; then
255 case "$(uname -m)" in
256 x86_64|i?86) ENABLE_EBPF=1 ;;
257 esac
258 fi
259
260 DONOTSTART=0
261 DONOTWAIT=0
262 NETDATA_PREFIX=
263 NETDATA_WINDOWS_PATH_PREFIX=
264 LIBS_ARE_HERE=0
265 NETDATA_ENABLE_ML=""
266 ENABLE_DBENGINE=1
267 ENABLE_GO=1
268 ENABLE_PYTHON=1
269 ENABLE_CHARTS=1
270 ENABLE_NETFLOW=0
271 ENABLE_OTEL=0
272 ENABLE_OTEL_SIGNAL_VIEWER=0
273 ENABLE_IBM=0
274 ENABLE_SCRIPTS=0
275 FORCE_LEGACY_CXX=0
276 NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS-}"
277 REMOVE_BUILD=1
278
279 RELEASE_CHANNEL="nightly" # valid values are 'nightly' and 'stable'
280 IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY:-"no"}"
281 while [ -n "${1}" ]; do
282 case "${1}" in
283 "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
284 "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
285 "--use-system-protobuf") USE_SYSTEM_PROTOBUF=1 ;;
286 "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
287 "--dont-start-it") DONOTSTART=1 ;;
288 "--dont-wait") DONOTWAIT=1 ;;
289 "--auto-update" | "-u") ;;
290 "--auto-update-type") ;;
291 "--stable-channel") RELEASE_CHANNEL="stable" ;;
292 "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
293 "--force-legacy-cxx") FORCE_LEGACY_CXX=1 ;;
294 "--enable-plugin-freeipmi") ENABLE_FREEIPMI=1 ;;
295 "--disable-plugin-freeipmi") ENABLE_FREEIPMI=0 ;;
296 "--disable-https")
297 warning "HTTPS cannot be disabled."
298 ;;
299 "--disable-dbengine") ENABLE_DBENGINE=0 ;;
300 "--enable-plugin-go") ENABLE_GO=1 ;;
301 "--disable-plugin-go") ENABLE_GO=0 ;;
302 "--disable-go") ENABLE_GO=0 ;;
303 "--enable-plugin-python") ENABLE_PYTHON=1 ;;
304 "--disable-plugin-python") ENABLE_PYTHON=0 ;;
305 "--enable-plugin-charts") ENABLE_CHARTS=1 ;;
306 "--disable-plugin-charts") ENABLE_CHARTS=0 ;;
307 "--enable-plugin-nfacct") ENABLE_NFACCT=1 ;;
308 "--disable-plugin-nfacct") ENABLE_NFACCT=0 ;;
309 "--enable-plugin-xenstat") ENABLE_XENSTAT=1 ;;
310 "--disable-plugin-xenstat") ENABLE_XENSTAT=0 ;;
311 "--enable-plugin-netflow") ENABLE_NETFLOW=1 ;;
312 "--disable-plugin-netflow") ENABLE_NETFLOW=0 ;;
313 "--enable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=1 ;;
314 "--disable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=0 ;;
315 "--internal-systemd-journal") USE_RUST_JOURNAL_FILE=1 ;;
316 "--enable-plugin-otel") ENABLE_OTEL=1 ;;
317 "--disable-plugin-otel") ENABLE_OTEL=0 ;;
318 "--enable-plugin-otel-signal-viewer") ENABLE_OTEL_SIGNAL_VIEWER=1 ;;
319 "--disable-plugin-otel-signal-viewer") ENABLE_OTEL_SIGNAL_VIEWER=0 ;;
320 "--enable-plugin-ibm") ENABLE_IBM=1 ;;
321 "--disable-plugin-ibm") ENABLE_IBM=0 ;;
322 "--enable-plugin-scripts") ENABLE_SCRIPTS=1 ;;
323 "--disable-plugin-scripts") ENABLE_SCRIPTS=0 ;;
324 "--enable-exporting-kinesis" | "--enable-backend-kinesis")
325 # TODO: Needs CMake Support
326 ;;
327 "--disable-exporting-kinesis" | "--disable-backend-kinesis")
328 # TODO: Needs CMake Support
329 ;;
330 "--enable-exporting-prometheus-remote-write" | "--enable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=1 ;;
331 "--disable-exporting-prometheus-remote-write" | "--disable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=0 ;;
332 "--enable-exporting-mongodb" | "--enable-backend-mongodb") EXPORTER_MONGODB=1 ;;
333 "--disable-exporting-mongodb" | "--disable-backend-mongodb") EXPORTER_MONGODB=0 ;;
334 "--enable-exporting-pubsub")
335 # TODO: Needs CMake support
336 ;;
337 "--disable-exporting-pubsub")
338 # TODO: Needs CMake support
339 ;;
340 "--enable-ml") NETDATA_ENABLE_ML=1 ;;
341 "--disable-ml") NETDATA_ENABLE_ML=0 ;;
342 "--enable-lto") NETDATA_ENABLE_LTO=1 ;;
343 "--disable-lto") NETDATA_ENABLE_LTO=0 ;;
344 "--disable-x86-sse")
345 # XXX: No longer supported.
346 ;;
347 "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
348 "--enable-ebpf") ENABLE_EBPF=1 ;;
349 "--disable-ebpf") ENABLE_EBPF=0 ;;
350 "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
351 "--one-time-build")
352 # XXX: No longer supported
353 ;;
354 "--disable-cloud")
355 warning "Cloud cannot be disabled."
356 ;;
357 "--require-cloud") ;;
358 "--build-json-c")
359 NETDATA_BUILD_JSON_C=1
360 ;;
361 "--install-prefix")
362 NETDATA_PREFIX="${2}/netdata"
363 shift 1
364 ;;
365 "--windows-path-prefix")
366 NETDATA_WINDOWS_PATH_PREFIX="${2}"
367 shift 1
368 ;;
369 "--install-no-prefix")
370 NETDATA_PREFIX="${2}"
371 shift 1
372 ;;
373 "--prepare-only")
374 NETDATA_DISABLE_TELEMETRY=1
375 NETDATA_PREPARE_ONLY=1
376 DONOTWAIT=1
377 ;;
378 "--dev")
379 REMOVE_BUILD=0
380 ;;
381 "--help" | "-h")
382 usage
383 exit 1
384 ;;
385 *)
386 echo >&2 "Unrecognized option '${1}'."
387 exit_reason "Unrecognized option '${1}'." I000E
388 usage
389 exit 1
390 ;;
391 esac
392 shift 1
393 done
394
395 if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
396 [ -n "$DISABLE_TELEMETRY" ] ||
397 [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
398 [ -n "$DO_NOT_TRACK" ]; then
399 NETDATA_DISABLE_TELEMETRY=1
400 fi
401
402 if [ -n "${MAKEOPTS}" ]; then
403 JOBS="$(echo "${MAKEOPTS}" | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
404 else
405 JOBS="$(find_processors)"
406 fi
407
408 if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
409 mega="$((1024 * 1024))"
410 base=1024
411 scale=256
412
413 target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
414 total_ram="$(grep MemTotal /proc/meminfo | cut -d ':' -f 2 | tr -d ' kB')"
415 total_ram="$((total_ram * 1024))"
416
417 if [ "${total_ram}" -le "$((base * mega))" ] && [ -z "${NETDATA_ENABLE_ML}" ]; then
418 NETDATA_ENABLE_ML=0
419 fi
420
421 if [ -z "${MAKEOPTS}" ]; then
422 MAKEOPTS="-j${JOBS}"
423
424 while [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ]; do
425 JOBS="$((JOBS - 1))"
426 target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
427 MAKEOPTS="-j${JOBS}"
428 done
429 else
430 if [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
431 target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
432 total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
433 run_failed "Netdata needs ${target_ram} of RAM to safely install, but this system only has ${total_ram}. Try reducing the number of processes used for the install using the \$MAKEOPTS variable."
434 exit_reason "Insufficient RAM to safely install." I000F
435 exit 2
436 fi
437 fi
438 fi
439
440 # set default make options
441 if [ -z "${MAKEOPTS}" ]; then
442 MAKEOPTS="-j$(find_processors)"
443 elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
444 MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
445 fi
446
447 if [ "$(id -u)" -ne 0 ] && [ -z "${NETDATA_PREPARE_ONLY}" ]; then
448 if [ -z "${NETDATA_PREFIX}" ]; then
449 netdata_banner
450 banner_nonroot_install "${@}"
451 exit_reason "Attempted install as non-root user to /." I0010
452 exit 1
453 else
454 banner_root_notify "${@}"
455 fi
456 fi
457
458 netdata_banner
459 progress "Netdata, X-Ray Vision for your infrastructure!"
460 cat << BANNER1
461
462 You are about to build and install netdata to your system.
463
464 The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
465 any temporary files. You can override this by setting \$TMPDIR to a
466 writable directory where you can execute files.
467
468 It will be installed at these locations:
469
470 - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
471 - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
472 - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
473 - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
474 - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
475 - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
476 - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
477 BANNER1
478
479 [ "$(id -u)" -eq 0 ] && cat << BANNER2
480 - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
481 - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
482 BANNER2
483
484 cat << BANNER3
485
486 This installer allows you to change the installation path.
487 Press Control-C and run the same command with --help for help.
488
489 BANNER3
490
491 if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
492 cat << BANNER4
493
494 ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
495 Anonymous usage stats will be collected and sent to Netdata.
496 To opt-out, pass --disable-telemetry option to the installer or export
497 the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
498 (e.g: export DISABLE_TELEMETRY=1).
499
500 BANNER4
501 fi
502
503 if ! command -v cmake >/dev/null 2>&1; then
504 fatal "Could not find CMake, which is required to build Netdata." I0012
505 else
506 cmake="$(command -v cmake)"
507 progress "Found CMake at ${cmake}. CMake version: $(${cmake} --version | head -n 1)"
508 fi
509
510 if ! command -v "ninja" >/dev/null 2>&1; then
511 progress "Could not find Ninja, will use Make instead."
512 else
513 ninja="$(command -v ninja)"
514 progress "Found Ninja at ${ninja}. Ninja version: $(${ninja} --version)"
515 progress "Will use Ninja for this build instead of Make when possible."
516 fi
517
518 make="$(command -v make 2>/dev/null)"
519
520 if [ -z "${make}" ] && [ -z "${ninja}" ]; then
521 fatal "Could not find a usable underlying build system (we support make and ninja)." I0014
522 fi
523
524 CMAKE_OPTS="${ninja:+-G Ninja}"
525 BUILD_OPTS="VERBOSE=1"
526 [ -n "${ninja}" ] && BUILD_OPTS="-k 1"
527
528 if [ ${DONOTWAIT} -eq 0 ]; then
529 if [ -n "${NETDATA_PREFIX}" ]; then
530 printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
531 else
532 printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
533 fi
534 read -r REPLY
535 if [ "$REPLY" != '' ]; then
536 exit_reason "User did not accept install attempt." I0011
537 exit 1
538 fi
539
540 fi
541
542 cmake_install() {
543 # run cmake --install ${1}
544 # The above command should be used to replace the logic below once we no longer support
545 # versions of CMake less than 3.15.
546 if [ -n "${ninja}" ]; then
547 run ${ninja} -C "${1}" install
548 else
549 run ${make} -C "${1}" install
550 fi
551 }
552
553 build_error() {
554 netdata_banner
555 trap - EXIT
556 fatal "Netdata failed to build for an unknown reason." I0002
557 }
558
559 if [ ${LIBS_ARE_HERE} -eq 1 ]; then
560 shift
561 echo >&2 "ok, assuming libs are really installed."
562 export ZLIB_CFLAGS=" "
563 export ZLIB_LIBS="-lz"
564 export UUID_CFLAGS=" "
565 export UUID_LIBS="-luuid"
566 fi
567
568 trap build_error EXIT
569
570 # -----------------------------------------------------------------------------
571 # If we’re building any Go-based component, ensure a working Go toolchain exists.
572 NEED_GO_TOOLCHAIN=0
573 if [ "${ENABLE_GO}" -eq 1 ] || [ "${ENABLE_IBM}" -eq 1 ] || [ "${ENABLE_SCRIPTS}" -eq 1 ]; then
574 NEED_GO_TOOLCHAIN=1
575 fi
576
577 if [ "${NEED_GO_TOOLCHAIN}" -eq 1 ]; then
578 progress "Checking for a usable Go toolchain and attempting to install one to /usr/local/go if needed."
579 . "${NETDATA_SOURCE_DIR}/packaging/check-for-go-toolchain.sh"
580
581 if ! ensure_go_toolchain; then
582 warning "Go ${GOLANG_MIN_VERSION} needed to build Go-based plugins (go.d, scripts.d, IBM), but could not find or install a usable toolchain: ${GOLANG_FAILURE_REASON}. Disabling those components."
583 ENABLE_GO=0
584 ENABLE_IBM=0
585 ENABLE_SCRIPTS=0
586 fi
587 fi
588
589 # -----------------------------------------------------------------------------
590 # If we're installing the IBM plugin, ensure CGO is available
591 if [ "${ENABLE_IBM}" -eq 1 ]; then
592 if [ "${ENABLE_GO}" -eq 0 ]; then
593 warning "IBM plugin requires Go plugin to be enabled. Disabling IBM plugin."
594 ENABLE_IBM=0
595 else
596 # Check for a C compiler for CGO
597 if ! command -v gcc >/dev/null 2>&1 && ! command -v clang >/dev/null 2>&1; then
598 warning "IBM plugin requires a C compiler (gcc or clang) for CGO. Disabling IBM plugin."
599 ENABLE_IBM=0
600 fi
601 fi
602 fi
603
604 # -----------------------------------------------------------------------------
605 # If we have the dashboard switching logic, make sure we're on the classic
606 # dashboard during the install (updates don't work correctly otherwise).
607 if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
608 "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
609 fi
610
611 # -----------------------------------------------------------------------------
612 # By default, `git` does not update local tags based on remotes. Because
613 # we use the most recent tag as part of our version determination in
614 # our build, this can lead to strange versions that look ancient but are
615 # actually really recent. To avoid this, try and fetch tags if we're
616 # working in a git checkout.
617 if [ -d ./.git ] ; then
618 echo >&2
619 progress "Updating tags in git to ensure a consistent version number"
620 run git fetch -t || true
621 fi
622
623 # -----------------------------------------------------------------------------
624
625 echo >&2
626
627 [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
628 NETDATA_BUILD_DIR="${NETDATA_BUILD_DIR:-./build/}"
629 [ ${REMOVE_BUILD} -eq 1 ] && rm -rf "${NETDATA_BUILD_DIR}"
630
631 # function to extract values from the config file
632 config_option() {
633 section="${1}"
634 key="${2}"
635 value="${3}"
636
637 if [ -x "${NETDATA_PREFIX}/usr/sbin/netdata" ] && [ -r "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
638 "${NETDATA_PREFIX}/usr/sbin/netdata" \
639 -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
640 -W get "${section}" "${key}" "${value}" ||
641 echo "${value}"
642 else
643 echo "${value}"
644 fi
645 }
646
647 # the user netdata will run as
648 if [ "$(id -u)" = "0" ]; then
649 NETDATA_USER="$(config_option "global" "run as user" "netdata")"
650 ROOT_USER="root"
651 else
652 NETDATA_USER="${USER}"
653 ROOT_USER="${USER}"
654 fi
655 NETDATA_GROUP="$(id -g -n "${NETDATA_USER}" 2> /dev/null)"
656 [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
657 echo >&2 "Netdata user and group set to: ${NETDATA_USER}/${NETDATA_GROUP}"
658
659 prepare_cmake_options
660
661 print_cmake_configure_command() {
662 printf "Would have used the following CMake command line for configuration: "
663 # shellcheck disable=SC2086
664 case "${NETDATA_CMAKE_INSTALL_PREFIX_OPTION:+I}${NETDATA_WINDOWS_PATH_PREFIX_OPTION:+W}" in
665 "IW")
666 escaped_print "${cmake}" ${NETDATA_CMAKE_OPTIONS} "${NETDATA_CMAKE_INSTALL_PREFIX_OPTION}" "${NETDATA_WINDOWS_PATH_PREFIX_OPTION}"
667 ;;
668 "I")
669 escaped_print "${cmake}" ${NETDATA_CMAKE_OPTIONS} "${NETDATA_CMAKE_INSTALL_PREFIX_OPTION}"
670 ;;
671 "W")
672 escaped_print "${cmake}" ${NETDATA_CMAKE_OPTIONS} "${NETDATA_WINDOWS_PATH_PREFIX_OPTION}"
673 ;;
674 *)
675 escaped_print "${cmake}" ${NETDATA_CMAKE_OPTIONS}
676 ;;
677 esac
678 printf "\n"
679 }
680
681 run_cmake_configure() {
682 # shellcheck disable=SC2086
683 case "${NETDATA_CMAKE_INSTALL_PREFIX_OPTION:+I}${NETDATA_WINDOWS_PATH_PREFIX_OPTION:+W}" in
684 "IW")
685 run ${cmake} ${NETDATA_CMAKE_OPTIONS} "${NETDATA_CMAKE_INSTALL_PREFIX_OPTION}" "${NETDATA_WINDOWS_PATH_PREFIX_OPTION}"
686 ;;
687 "I")
688 run ${cmake} ${NETDATA_CMAKE_OPTIONS} "${NETDATA_CMAKE_INSTALL_PREFIX_OPTION}"
689 ;;
690 "W")
691 run ${cmake} ${NETDATA_CMAKE_OPTIONS} "${NETDATA_WINDOWS_PATH_PREFIX_OPTION}"
692 ;;
693 *)
694 run ${cmake} ${NETDATA_CMAKE_OPTIONS}
695 ;;
696 esac
697 }
698
699 if [ -n "${NETDATA_PREPARE_ONLY}" ]; then
700 progress "Exiting before building Netdata as requested."
701 print_cmake_configure_command
702 trap - EXIT
703 exit 0
704 fi
705
706 # Let cmake know we don't want to link shared libs
707 if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
708 NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DBUILD_SHARED_LIBS=Off"
709 fi
710
711 # shellcheck disable=SC2086
712 if ! run_cmake_configure; then
713 fatal "Failed to configure Netdata sources." I000A
714 fi
715
716 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
717
718 # remove the build_error hook
719 trap - EXIT
720
721 # -----------------------------------------------------------------------------
722 [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
723
724 # -----------------------------------------------------------------------------
725 progress "Compile netdata"
726
727 # shellcheck disable=SC2086
728 if ! run ${cmake} --build "${NETDATA_BUILD_DIR}" --parallel ${JOBS} -- ${BUILD_OPTS}; then
729 fatal "Failed to build Netdata." I000B
730 fi
731
732 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
733
734 # -----------------------------------------------------------------------------
735 [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
736
737 # -----------------------------------------------------------------------------
738 progress "Install netdata"
739
740 if ! cmake_install "${NETDATA_BUILD_DIR}"; then
741 fatal "Failed to install Netdata." I000C
742 fi
743
744 # -----------------------------------------------------------------------------
745 progress "Creating standard user and groups for netdata"
746
747 NETDATA_ADDED_TO_GROUPS=""
748 if [ "$(id -u)" -eq 0 ]; then
749 create_netdata_accounts
750 else
751 run_failed "The installer does not run as root. Nothing to do for user and groups"
752 fi
753
754 # -----------------------------------------------------------------------------
755 progress "Install logrotate configuration for netdata"
756
757 install_netdata_logrotate
758
759 progress "Install journald configuration for netdata"
760
761 install_netdata_journald_conf
762
763 # -----------------------------------------------------------------------------
764 progress "Read installation options from netdata.conf"
765
766 # create an empty config if it does not exist
767 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
768 touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
769
770 # port
771 defport=19999
772 NETDATA_PORT="$(config_option "web" "default port" ${defport})"
773
774 # directories
775 NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
776 NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
777 NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
778 NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
779 NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
780 NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
781 NETDATA_STOCK_DATA_DIR="$(config_option "global" "stock data directory" "${NETDATA_PREFIX}/usr/share/netdata")"
782 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
783 NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
784
785 cat << OPTIONSEOF
786
787 Permissions
788 - netdata user : ${NETDATA_USER}
789 - netdata group : ${NETDATA_GROUP}
790 - root user : ${ROOT_USER}
791
792 Directories
793 - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
794 - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
795 - netdata stock data dir : ${NETDATA_STOCK_DATA_DIR}
796 - netdata log dir : ${NETDATA_LOG_DIR}
797 - netdata run dir : ${NETDATA_RUN_DIR}
798 - netdata lib dir : ${NETDATA_LIB_DIR}
799 - netdata web dir : ${NETDATA_WEB_DIR}
800 - netdata cache dir : ${NETDATA_CACHE_DIR}
801
802 Other
803 - netdata port : ${NETDATA_PORT}
804
805 OPTIONSEOF
806
807 # -----------------------------------------------------------------------------
808 progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
809
810 if [ ! -d "${NETDATA_RUN_DIR}" ]; then
811 # this is needed if NETDATA_PREFIX is not empty
812 if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
813 warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
814 fi
815 fi
816
817 # --- stock conf dir ----
818
819 [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
820 [ ! -d "${NETDATA_STOCK_DATA_DIR}" ] && mkdir -p "${NETDATA_STOCK_DATA_DIR}"
821 [ -L "${NETDATA_USER_CONFIG_DIR}/orig" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/orig"
822 run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/orig"
823
824
825 # --- web dir ---
826 if [ ! -d "${NETDATA_WEB_DIR}" ]; then
827 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
828 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
829 fi
830 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
831 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
832
833 # --- other dirs ----
834
835 install_netdata_dirs
836
837 # --- plugins ----
838
839 if [ "$(id -u)" -eq 0 ]; then
840 # find the admin group
841 admin_group=
842 test -z "${admin_group}" && get_group root > /dev/null 2>&1 && admin_group="root"
843 test -z "${admin_group}" && get_group daemon > /dev/null 2>&1 && admin_group="daemon"
844 test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
845
846 run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
847 run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
848 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
849 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
850 # shellcheck disable=SC2086
851 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*plugin -exec chown :${NETDATA_GROUP} {} \;
852 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*plugin -exec chmod 0750 {} \;
853 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
854
855 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
856 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
857 capabilities=0
858 if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
859 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
860 if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
861 # if we managed to setcap, but we fail to execute apps.plugin setuid to root
862 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
863 fi
864 fi
865
866 if [ $capabilities -eq 0 ]; then
867 # fix apps.plugin to be setuid to root
868 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
869 fi
870 fi
871
872 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" ]; then
873 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
874 capabilities=0
875 if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
876 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
877 if run setcap cap_dac_read_search,cap_audit_control+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"; then
878 # if we managed to setcap, but we fail to execute debugfs.plugin setuid to root
879 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
880 fi
881 fi
882
883 if [ $capabilities -eq 0 ]; then
884 # fix debugfs.plugin to be setuid to root
885 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
886 fi
887 fi
888
889 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin" ]; then
890 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
891 capabilities=0
892 if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
893 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
894 if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"; then
895 capabilities=1
896 fi
897 fi
898
899 if [ $capabilities -eq 0 ]; then
900 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
901 fi
902 fi
903
904 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/otel-signal-viewer-plugin" ]; then
905 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/otel-signal-viewer-plugin"
906 capabilities=0
907 if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
908 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/otel-signal-viewer-plugin"
909 if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/otel-signal-viewer-plugin"; then
910 capabilities=1
911 fi
912 fi
913
914 if [ $capabilities -eq 0 ]; then
915 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/otel-signal-viewer-plugin"
916 fi
917 fi
918
919 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
920 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
921 capabilities=0
922 if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
923 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
924 if run sh -c "setcap cap_perfmon+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin\" || setcap cap_sys_admin+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin\""; then
925 capabilities=1
926 fi
927 fi
928
929 if [ $capabilities -eq 0 ]; then
930 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
931 fi
932 fi
933
934 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
935 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
936 capabilities=0
937 if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
938 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
939 if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"; then
940 capabilities=1
941 fi
942 fi
943
944 if [ $capabilities -eq 0 ]; then
945 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
946 fi
947 fi
948
949 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
950 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
951 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
952 fi
953
954 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
955 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
956 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
957 fi
958
959 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
960 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
961 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
962 fi
963
964 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
965 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
966 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
967 fi
968
969 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
970 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
971 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
972 fi
973
974 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
975 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
976 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
977 fi
978
979 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
980 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
981 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
982 fi
983
984 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners" ]; then
985 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
986 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
987 fi
988
989 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin" ]; then
990 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
991 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
992 fi
993
994 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo" ]; then
995 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
996 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
997 fi
998
999 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin" ]; then
1000 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
1001 capabilities=0
1002 if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
1003 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
1004 if run setcap "cap_dac_read_search+epi cap_net_admin+epi cap_net_raw=eip" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"; then
1005 capabilities=1
1006 fi
1007 fi
1008
1009 if [ $capabilities -eq 0 ]; then
1010 # fix go.d.plugin to be setuid to root
1011 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
1012 fi
1013 fi
1014
1015 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/otel-plugin" ]; then
1016 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/otel-plugin"
1017 if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
1018 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/otel-plugin"
1019 fi
1020 fi
1021
1022 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/netflow-plugin" ]; then
1023 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/netflow-plugin"
1024 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/netflow-plugin"
1025 fi
1026
1027 else
1028 # non-privileged user installation
1029 run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
1030 run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
1031 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
1032 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
1033 fi
1034
1035 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
1036
1037 # -----------------------------------------------------------------------------
1038 progress "Telemetry configuration"
1039
1040 # Opt-out from telemetry program
1041 if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
1042 run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
1043 else
1044 printf "You can opt out from anonymous statistics via the --disable-telemetry option, or by creating an empty file %s \n\n" "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
1045 fi
1046
1047 # -----------------------------------------------------------------------------
1048 progress "Install netdata at system init"
1049
1050 # By default we assume the shutdown/startup of the Netdata Agent are effectively
1051 # without any system supervisor/init like SystemD or SysV. So we assume the most
1052 # basic startup/shutdown commands...
1053 NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
1054 NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
1055
1056 if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
1057 # If docker runs systemd for some weird reason, let the install proceed
1058 is_systemd_running="NO"
1059 if command -v pidof > /dev/null 2>&1; then
1060 is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
1061 else
1062 is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
1063 fi
1064
1065 if [ "${is_systemd_running}" = "1" ]; then
1066 echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
1067 install_netdata_service || run_failed "Cannot install netdata init service."
1068 else
1069 echo >&2 "We are running within a docker container, will not be installing netdata service"
1070 fi
1071 echo >&2
1072 else
1073 install_netdata_service || run_failed "Cannot install netdata init service."
1074 fi
1075
1076 # -----------------------------------------------------------------------------
1077 # check if we can re-start netdata
1078
1079 # TODO: Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
1080 started=0
1081 if [ ${DONOTSTART} -eq 1 ]; then
1082 create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1083 else
1084 if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
1085 fatal "Cannot start netdata!" I000D
1086 fi
1087
1088 started=1
1089 run_ok "netdata started!"
1090 create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
1091 fi
1092 run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1093
1094 if [ "$(uname)" = "Linux" ]; then
1095 # -------------------------------------------------------------------------
1096 progress "Check KSM (kernel memory deduper)"
1097
1098 ksm_is_available_but_disabled() {
1099 cat << KSM1
1100
1101 ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
1102
1103 You have kernel memory de-duper (called Kernel Same-page Merging,
1104 or KSM) available, but it is not currently enabled.
1105
1106 To enable it run:
1107
1108 ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
1109 ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
1110
1111 If you enable it, you will save 40-60% of netdata memory.
1112
1113 KSM1
1114 }
1115
1116 ksm_is_not_available() {
1117 cat << KSM2
1118
1119 ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
1120
1121 It seems you do not have kernel memory de-duper (called Kernel Same-page
1122 Merging, or KSM) available.
1123
1124 To enable it, you need a kernel built with CONFIG_KSM=y
1125
1126 If you can have it, you will save 40-60% of netdata memory.
1127
1128 KSM2
1129 }
1130
1131 if [ -f "/sys/kernel/mm/ksm/run" ]; then
1132 if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
1133 ksm_is_available_but_disabled
1134 fi
1135 else
1136 ksm_is_not_available
1137 fi
1138 fi
1139
1140 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
1141 # -----------------------------------------------------------------------------
1142 progress "Check apps.plugin"
1143
1144 if [ "$(id -u)" -ne 0 ]; then
1145 cat << SETUID_WARNING
1146
1147 ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
1148
1149 Since you have installed netdata as a normal user, to have apps.plugin collect
1150 all the needed data, you have to give it the access rights it needs, by running
1151 either of the following sets of commands:
1152
1153 To run apps.plugin with escalated capabilities:
1154
1155 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
1156 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
1157 ${TPUT_YELLOW}${TPUT_BOLD}sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
1158
1159 or, to run apps.plugin as root:
1160
1161 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
1162 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
1163
1164 apps.plugin is performing a hard-coded function of data collection for all
1165 running processes. It cannot be instructed from the netdata daemon to perform
1166 any task, so it is pretty safe to do this.
1167
1168 SETUID_WARNING
1169 fi
1170 fi
1171
1172 # -----------------------------------------------------------------------------
1173 progress "Copy uninstaller"
1174 if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
1175 echo >&2 "Removing uninstaller from old location"
1176 rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
1177 fi
1178
1179 sed "s|ENVIRONMENT_FILE=\"/etc/netdata/.environment\"|ENVIRONMENT_FILE=\"${NETDATA_PREFIX}/etc/netdata/.environment\"|" packaging/installer/netdata-uninstaller.sh > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
1180 chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
1181
1182 # -----------------------------------------------------------------------------
1183 progress "Basic netdata instructions"
1184
1185 cat << END
1186
1187 netdata by default listens on all IPs on port ${NETDATA_PORT},
1188 so you can access it with:
1189
1190 ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
1191
1192 To stop netdata run:
1193
1194 ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
1195
1196 To start netdata run:
1197
1198 ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
1199
1200 END
1201 echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
1202 echo >&2
1203
1204 # -----------------------------------------------------------------------------
1205 progress "Installing (but not enabling) the netdata updater tool"
1206 install_netdata_updater || run_failed "Cannot install netdata updater tool."
1207
1208 # -----------------------------------------------------------------------------
1209 progress "Wrap up environment set up"
1210
1211 # Save environment variables
1212 echo >&2 "Preparing .environment file"
1213 cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
1214 # Created by installer
1215 PATH="${PATH}"
1216 CFLAGS="${CFLAGS}"
1217 LDFLAGS="${LDFLAGS}"
1218 MAKEOPTS="${MAKEOPTS}"
1219 NETDATA_TMPDIR="${TMPDIR}"
1220 NETDATA_PREFIX="${NETDATA_PREFIX}"
1221 NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS}"
1222 NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
1223 INSTALL_UID="$(id -u)"
1224 NETDATA_GROUP="${NETDATA_GROUP}"
1225 REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
1226 RELEASE_CHANNEL="${RELEASE_CHANNEL}"
1227 IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
1228 NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
1229 EOF
1230 run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
1231
1232 echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
1233 cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
1234 new_installation
1235 EOF
1236
1237 print_deferred_errors
1238
1239 # -----------------------------------------------------------------------------
1240 echo >&2
1241 progress "We are done!"
1242
1243 if [ ${started} -eq 1 ]; then
1244 netdata_banner
1245 progress "is installed and running now!"
1246 else
1247 netdata_banner
1248 progress "is installed now!"
1249 fi
1250
1251 echo >&2 " Enjoy X-Ray Vision for your infrastructure..."
1252 echo >&2
1253 exit 0