netdata-installer.sh 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634
  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. DONOTSTART=0
  205. DONOTWAIT=0
  206. NETDATA_PREFIX=
  207. LIBS_ARE_HERE=0
  208. NETDATA_ENABLE_ML=""
  209. ENABLE_DBENGINE=1
  210. ENABLE_EBPF=1
  211. ENABLE_GO=1
  212. ENABLE_H2O=1
  213. ENABLE_CLOUD=1
  214. ENABLE_LOGS_MANAGEMENT=1
  215. ENABLE_LOGS_MANAGEMENT_TESTS=0
  216. FORCE_LEGACY_CXX=0
  217. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS-}"
  218. RELEASE_CHANNEL="nightly" # valid values are 'nightly' and 'stable'
  219. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY:-"no"}"
  220. while [ -n "${1}" ]; do
  221. case "${1}" in
  222. "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
  223. "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
  224. "--use-system-protobuf") USE_SYSTEM_PROTOBUF=1 ;;
  225. "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
  226. "--dont-start-it") DONOTSTART=1 ;;
  227. "--dont-wait") DONOTWAIT=1 ;;
  228. "--auto-update" | "-u") ;;
  229. "--auto-update-type") ;;
  230. "--stable-channel") RELEASE_CHANNEL="stable" ;;
  231. "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
  232. "--force-legacy-cxx") FORCE_LEGACY_CXX=1 ;;
  233. "--enable-plugin-freeipmi") ENABLE_FREEIPMI=1 ;;
  234. "--disable-plugin-freeipmi") ENABLE_FREEIPMI=0 ;;
  235. "--disable-https")
  236. ENABLE_DBENGINE=0
  237. ENABLE_H2O=0
  238. ENABLE_CLOUD=0
  239. ;;
  240. "--disable-dbengine") ENABLE_DBENGINE=0 ;;
  241. "--enable-plugin-go") ENABLE_GO=1 ;;
  242. "--disable-plugin-go") ENABLE_GO=0 ;;
  243. "--disable-go") ENABLE_GO=0 ;;
  244. "--enable-plugin-nfacct") ENABLE_NFACCT=1 ;;
  245. "--disable-plugin-nfacct") ENABLE_NFACCT=0 ;;
  246. "--enable-plugin-xenstat") ENABLE_XENSTAT=1 ;;
  247. "--disable-plugin-xenstat") ENABLE_XENSTAT=0 ;;
  248. "--enable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=1 ;;
  249. "--disable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=0 ;;
  250. "--enable-exporting-kinesis" | "--enable-backend-kinesis")
  251. # TODO: Needs CMake Support
  252. ;;
  253. "--disable-exporting-kinesis" | "--disable-backend-kinesis")
  254. # TODO: Needs CMake Support
  255. ;;
  256. "--enable-exporting-prometheus-remote-write" | "--enable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=1 ;;
  257. "--disable-exporting-prometheus-remote-write" | "--disable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=0 ;;
  258. "--enable-exporting-mongodb" | "--enable-backend-mongodb") EXPORTER_MONGODB=1 ;;
  259. "--disable-exporting-mongodb" | "--disable-backend-mongodb") EXPORTER_MONGODB=0 ;;
  260. "--enable-exporting-pubsub")
  261. # TODO: Needs CMake support
  262. ;;
  263. "--disable-exporting-pubsub")
  264. # TODO: Needs CMake support
  265. ;;
  266. "--enable-ml") NETDATA_ENABLE_ML=1 ;;
  267. "--disable-ml") NETDATA_ENABLE_ML=0 ;;
  268. "--enable-lto")
  269. # TODO: Needs CMake support
  270. ;;
  271. "--enable-logs-management") ENABLE_LOGS_MANAGEMENT=1 ;;
  272. "--disable-logsmanagement") ENABLE_LOGS_MANAGEMENT=0 ;;
  273. "--enable-logsmanagement-tests") ENABLE_LOGS_MANAGEMENT_TESTS=1 ;;
  274. "--disable-lto")
  275. # TODO: Needs CMake support
  276. ;;
  277. "--disable-x86-sse")
  278. # XXX: No longer supported.
  279. ;;
  280. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
  281. "--enable-ebpf")
  282. ENABLE_EBPF=1
  283. NETDATA_DISABLE_EBPF=0
  284. ;;
  285. "--disable-ebpf")
  286. ENABLE_EBPF=0
  287. NETDATA_DISABLE_EBPF=1
  288. ;;
  289. "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
  290. "--one-time-build")
  291. # XXX: No longer supported
  292. ;;
  293. "--disable-cloud")
  294. if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
  295. warning "Cloud explicitly enabled, ignoring --disable-cloud."
  296. else
  297. ENABLE_CLOUD=0
  298. NETDATA_DISABLE_CLOUD=1
  299. fi
  300. ;;
  301. "--require-cloud")
  302. if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
  303. warning "Cloud explicitly disabled, ignoring --require-cloud."
  304. else
  305. ENABLE_CLOUD=1
  306. NETDATA_REQUIRE_CLOUD=1
  307. fi
  308. ;;
  309. "--build-json-c")
  310. NETDATA_BUILD_JSON_C=1
  311. ;;
  312. "--install-prefix")
  313. NETDATA_PREFIX="${2}/netdata"
  314. shift 1
  315. ;;
  316. "--install-no-prefix")
  317. NETDATA_PREFIX="${2}"
  318. shift 1
  319. ;;
  320. "--prepare-only")
  321. NETDATA_DISABLE_TELEMETRY=1
  322. NETDATA_PREPARE_ONLY=1
  323. DONOTWAIT=1
  324. ;;
  325. "--help" | "-h")
  326. usage
  327. exit 1
  328. ;;
  329. *)
  330. echo >&2 "Unrecognized option '${1}'."
  331. exit_reason "Unrecognized option '${1}'." I000E
  332. usage
  333. exit 1
  334. ;;
  335. esac
  336. shift 1
  337. done
  338. if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
  339. [ -n "$DISABLE_TELEMETRY" ] ||
  340. [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
  341. [ -n "$DO_NOT_TRACK" ]; then
  342. NETDATA_DISABLE_TELEMETRY=1
  343. fi
  344. if [ -n "${MAKEOPTS}" ]; then
  345. JOBS="$(echo "${MAKEOPTS}" | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
  346. else
  347. JOBS="$(find_processors)"
  348. fi
  349. if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
  350. mega="$((1024 * 1024))"
  351. base=1024
  352. scale=256
  353. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  354. total_ram="$(grep MemTotal /proc/meminfo | cut -d ':' -f 2 | tr -d ' kB')"
  355. total_ram="$((total_ram * 1024))"
  356. if [ "${total_ram}" -le "$((base * mega))" ] && [ -z "${NETDATA_ENABLE_ML}" ]; then
  357. NETDATA_ENABLE_ML=0
  358. fi
  359. if [ -z "${MAKEOPTS}" ]; then
  360. MAKEOPTS="-j${JOBS}"
  361. while [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ]; do
  362. JOBS="$((JOBS - 1))"
  363. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  364. MAKEOPTS="-j${JOBS}"
  365. done
  366. else
  367. if [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
  368. target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  369. total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  370. 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."
  371. exit_reason "Insufficient RAM to safely install." I000F
  372. exit 2
  373. fi
  374. fi
  375. fi
  376. # set default make options
  377. if [ -z "${MAKEOPTS}" ]; then
  378. MAKEOPTS="-j$(find_processors)"
  379. elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
  380. MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
  381. fi
  382. if [ "$(id -u)" -ne 0 ] && [ -z "${NETDATA_PREPARE_ONLY}" ]; then
  383. if [ -z "${NETDATA_PREFIX}" ]; then
  384. netdata_banner
  385. banner_nonroot_install "${@}"
  386. exit_reason "Attempted install as non-root user to /." I0010
  387. exit 1
  388. else
  389. banner_root_notify "${@}"
  390. fi
  391. fi
  392. netdata_banner
  393. progress "real-time performance monitoring, done right!"
  394. cat << BANNER1
  395. You are about to build and install netdata to your system.
  396. The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
  397. any temporary files. You can override this by setting \$TMPDIR to a
  398. writable directory where you can execute files.
  399. It will be installed at these locations:
  400. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  401. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  402. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  403. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  404. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  405. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  406. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  407. BANNER1
  408. [ "$(id -u)" -eq 0 ] && cat << BANNER2
  409. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  410. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  411. BANNER2
  412. cat << BANNER3
  413. This installer allows you to change the installation path.
  414. Press Control-C and run the same command with --help for help.
  415. BANNER3
  416. if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
  417. cat << BANNER4
  418. ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
  419. Anonymous usage stats will be collected and sent to Netdata.
  420. To opt-out, pass --disable-telemetry option to the installer or export
  421. the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
  422. (e.g: export DISABLE_TELEMETRY=1).
  423. BANNER4
  424. fi
  425. if ! command -v cmake >/dev/null 2>&1; then
  426. fatal "Could not find CMake, which is required to build Netdata." I0012
  427. else
  428. cmake="$(command -v cmake)"
  429. progress "Found CMake at ${cmake}. CMake version: $(${cmake} --version | head -n 1)"
  430. fi
  431. if ! command -v "ninja" >/dev/null 2>&1; then
  432. progress "Could not find Ninja, will use Make instead."
  433. else
  434. ninja="$(command -v ninja)"
  435. progress "Found Ninja at ${ninja}. Ninja version: $(${ninja} --version)"
  436. progress "Will use Ninja for this build instead of Make when possible."
  437. fi
  438. make="$(command -v make 2>/dev/null)"
  439. if [ -z "${make}" ] && [ -z "${ninja}" ]; then
  440. fatal "Could not find a usable underlying build system (we support make and ninja)." I0014
  441. fi
  442. CMAKE_OPTS="${ninja:+-G Ninja}"
  443. BUILD_OPTS="VERBOSE=1"
  444. [ -n "${ninja}" ] && BUILD_OPTS="-v"
  445. if [ ${DONOTWAIT} -eq 0 ]; then
  446. if [ -n "${NETDATA_PREFIX}" ]; then
  447. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  448. else
  449. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  450. fi
  451. read -r REPLY
  452. if [ "$REPLY" != '' ]; then
  453. exit_reason "User did not accept install attempt." I0011
  454. exit 1
  455. fi
  456. fi
  457. cmake_install() {
  458. # run cmake --install ${1}
  459. # The above command should be used to replace the logic below once we no longer support
  460. # versions of CMake less than 3.15.
  461. if [ -n "${ninja}" ]; then
  462. run ${ninja} -C "${1}" install
  463. else
  464. run ${make} -C "${1}" install
  465. fi
  466. }
  467. build_error() {
  468. netdata_banner
  469. trap - EXIT
  470. fatal "Netdata failed to build for an unknown reason." I0002
  471. }
  472. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  473. shift
  474. echo >&2 "ok, assuming libs are really installed."
  475. export ZLIB_CFLAGS=" "
  476. export ZLIB_LIBS="-lz"
  477. export UUID_CFLAGS=" "
  478. export UUID_LIBS="-luuid"
  479. fi
  480. trap build_error EXIT
  481. # -----------------------------------------------------------------------------
  482. get_kernel_version() {
  483. r="$(uname -r | cut -f 1 -d '-')"
  484. tmpfile="$(mktemp)"
  485. echo "${r}" | tr '.' ' ' > "${tmpfile}"
  486. read -r maj min patch _ < "${tmpfile}"
  487. rm -f "${tmpfile}"
  488. printf "%03d%03d%03d" "${maj}" "${min}" "${patch}"
  489. }
  490. detect_libc() {
  491. libc=
  492. if ldd --version 2>&1 | grep -q -i glibc; then
  493. echo >&2 " Detected GLIBC"
  494. libc="glibc"
  495. elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
  496. echo >&2 " Detected GLIBC"
  497. libc="glibc"
  498. elif ldd --version 2>&1 | grep -q -i musl; then
  499. echo >&2 " Detected musl"
  500. libc="musl"
  501. else
  502. cmd=$(ldd /bin/sh | grep -w libc | cut -d" " -f 3)
  503. if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
  504. echo >&2 " Detected GLIBC"
  505. libc="glibc"
  506. fi
  507. fi
  508. if [ -z "$libc" ]; then
  509. warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
  510. return 1
  511. fi
  512. echo "${libc}"
  513. return 0
  514. }
  515. build_libbpf() {
  516. cd "${1}/src" > /dev/null || return 1
  517. mkdir root build
  518. # shellcheck disable=SC2086
  519. run env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
  520. cd - > /dev/null || return 1
  521. }
  522. copy_libbpf() {
  523. target_dir="${PWD}/externaldeps/libbpf"
  524. if [ "$(uname -m)" = x86_64 ]; then
  525. lib_subdir="lib64"
  526. else
  527. lib_subdir="lib"
  528. fi
  529. run mkdir -p "${target_dir}" || return 1
  530. run cp "${1}/usr/${lib_subdir}/libbpf.a" "${target_dir}/libbpf.a" || return 1
  531. run cp -r "${1}/usr/include" "${target_dir}" || return 1
  532. run cp -r "${1}/include/uapi" "${target_dir}/include" || return 1
  533. }
  534. bundle_libbpf() {
  535. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  536. ENABLE_EBPF=0
  537. NETDATA_DISABLE_EBPF=1
  538. return 0
  539. fi
  540. if [ -z "${make}" ]; then
  541. warning "No usable copy of Make found, which is required to bundle libbpf. Disabling eBPF support."
  542. ENABLE_EBPF=0
  543. NETDATA_DISABLE_EBPF=1
  544. return 0
  545. fi
  546. # When libc is not detected, we do not have necessity to compile libbpf and we should not do download of eBPF programs
  547. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  548. if [ -z "$libc" ]; then
  549. NETDATA_DISABLE_EBPF=1
  550. ENABLE_EBPF=0
  551. return 0
  552. fi
  553. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  554. progress "Prepare libbpf"
  555. if [ "$(get_kernel_version)" -ge "004014000" ]; then
  556. LIBBPF_PACKAGE_VERSION="$(cat packaging/current_libbpf.version)"
  557. LIBBPF_PACKAGE_COMPONENT="current_libbpf"
  558. else
  559. LIBBPF_PACKAGE_VERSION="$(cat packaging/libbpf_0_0_9.version)"
  560. LIBBPF_PACKAGE_COMPONENT="libbpf_0_0_9"
  561. fi
  562. tmp="$(mktemp -d -t netdata-libbpf-XXXXXX)"
  563. LIBBPF_PACKAGE_BASENAME="v${LIBBPF_PACKAGE_VERSION}.tar.gz"
  564. if fetch_and_verify "${LIBBPF_PACKAGE_COMPONENT}" \
  565. "https://github.com/netdata/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
  566. "${LIBBPF_PACKAGE_BASENAME}" \
  567. "${tmp}" \
  568. "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBBPF}"; then
  569. if run tar --no-same-owner -xf "${tmp}/${LIBBPF_PACKAGE_BASENAME}" -C "${tmp}" &&
  570. build_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  571. copy_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  572. rm -rf "${tmp}"; then
  573. run_ok "libbpf built and prepared."
  574. ENABLE_EBPF=1
  575. else
  576. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  577. fatal "failed to build libbpf." I0005
  578. else
  579. run_failed "Failed to build libbpf. eBPF support will be disabled"
  580. ENABLE_EBPF=0
  581. NETDATA_DISABLE_EBPF=1
  582. fi
  583. fi
  584. else
  585. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  586. fatal "Failed to fetch sources for libbpf." I0006
  587. else
  588. run_failed "Unable to fetch sources for libbpf. eBPF support will be disabled"
  589. ENABLE_EBPF=0
  590. NETDATA_DISABLE_EBPF=1
  591. fi
  592. fi
  593. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  594. }
  595. bundle_libbpf
  596. copy_co_re() {
  597. cp -R "${1}/includes" "src/libnetdata/ebpf/"
  598. }
  599. bundle_ebpf_co_re() {
  600. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  601. return 0
  602. fi
  603. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  604. progress "eBPF CO-RE"
  605. CORE_PACKAGE_VERSION="$(cat packaging/ebpf-co-re.version)"
  606. tmp="$(mktemp -d -t netdata-ebpf-co-re-XXXXXX)"
  607. CORE_PACKAGE_BASENAME="netdata-ebpf-co-re-glibc-${CORE_PACKAGE_VERSION}.tar.xz"
  608. if fetch_and_verify "ebpf-co-re" \
  609. "https://github.com/netdata/ebpf-co-re/releases/download/${CORE_PACKAGE_VERSION}/${CORE_PACKAGE_BASENAME}" \
  610. "${CORE_PACKAGE_BASENAME}" \
  611. "${tmp}" \
  612. "${NETDATA_LOCAL_TARBALL_OVERRIDE_CORE}"; then
  613. if run tar --no-same-owner -xf "${tmp}/${CORE_PACKAGE_BASENAME}" -C "${tmp}" &&
  614. copy_co_re "${tmp}" &&
  615. rm -rf "${tmp}"; then
  616. run_ok "libbpf built and prepared."
  617. ENABLE_EBPF=1
  618. else
  619. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  620. fatal "Failed to get eBPF CO-RE files." I0007
  621. else
  622. run_failed "Failed to get eBPF CO-RE files. eBPF support will be disabled"
  623. NETDATA_DISABLE_EBPF=1
  624. ENABLE_EBPF=0
  625. enable_feature PLUGIN_EBPF 0
  626. fi
  627. fi
  628. else
  629. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  630. fatal "Failed to fetch eBPF CO-RE files." I0008
  631. else
  632. run_failed "Failed to fetch eBPF CO-RE files. eBPF support will be disabled"
  633. NETDATA_DISABLE_EBPF=1
  634. ENABLE_EBPF=0
  635. enable_feature PLUGIN_EBPF 0
  636. fi
  637. fi
  638. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  639. }
  640. bundle_ebpf_co_re
  641. # -----------------------------------------------------------------------------
  642. build_fluentbit() {
  643. env_cmd="env CFLAGS='-w' CXXFLAGS='-w' LDFLAGS="
  644. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  645. env_cmd="env CFLAGS='-fPIC -pipe -w' CXXFLAGS='-fPIC -pipe -w' LDFLAGS="
  646. fi
  647. mkdir -p src/fluent-bit/build || return 1
  648. cd src/fluent-bit/build > /dev/null || return 1
  649. rm CMakeCache.txt > /dev/null 2>&1
  650. if ! run eval "${env_cmd} $1 -C ../../logsmanagement/fluent_bit_build/config.cmake -B./ -S../"; then
  651. cd - > /dev/null || return 1
  652. rm -rf src/fluent-bit/build > /dev/null 2>&1
  653. return 1
  654. fi
  655. if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
  656. cd - > /dev/null || return 1
  657. rm -rf src/fluent-bit/build > /dev/null 2>&1
  658. return 1
  659. fi
  660. cd - > /dev/null || return 1
  661. }
  662. bundle_fluentbit() {
  663. progress "Prepare Fluent-Bit"
  664. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  665. warning "You have explicitly requested to disable Netdata Logs Management support, Fluent-Bit build is skipped."
  666. return 0
  667. fi
  668. if [ ! -d "src/fluent-bit" ]; then
  669. warning "Missing submodule Fluent-Bit. The install process will continue, but Netdata Logs Management support will be disabled."
  670. ENABLE_LOGS_MANAGEMENT=0
  671. return 0
  672. fi
  673. patch -N -p1 src/fluent-bit/CMakeLists.txt -i src/logsmanagement/fluent_bit_build/CMakeLists.patch
  674. patch -N -p1 src/fluent-bit/src/flb_log.c -i src/logsmanagement/fluent_bit_build/flb-log-fmt.patch
  675. # If musl is used, we need to patch chunkio, providing fts has been previously installed.
  676. libc="$(detect_libc)"
  677. if [ "${libc}" = "musl" ]; then
  678. patch -N -p1 src/fluent-bit/lib/chunkio/src/CMakeLists.txt -i src/logsmanagement/fluent_bit_build/chunkio-static-lib-fts.patch
  679. patch -N -p1 src/fluent-bit/cmake/luajit.cmake -i src/logsmanagement/fluent_bit_build/exclude-luajit.patch
  680. patch -N -p1 src/fluent-bit/src/flb_network.c -i src/logsmanagement/fluent_bit_build/xsi-strerror.patch
  681. fi
  682. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling Fluent-Bit."
  683. if build_fluentbit "$cmake"; then
  684. # If Fluent-Bit built with inotify support, use it.
  685. if [ "$(grep -o '^FLB_HAVE_INOTIFY:INTERNAL=.*' src/fluent-bit/build/CMakeCache.txt | cut -d '=' -f 2)" ]; then
  686. CFLAGS="${CFLAGS} -DFLB_HAVE_INOTIFY"
  687. fi
  688. FLUENT_BIT_BUILD_SUCCESS=1
  689. run_ok "Fluent-Bit built successfully."
  690. else
  691. warning "Failed to build Fluent-Bit, Netdata Logs Management support will be disabled in this build."
  692. ENABLE_LOGS_MANAGEMENT=0
  693. fi
  694. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  695. }
  696. bundle_fluentbit
  697. # -----------------------------------------------------------------------------
  698. # If we’re installing the Go plugin, ensure a working Go toolchain is installed.
  699. if [ "${ENABLE_GO}" -eq 1 ]; then
  700. progress "Checking for a usable Go toolchain and attempting to install one to /usr/local/go if needed."
  701. . "${NETDATA_SOURCE_DIR}/packaging/check-for-go-toolchain.sh"
  702. if ! ensure_go_toolchain; then
  703. warning "Go ${GOLANG_MIN_VERSION} needed to build Go plugin, but could not find or install a usable toolchain: ${GOLANG_FAILURE_REASON}"
  704. ENABLE_GO=0
  705. fi
  706. fi
  707. # -----------------------------------------------------------------------------
  708. # If we have the dashboard switching logic, make sure we're on the classic
  709. # dashboard during the install (updates don't work correctly otherwise).
  710. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
  711. "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
  712. fi
  713. # -----------------------------------------------------------------------------
  714. # By default, `git` does not update local tags based on remotes. Because
  715. # we use the most recent tag as part of our version determination in
  716. # our build, this can lead to strange versions that look ancient but are
  717. # actually really recent. To avoid this, try and fetch tags if we're
  718. # working in a git checkout.
  719. if [ -d ./.git ] ; then
  720. echo >&2
  721. progress "Updating tags in git to ensure a consistent version number"
  722. run git fetch -t || true
  723. fi
  724. # -----------------------------------------------------------------------------
  725. echo >&2
  726. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
  727. NETDATA_BUILD_DIR="${NETDATA_BUILD_DIR:-./build/}"
  728. rm -rf "${NETDATA_BUILD_DIR}"
  729. # function to extract values from the config file
  730. config_option() {
  731. section="${1}"
  732. key="${2}"
  733. value="${3}"
  734. if [ -x "${NETDATA_PREFIX}/usr/sbin/netdata" ] && [ -r "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  735. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  736. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  737. -W get "${section}" "${key}" "${value}" ||
  738. echo "${value}"
  739. else
  740. echo "${value}"
  741. fi
  742. }
  743. # the user netdata will run as
  744. if [ "$(id -u)" = "0" ]; then
  745. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  746. ROOT_USER="root"
  747. else
  748. NETDATA_USER="${USER}"
  749. ROOT_USER="${USER}"
  750. fi
  751. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}" 2> /dev/null)"
  752. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  753. echo >&2 "Netdata user and group set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  754. prepare_cmake_options
  755. if [ -n "${NETDATA_PREPARE_ONLY}" ]; then
  756. progress "Exiting before building Netdata as requested."
  757. printf "Would have used the following CMake command line for configuration: %s\n" "${cmake} ${NETDATA_CMAKE_OPTIONS}"
  758. trap - EXIT
  759. exit 0
  760. fi
  761. # Let cmake know we don't want to link shared libs
  762. if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
  763. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DBUILD_SHARED_LIBS=Off"
  764. fi
  765. # shellcheck disable=SC2086
  766. if ! run ${cmake} ${NETDATA_CMAKE_OPTIONS}; then
  767. fatal "Failed to configure Netdata sources." I000A
  768. fi
  769. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  770. # remove the build_error hook
  771. trap - EXIT
  772. # -----------------------------------------------------------------------------
  773. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
  774. # -----------------------------------------------------------------------------
  775. progress "Compile netdata"
  776. # shellcheck disable=SC2086
  777. if ! run ${cmake} --build "${NETDATA_BUILD_DIR}" --parallel ${JOBS} -- ${BUILD_OPTS}; then
  778. fatal "Failed to build Netdata." I000B
  779. fi
  780. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  781. # -----------------------------------------------------------------------------
  782. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
  783. # -----------------------------------------------------------------------------
  784. progress "Install netdata"
  785. if ! cmake_install "${NETDATA_BUILD_DIR}"; then
  786. fatal "Failed to install Netdata." I000C
  787. fi
  788. # -----------------------------------------------------------------------------
  789. progress "Creating standard user and groups for netdata"
  790. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  791. NETDATA_ADDED_TO_GROUPS=""
  792. if [ "$(id -u)" -eq 0 ]; then
  793. progress "Adding group 'netdata'"
  794. portable_add_group netdata || :
  795. progress "Adding user 'netdata'"
  796. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  797. progress "Assign user 'netdata' to required groups"
  798. for g in ${NETDATA_WANTED_GROUPS}; do
  799. # shellcheck disable=SC2086
  800. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  801. done
  802. # Netdata must be able to read /etc/pve/qemu-server/* and /etc/pve/lxc/*
  803. # for reading VMs/containers names, CPU and memory limits on Proxmox.
  804. if [ -d "/etc/pve" ]; then
  805. portable_add_user_to_group "www-data" netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} www-data"
  806. fi
  807. else
  808. run_failed "The installer does not run as root. Nothing to do for user and groups"
  809. fi
  810. # -----------------------------------------------------------------------------
  811. progress "Install logrotate configuration for netdata"
  812. install_netdata_logrotate
  813. # -----------------------------------------------------------------------------
  814. progress "Read installation options from netdata.conf"
  815. # create an empty config if it does not exist
  816. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  817. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  818. # port
  819. defport=19999
  820. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  821. # directories
  822. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  823. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  824. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  825. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  826. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  827. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  828. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  829. NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
  830. cat << OPTIONSEOF
  831. Permissions
  832. - netdata user : ${NETDATA_USER}
  833. - netdata group : ${NETDATA_GROUP}
  834. - root user : ${ROOT_USER}
  835. Directories
  836. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  837. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  838. - netdata log dir : ${NETDATA_LOG_DIR}
  839. - netdata run dir : ${NETDATA_RUN_DIR}
  840. - netdata lib dir : ${NETDATA_LIB_DIR}
  841. - netdata web dir : ${NETDATA_WEB_DIR}
  842. - netdata cache dir : ${NETDATA_CACHE_DIR}
  843. Other
  844. - netdata port : ${NETDATA_PORT}
  845. OPTIONSEOF
  846. # -----------------------------------------------------------------------------
  847. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  848. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  849. # this is needed if NETDATA_PREFIX is not empty
  850. if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
  851. warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
  852. fi
  853. fi
  854. # --- stock conf dir ----
  855. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  856. [ -L "${NETDATA_USER_CONFIG_DIR}/orig" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/orig"
  857. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/orig"
  858. # --- web dir ----
  859. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  860. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  861. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  862. fi
  863. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  864. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  865. # --- data dirs ----
  866. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  867. if [ ! -d "${x}" ]; then
  868. echo >&2 "Creating directory '${x}'"
  869. if ! run mkdir -p "${x}"; then
  870. warning "Failed to create ${x}, it must be created by hand or the Netdata Agent will not be able to be started."
  871. fi
  872. fi
  873. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  874. #run find "${x}" -type f -exec chmod 0660 {} \;
  875. #run find "${x}" -type d -exec chmod 0770 {} \;
  876. done
  877. run chmod 755 "${NETDATA_LOG_DIR}"
  878. # --- claiming dir ----
  879. if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
  880. echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
  881. if ! run mkdir -p "${NETDATA_CLAIMING_DIR}"; then
  882. warning "failed to create ${NETDATA_CLAIMING_DIR}, it will need to be created manually."
  883. fi
  884. fi
  885. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
  886. run chmod 770 "${NETDATA_CLAIMING_DIR}"
  887. # --- plugins ----
  888. if [ "$(id -u)" -eq 0 ]; then
  889. # find the admin group
  890. admin_group=
  891. test -z "${admin_group}" && get_group root > /dev/null 2>&1 && admin_group="root"
  892. test -z "${admin_group}" && get_group daemon > /dev/null 2>&1 && admin_group="daemon"
  893. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  894. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  895. run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  896. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  897. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  898. # shellcheck disable=SC2086
  899. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
  900. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  901. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  902. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  903. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  904. capabilities=0
  905. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  906. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  907. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  908. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  909. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  910. fi
  911. fi
  912. if [ $capabilities -eq 0 ]; then
  913. # fix apps.plugin to be setuid to root
  914. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  915. fi
  916. fi
  917. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" ]; then
  918. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  919. capabilities=0
  920. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  921. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  922. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"; then
  923. # if we managed to setcap, but we fail to execute debugfs.plugin setuid to root
  924. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  925. fi
  926. fi
  927. if [ $capabilities -eq 0 ]; then
  928. # fix debugfs.plugin to be setuid to root
  929. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  930. fi
  931. fi
  932. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin" ]; then
  933. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  934. capabilities=0
  935. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  936. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  937. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"; then
  938. capabilities=1
  939. fi
  940. fi
  941. if [ $capabilities -eq 0 ]; then
  942. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  943. fi
  944. fi
  945. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin" ]; then
  946. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  947. capabilities=0
  948. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  949. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  950. if run setcap cap_dac_read_search,cap_syslog+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"; then
  951. capabilities=1
  952. fi
  953. fi
  954. if [ $capabilities -eq 0 ]; then
  955. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  956. fi
  957. fi
  958. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  959. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  960. capabilities=0
  961. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  962. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  963. 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
  964. capabilities=1
  965. fi
  966. fi
  967. if [ $capabilities -eq 0 ]; then
  968. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  969. fi
  970. fi
  971. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
  972. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  973. capabilities=0
  974. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  975. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  976. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"; then
  977. capabilities=1
  978. fi
  979. fi
  980. if [ $capabilities -eq 0 ]; then
  981. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  982. fi
  983. fi
  984. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  985. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  986. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  987. fi
  988. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  989. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  990. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  991. fi
  992. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  993. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  994. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  995. fi
  996. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  997. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  998. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  999. fi
  1000. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
  1001. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1002. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1003. fi
  1004. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  1005. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1006. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1007. fi
  1008. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  1009. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1010. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1011. fi
  1012. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners" ]; then
  1013. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  1014. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  1015. fi
  1016. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin" ]; then
  1017. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
  1018. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
  1019. fi
  1020. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo" ]; then
  1021. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  1022. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  1023. fi
  1024. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin" ]; then
  1025. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1026. capabilities=1
  1027. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1028. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1029. 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
  1030. capabilities=0
  1031. fi
  1032. fi
  1033. if [ $capabilities -eq 0 ]; then
  1034. # fix go.d.plugin to be setuid to root
  1035. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1036. fi
  1037. fi
  1038. else
  1039. # non-privileged user installation
  1040. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  1041. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1042. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  1043. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1044. fi
  1045. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1046. should_install_ebpf() {
  1047. if [ "${NETDATA_DISABLE_EBPF:=0}" -eq 1 ]; then
  1048. run_failed "eBPF has been explicitly disabled, it will not be available in this install."
  1049. return 1
  1050. fi
  1051. if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
  1052. if [ "${NETDATA_DISABLE_EBPF:=1}" -eq 0 ]; then
  1053. run_failed "Currently eBPF is only supported on Linux on X86_64."
  1054. fi
  1055. return 1
  1056. fi
  1057. # Check Kernel Config
  1058. if ! run "${INSTALLER_DIR}"/packaging/check-kernel-config.sh; then
  1059. warning "Kernel unsupported or missing required config (eBPF may not work on your system)"
  1060. fi
  1061. return 0
  1062. }
  1063. remove_old_ebpf() {
  1064. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin" ]; then
  1065. echo >&2 "Removing alpha eBPF collector."
  1066. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin"
  1067. fi
  1068. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf" ]; then
  1069. echo >&2 "Removing alpha eBPF stock file"
  1070. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf"
  1071. fi
  1072. if [ -f "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" ]; then
  1073. echo >&2 "Renaming eBPF configuration file."
  1074. mv "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" "${NETDATA_PREFIX}/etc/netdata/ebpf.d.conf"
  1075. fi
  1076. # Added to remove eBPF programs with name pattern: NAME_VERSION.SUBVERSION.PATCH
  1077. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.0.o" ]; then
  1078. echo >&2 "Removing old eBPF programs with patch."
  1079. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.*.o
  1080. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.*.o
  1081. fi
  1082. # Remove old eBPF program to store new eBPF program inside subdirectory
  1083. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.o" ]; then
  1084. echo >&2 "Removing old eBPF programs installed in old directory."
  1085. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.o
  1086. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.o
  1087. fi
  1088. # Remove old eBPF programs that did not have "rhf" suffix
  1089. if [ ! -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/pnetdata_ebpf_process.3.10.rhf.o" ]; then
  1090. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/"*.o
  1091. fi
  1092. # Remove old reject list from previous directory
  1093. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt" ]; then
  1094. echo >&2 "Removing old ebpf_kernel_reject_list.txt."
  1095. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt"
  1096. fi
  1097. # Remove old reset script
  1098. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh" ]; then
  1099. echo >&2 "Removing old reset_netdata_trace.sh."
  1100. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh"
  1101. fi
  1102. }
  1103. install_ebpf() {
  1104. if ! should_install_ebpf; then
  1105. return 0
  1106. fi
  1107. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing eBPF code."
  1108. remove_old_ebpf
  1109. progress "Installing eBPF plugin"
  1110. # Detect libc
  1111. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  1112. EBPF_VERSION="$(cat packaging/ebpf.version)"
  1113. EBPF_TARBALL="netdata-kernel-collector-${libc}-${EBPF_VERSION}.tar.xz"
  1114. tmp="$(mktemp -d -t netdata-ebpf-XXXXXX)"
  1115. if ! fetch_and_verify "ebpf" \
  1116. "https://github.com/netdata/kernel-collector/releases/download/${EBPF_VERSION}/${EBPF_TARBALL}" \
  1117. "${EBPF_TARBALL}" \
  1118. "${tmp}" \
  1119. "${NETDATA_LOCAL_TARBALL_OVERRIDE_EBPF}"; then
  1120. run_failed "Failed to download eBPF collector package"
  1121. echo 2>&" Removing temporary directory ${tmp} ..."
  1122. rm -rf "${tmp}"
  1123. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1124. return 1
  1125. fi
  1126. echo >&2 " Extracting ${EBPF_TARBALL} ..."
  1127. tar --no-same-owner -xf "${tmp}/${EBPF_TARBALL}" -C "${tmp}"
  1128. # chown everything to root:netdata before we start copying out of our package
  1129. run chown -R root:netdata "${tmp}"
  1130. if [ ! -d "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d ]; then
  1131. mkdir "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1132. RET=$?
  1133. if [ "${RET}" != "0" ]; then
  1134. rm -rf "${tmp}"
  1135. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1136. return 1
  1137. fi
  1138. fi
  1139. run cp -a -v "${tmp}"/*netdata_ebpf_*.o "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1140. rm -rf "${tmp}"
  1141. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1142. }
  1143. progress "eBPF Kernel Collector"
  1144. install_ebpf
  1145. should_install_fluentbit() {
  1146. if [ "$(uname -s)" = "Darwin" ]; then
  1147. return 1
  1148. fi
  1149. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  1150. warning "netdata-installer.sh run with --disable-logsmanagement, Fluent-Bit installation is skipped."
  1151. return 1
  1152. elif [ "${FLUENT_BIT_BUILD_SUCCESS:=0}" -eq 0 ]; then
  1153. run_failed "Fluent-Bit was not built successfully, Netdata Logs Management support will be disabled in this build."
  1154. return 1
  1155. elif [ ! -f src/fluent-bit/build/lib/libfluent-bit.so ]; then
  1156. run_failed "libfluent-bit.so is missing, Netdata Logs Management support will be disabled in this build."
  1157. return 1
  1158. fi
  1159. return 0
  1160. }
  1161. install_fluentbit() {
  1162. if ! should_install_fluentbit; then
  1163. enable_feature PLUGIN_LOGS_MANAGEMENT 0
  1164. return 0
  1165. fi
  1166. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Fluent-Bit."
  1167. run chown "root:${NETDATA_GROUP}" src/fluent-bit/build/lib
  1168. run chmod 0644 src/fluent-bit/build/lib/libfluent-bit.so
  1169. run cp -a -v src/fluent-bit/build/lib/libfluent-bit.so "${NETDATA_PREFIX}"/usr/lib/netdata
  1170. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1171. }
  1172. progress "Installing Fluent-Bit plugin"
  1173. install_fluentbit
  1174. # -----------------------------------------------------------------------------
  1175. progress "Telemetry configuration"
  1176. # Opt-out from telemetry program
  1177. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  1178. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  1179. else
  1180. 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"
  1181. fi
  1182. # -----------------------------------------------------------------------------
  1183. progress "Install netdata at system init"
  1184. # By default we assume the shutdown/startup of the Netdata Agent are effectively
  1185. # without any system supervisor/init like SystemD or SysV. So we assume the most
  1186. # basic startup/shutdown commands...
  1187. NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
  1188. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  1189. if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
  1190. # If docker runs systemd for some weird reason, let the install proceed
  1191. is_systemd_running="NO"
  1192. if command -v pidof > /dev/null 2>&1; then
  1193. is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
  1194. else
  1195. is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
  1196. fi
  1197. if [ "${is_systemd_running}" = "1" ]; then
  1198. echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
  1199. install_netdata_service || run_failed "Cannot install netdata init service."
  1200. else
  1201. echo >&2 "We are running within a docker container, will not be installing netdata service"
  1202. fi
  1203. echo >&2
  1204. else
  1205. install_netdata_service || run_failed "Cannot install netdata init service."
  1206. fi
  1207. # -----------------------------------------------------------------------------
  1208. # check if we can re-start netdata
  1209. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  1210. started=0
  1211. if [ ${DONOTSTART} -eq 1 ]; then
  1212. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1213. else
  1214. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  1215. fatal "Cannot start netdata!" I000D
  1216. fi
  1217. started=1
  1218. run_ok "netdata started!"
  1219. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  1220. fi
  1221. run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1222. if [ "$(uname)" = "Linux" ]; then
  1223. # -------------------------------------------------------------------------
  1224. progress "Check KSM (kernel memory deduper)"
  1225. ksm_is_available_but_disabled() {
  1226. cat << KSM1
  1227. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  1228. You have kernel memory de-duper (called Kernel Same-page Merging,
  1229. or KSM) available, but it is not currently enabled.
  1230. To enable it run:
  1231. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  1232. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  1233. If you enable it, you will save 40-60% of netdata memory.
  1234. KSM1
  1235. }
  1236. ksm_is_not_available() {
  1237. cat << KSM2
  1238. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  1239. It seems you do not have kernel memory de-duper (called Kernel Same-page
  1240. Merging, or KSM) available.
  1241. To enable it, you need a kernel built with CONFIG_KSM=y
  1242. If you can have it, you will save 40-60% of netdata memory.
  1243. KSM2
  1244. }
  1245. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  1246. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  1247. ksm_is_available_but_disabled
  1248. fi
  1249. else
  1250. ksm_is_not_available
  1251. fi
  1252. fi
  1253. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1254. # -----------------------------------------------------------------------------
  1255. progress "Check apps.plugin"
  1256. if [ "$(id -u)" -ne 0 ]; then
  1257. cat << SETUID_WARNING
  1258. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  1259. Since you have installed netdata as a normal user, to have apps.plugin collect
  1260. all the needed data, you have to give it the access rights it needs, by running
  1261. either of the following sets of commands:
  1262. To run apps.plugin with escalated capabilities:
  1263. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1264. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1265. ${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}
  1266. or, to run apps.plugin as root:
  1267. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1268. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1269. apps.plugin is performing a hard-coded function of data collection for all
  1270. running processes. It cannot be instructed from the netdata daemon to perform
  1271. any task, so it is pretty safe to do this.
  1272. SETUID_WARNING
  1273. fi
  1274. fi
  1275. # -----------------------------------------------------------------------------
  1276. progress "Copy uninstaller"
  1277. if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
  1278. echo >&2 "Removing uninstaller from old location"
  1279. rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
  1280. fi
  1281. 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"
  1282. chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  1283. # -----------------------------------------------------------------------------
  1284. progress "Basic netdata instructions"
  1285. cat << END
  1286. netdata by default listens on all IPs on port ${NETDATA_PORT},
  1287. so you can access it with:
  1288. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  1289. To stop netdata run:
  1290. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  1291. To start netdata run:
  1292. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  1293. END
  1294. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
  1295. echo >&2
  1296. # -----------------------------------------------------------------------------
  1297. progress "Installing (but not enabling) the netdata updater tool"
  1298. install_netdata_updater || run_failed "Cannot install netdata updater tool."
  1299. # -----------------------------------------------------------------------------
  1300. progress "Wrap up environment set up"
  1301. # Save environment variables
  1302. echo >&2 "Preparing .environment file"
  1303. cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  1304. # Created by installer
  1305. PATH="${PATH}"
  1306. CFLAGS="${CFLAGS}"
  1307. LDFLAGS="${LDFLAGS}"
  1308. MAKEOPTS="${MAKEOPTS}"
  1309. NETDATA_TMPDIR="${TMPDIR}"
  1310. NETDATA_PREFIX="${NETDATA_PREFIX}"
  1311. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS}"
  1312. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  1313. INSTALL_UID="$(id -u)"
  1314. NETDATA_GROUP="${NETDATA_GROUP}"
  1315. REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
  1316. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  1317. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
  1318. NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
  1319. EOF
  1320. run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
  1321. echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
  1322. cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  1323. new_installation
  1324. EOF
  1325. print_deferred_errors
  1326. # -----------------------------------------------------------------------------
  1327. echo >&2
  1328. progress "We are done!"
  1329. if [ ${started} -eq 1 ]; then
  1330. netdata_banner
  1331. progress "is installed and running now!"
  1332. else
  1333. netdata_banner
  1334. progress "is installed now!"
  1335. fi
  1336. echo >&2 " enjoy real-time performance and health monitoring..."
  1337. echo >&2
  1338. exit 0