netdata-installer.sh 49 KB

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