netdata-installer.sh 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114
  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. download_go() {
  87. download_file "${1}" "${2}" "go.d plugin" "go"
  88. }
  89. # make sure we save all commands we run
  90. # Variable is used by code in the packaging/installer/functions.sh
  91. # shellcheck disable=SC2034
  92. run_logfile="netdata-installer.log"
  93. # -----------------------------------------------------------------------------
  94. # fix PKG_CHECK_MODULES error
  95. if [ -d /usr/share/aclocal ]; then
  96. ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
  97. export ACLOCAL_PATH
  98. fi
  99. export LC_ALL=C
  100. umask 002
  101. # Be nice on production environments
  102. renice 19 $$ > /dev/null 2> /dev/null
  103. # you can set CFLAGS before running installer
  104. # shellcheck disable=SC2269
  105. LDFLAGS="${LDFLAGS}"
  106. CFLAGS="${CFLAGS-"-O2 -pipe"}"
  107. [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
  108. # shellcheck disable=SC2269
  109. ACLK="${ACLK}"
  110. # keep a log of this command
  111. {
  112. printf "\n# "
  113. date
  114. printf 'CFLAGS="%s" ' "${CFLAGS}"
  115. printf 'LDFLAGS="%s" ' "${LDFLAGS}"
  116. printf "%s" "${PROGRAM}" "${@}"
  117. printf "\n"
  118. } >> netdata-installer.log
  119. REINSTALL_OPTIONS="$(
  120. printf "%s" "${*}"
  121. printf "\n"
  122. )"
  123. # remove options that shown not be inherited by netdata-updater.sh
  124. REINSTALL_OPTIONS="$(echo "${REINSTALL_OPTIONS}" | sed 's/--dont-wait//g' | sed 's/--dont-start-it//g')"
  125. banner_nonroot_install() {
  126. cat << NONROOTNOPREFIX
  127. ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
  128. You are attempting to install netdata as a non-root user, but you plan
  129. to install it in system paths.
  130. Please set an installation prefix, like this:
  131. $PROGRAM ${@} --install-prefix /tmp
  132. or, run the installer as root:
  133. sudo $PROGRAM ${@}
  134. We suggest to install it as root, or certain data collectors will
  135. not be able to work. Netdata drops root privileges when running.
  136. So, if you plan to keep it, install it as root to get the full
  137. functionality.
  138. NONROOTNOPREFIX
  139. }
  140. banner_root_notify() {
  141. cat << NONROOT
  142. ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
  143. You are about to install netdata as a non-root user.
  144. Netdata will work, but a few data collection modules that
  145. require root access will fail.
  146. If you are installing netdata permanently on your system, run
  147. the installer like this:
  148. ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
  149. NONROOT
  150. }
  151. usage() {
  152. netdata_banner
  153. progress "installer command line options"
  154. cat << HEREDOC
  155. USAGE: ${PROGRAM} [options]
  156. where options include:
  157. --install-prefix <path> Install netdata in <path>. Ex. --install-prefix /opt will put netdata in /opt/netdata.
  158. --dont-start-it Do not (re)start netdata after installation.
  159. --dont-wait Run installation in non-interactive mode.
  160. --stable-channel Use packages from GitHub release pages instead of nightly updates.
  161. This results in less frequent updates.
  162. --nightly-channel Use most recent nightly updates instead of GitHub releases.
  163. This results in more frequent updates.
  164. --disable-go Disable installation of go.d.plugin.
  165. --disable-ebpf Disable eBPF Kernel plugin. Default: enabled.
  166. --disable-cloud Disable all Netdata Cloud functionality.
  167. --require-cloud Fail the install if it can't build Netdata Cloud support.
  168. --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
  169. --disable-plugin-freeipmi Explicitly disable the FreeIPMI plugin.
  170. --disable-https Explicitly disable TLS support.
  171. --disable-dbengine Explicitly disable DB engine support.
  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 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. Netdata will by default be compiled with gcc optimization -O2
  203. If you need to pass different CFLAGS, use something like this:
  204. CFLAGS="<gcc options>" ${PROGRAM} [options]
  205. If you also need to provide different LDFLAGS, use something like this:
  206. LDFLAGS="<extra ldflag options>" ${PROGRAM} [options]
  207. or use the following if both LDFLAGS and CFLAGS need to be overridden:
  208. CFLAGS="<gcc options>" LDFLAGS="<extra ld options>" ${PROGRAM} [options]
  209. For the installer to complete successfully, you will need these packages installed:
  210. gcc
  211. make
  212. autoconf
  213. automake
  214. pkg-config
  215. zlib1g-dev (or zlib-devel)
  216. uuid-dev (or libuuid-devel)
  217. For the plugins, you will at least need:
  218. curl
  219. bash (v4+)
  220. python (v2 or v3)
  221. node.js
  222. HEREDOC
  223. }
  224. DONOTSTART=0
  225. DONOTWAIT=0
  226. NETDATA_PREFIX=
  227. LIBS_ARE_HERE=0
  228. NETDATA_ENABLE_ML=""
  229. ENABLE_DBENGINE=1
  230. ENABLE_EBPF=1
  231. ENABLE_H2O=1
  232. ENABLE_CLOUD=1
  233. ENABLE_LOGS_MANAGEMENT=1
  234. ENABLE_LOGS_MANAGEMENT_TESTS=0
  235. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS-}"
  236. RELEASE_CHANNEL="nightly" # valid values are 'nightly' and 'stable'
  237. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY:-"no"}"
  238. while [ -n "${1}" ]; do
  239. case "${1}" in
  240. "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
  241. "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
  242. "--use-system-protobuf") USE_SYSTEM_PROTOBUF=1 ;;
  243. "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
  244. "--dont-start-it") DONOTSTART=1 ;;
  245. "--dont-wait") DONOTWAIT=1 ;;
  246. "--auto-update" | "-u") ;;
  247. "--auto-update-type") ;;
  248. "--stable-channel") RELEASE_CHANNEL="stable" ;;
  249. "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
  250. "--enable-plugin-freeipmi") ENABLE_FREEIPMI=1 ;;
  251. "--disable-plugin-freeipmi") ENABLE_FREEIPMI=0 ;;
  252. "--disable-https")
  253. ENABLE_DBENGINE=0
  254. ENABLE_H2O=0
  255. ENABLE_CLOUD=0
  256. ;;
  257. "--disable-dbengine") ENABLE_DBENGINE=0 ;;
  258. "--enable-plugin-nfacct") ENABLE_NFACCT=1 ;;
  259. "--disable-plugin-nfacct") ENABLE_NFACCT=0 ;;
  260. "--enable-plugin-xenstat") ENABLE_XENSTAT=1 ;;
  261. "--disable-plugin-xenstat") ENABLE_XENSTAT=0 ;;
  262. "--enable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=1 ;;
  263. "--disable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=0 ;;
  264. "--enable-exporting-kinesis" | "--enable-backend-kinesis")
  265. # TODO: Needs CMake Support
  266. ;;
  267. "--disable-exporting-kinesis" | "--disable-backend-kinesis")
  268. # TODO: Needs CMake Support
  269. ;;
  270. "--enable-exporting-prometheus-remote-write" | "--enable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=1 ;;
  271. "--disable-exporting-prometheus-remote-write" | "--disable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=0 ;;
  272. "--enable-exporting-mongodb" | "--enable-backend-mongodb") EXPORTER_MONGODB=1 ;;
  273. "--disable-exporting-mongodb" | "--disable-backend-mongodb") EXPORTER_MONGODB=0 ;;
  274. "--enable-exporting-pubsub")
  275. # TODO: Needs CMake support
  276. ;;
  277. "--disable-exporting-pubsub")
  278. # TODO: Needs CMake support
  279. ;;
  280. "--enable-ml") NETDATA_ENABLE_ML=1 ;;
  281. "--disable-ml") NETDATA_ENABLE_ML=0 ;;
  282. "--enable-lto")
  283. # TODO: Needs CMake support
  284. ;;
  285. "--enable-logs-management") ENABLE_LOGS_MANAGEMENT=1 ;;
  286. "--disable-logsmanagement") ENABLE_LOGS_MANAGEMENT=0 ;;
  287. "--enable-logsmanagement-tests") ENABLE_LOGS_MANAGEMENT_TESTS=1 ;;
  288. "--disable-lto")
  289. # TODO: Needs CMake support
  290. ;;
  291. "--disable-x86-sse")
  292. # XXX: No longer supported.
  293. ;;
  294. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
  295. "--disable-go") NETDATA_DISABLE_GO=1 ;;
  296. "--enable-ebpf")
  297. ENABLE_EBPF=1
  298. NETDATA_DISABLE_EBPF=0
  299. ;;
  300. "--disable-ebpf")
  301. ENABLE_EBPF=0
  302. NETDATA_DISABLE_EBPF=1
  303. ;;
  304. "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
  305. "--one-time-build")
  306. # XXX: No longer supported
  307. ;;
  308. "--disable-cloud")
  309. if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
  310. warning "Cloud explicitly enabled, ignoring --disable-cloud."
  311. else
  312. ENABLE_CLOUD=0
  313. NETDATA_DISABLE_CLOUD=1
  314. fi
  315. ;;
  316. "--require-cloud")
  317. if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
  318. warning "Cloud explicitly disabled, ignoring --require-cloud."
  319. else
  320. ENABLE_CLOUD=1
  321. NETDATA_REQUIRE_CLOUD=1
  322. fi
  323. ;;
  324. "--build-json-c")
  325. NETDATA_BUILD_JSON_C=1
  326. ;;
  327. "--install-prefix")
  328. NETDATA_PREFIX="${2}/netdata"
  329. shift 1
  330. ;;
  331. "--install-no-prefix")
  332. NETDATA_PREFIX="${2}"
  333. shift 1
  334. ;;
  335. "--prepare-only")
  336. NETDATA_DISABLE_TELEMETRY=1
  337. NETDATA_PREPARE_ONLY=1
  338. DONOTWAIT=1
  339. ;;
  340. "--help" | "-h")
  341. usage
  342. exit 1
  343. ;;
  344. *)
  345. echo >&2 "Unrecognized option '${1}'."
  346. exit_reason "Unrecognized option '${1}'." I000E
  347. usage
  348. exit 1
  349. ;;
  350. esac
  351. shift 1
  352. done
  353. if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
  354. [ -n "$DISABLE_TELEMETRY" ] ||
  355. [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
  356. [ -n "$DO_NOT_TRACK" ]; then
  357. NETDATA_DISABLE_TELEMETRY=1
  358. fi
  359. if [ -n "${MAKEOPTS}" ]; then
  360. JOBS="$(echo "${MAKEOPTS}" | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
  361. else
  362. JOBS="$(find_processors)"
  363. fi
  364. if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
  365. mega="$((1024 * 1024))"
  366. base=1024
  367. scale=256
  368. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  369. total_ram="$(grep MemTotal /proc/meminfo | cut -d ':' -f 2 | tr -d ' kB')"
  370. total_ram="$((total_ram * 1024))"
  371. if [ "${total_ram}" -le "$((base * mega))" ] && [ -z "${NETDATA_ENABLE_ML}" ]; then
  372. NETDATA_ENABLE_ML=0
  373. fi
  374. if [ -z "${MAKEOPTS}" ]; then
  375. MAKEOPTS="-j${JOBS}"
  376. while [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ]; do
  377. JOBS="$((JOBS - 1))"
  378. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  379. MAKEOPTS="-j${JOBS}"
  380. done
  381. else
  382. if [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
  383. target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  384. total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  385. 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."
  386. exit_reason "Insufficient RAM to safely install." I000F
  387. exit 2
  388. fi
  389. fi
  390. fi
  391. enable_feature() {
  392. NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed -e "s/-DENABLE_${1}=Off[[:space:]]*//g" -e "s/-DENABLE_${1}=On[[:space:]]*//g")"
  393. if [ "${2}" -eq 1 ]; then
  394. NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed "s/$/ -DENABLE_${1}=On/")"
  395. else
  396. NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed "s/$/ -DENABLE_${1}=Off/")"
  397. fi
  398. }
  399. # set default make options
  400. if [ -z "${MAKEOPTS}" ]; then
  401. MAKEOPTS="-j$(find_processors)"
  402. elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
  403. MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
  404. fi
  405. if [ "$(id -u)" -ne 0 ] && [ -z "${NETDATA_PREPARE_ONLY}" ]; then
  406. if [ -z "${NETDATA_PREFIX}" ]; then
  407. netdata_banner
  408. banner_nonroot_install "${@}"
  409. exit_reason "Attempted install as non-root user to /." I0010
  410. exit 1
  411. else
  412. banner_root_notify "${@}"
  413. fi
  414. fi
  415. netdata_banner
  416. progress "real-time performance monitoring, done right!"
  417. cat << BANNER1
  418. You are about to build and install netdata to your system.
  419. The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
  420. any temporary files. You can override this by setting \$TMPDIR to a
  421. writable directory where you can execute files.
  422. It will be installed at these locations:
  423. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  424. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  425. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  426. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  427. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  428. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  429. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  430. BANNER1
  431. [ "$(id -u)" -eq 0 ] && cat << BANNER2
  432. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  433. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  434. BANNER2
  435. cat << BANNER3
  436. This installer allows you to change the installation path.
  437. Press Control-C and run the same command with --help for help.
  438. BANNER3
  439. if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
  440. cat << BANNER4
  441. ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
  442. Anonymous usage stats will be collected and sent to Netdata.
  443. To opt-out, pass --disable-telemetry option to the installer or export
  444. the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
  445. (e.g: export DISABLE_TELEMETRY=1).
  446. BANNER4
  447. fi
  448. if ! command -v cmake >/dev/null 2>&1; then
  449. fatal "Could not find CMake, which is required to build Netdata." I0012
  450. else
  451. cmake="$(command -v cmake)"
  452. progress "Found CMake at ${cmake}. CMake version: $(${cmake} --version | head -n 1)"
  453. fi
  454. if ! command -v "ninja" >/dev/null 2>&1; then
  455. progress "Could not find Ninja, will use Make instead."
  456. else
  457. ninja="$(command -v ninja)"
  458. progress "Found Ninja at ${ninja}. Ninja version: $(${ninja} --version)"
  459. progress "Will use Ninja for this build instead of Make when possible."
  460. fi
  461. make="$(command -v make 2>/dev/null)"
  462. if [ -z "${make}" ] && [ -z "${ninja}" ]; then
  463. fatal "Could not find a usable underlying build system (we support make and ninja)." I0014
  464. fi
  465. CMAKE_OPTS="${ninja:+-G Ninja}"
  466. BUILD_OPTS="VERBOSE=1"
  467. [ -n "${ninja}" ] && BUILD_OPTS="-v"
  468. if [ ${DONOTWAIT} -eq 0 ]; then
  469. if [ -n "${NETDATA_PREFIX}" ]; then
  470. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  471. else
  472. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  473. fi
  474. read -r REPLY
  475. if [ "$REPLY" != '' ]; then
  476. exit_reason "User did not accept install attempt." I0011
  477. exit 1
  478. fi
  479. fi
  480. cmake_install() {
  481. # run cmake --install ${1}
  482. # The above command should be used to replace the logic below once we no longer support
  483. # versions of CMake less than 3.15.
  484. if [ -n "${ninja}" ]; then
  485. run ${ninja} -C "${1}" install
  486. else
  487. run ${make} -C "${1}" install
  488. fi
  489. }
  490. build_error() {
  491. netdata_banner
  492. trap - EXIT
  493. fatal "Netdata failed to build for an unknown reason." I0002
  494. }
  495. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  496. shift
  497. echo >&2 "ok, assuming libs are really installed."
  498. export ZLIB_CFLAGS=" "
  499. export ZLIB_LIBS="-lz"
  500. export UUID_CFLAGS=" "
  501. export UUID_LIBS="-luuid"
  502. fi
  503. trap build_error EXIT
  504. # -----------------------------------------------------------------------------
  505. build_protobuf() {
  506. env_cmd=''
  507. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  508. env_cmd="env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  509. fi
  510. cd "${1}" > /dev/null || return 1
  511. if ! run eval "${env_cmd} ./configure --disable-shared --without-zlib --disable-dependency-tracking --with-pic"; then
  512. cd - > /dev/null || return 1
  513. return 1
  514. fi
  515. if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
  516. cd - > /dev/null || return 1
  517. return 1
  518. fi
  519. cd - > /dev/null || return 1
  520. }
  521. copy_protobuf() {
  522. target_dir="${PWD}/externaldeps/protobuf"
  523. run mkdir -p "${target_dir}" || return 1
  524. run cp -a "${1}/src" "${target_dir}" || return 1
  525. }
  526. bundle_protobuf() {
  527. if [ -n "${NETDATA_DISABLE_CLOUD}" ] && [ -n "${EXPORTER_PROMETHEUS}" ] && [ "${EXPORTER_PROMETHEUS}" -eq 0 ]; then
  528. echo "Skipping protobuf"
  529. return 0
  530. fi
  531. if [ -n "${USE_SYSTEM_PROTOBUF}" ]; then
  532. echo "Skipping protobuf"
  533. warning "You have requested use of a system copy of protobuf. This should work, but it is not recommended as it's very likely to break if you upgrade the currently installed version of protobuf."
  534. return 0
  535. fi
  536. if [ -z "${make}" ]; then
  537. warning "No usable copy of Make found, which is required for bundling protobuf. Attempting to use a system copy of protobuf instead."
  538. USE_SYSTEM_PROTOBUF=1
  539. return 0
  540. fi
  541. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling protobuf."
  542. PROTOBUF_PACKAGE_VERSION="$(cat packaging/protobuf.version)"
  543. if [ -f "${PWD}/externaldeps/protobuf/.version" ] && [ "${PROTOBUF_PACKAGE_VERSION}" = "$(cat "${PWD}/externaldeps/protobuf/.version")" ]
  544. then
  545. echo >&2 "Found compiled protobuf, same version, not compiling it again. Remove file '${PWD}/externaldeps/protobuf/.version' to recompile."
  546. USE_SYSTEM_PROTOBUF=0
  547. return 0
  548. fi
  549. tmp="$(mktemp -d -t netdata-protobuf-XXXXXX)"
  550. PROTOBUF_PACKAGE_BASENAME="protobuf-cpp-${PROTOBUF_PACKAGE_VERSION}.tar.gz"
  551. if fetch_and_verify "protobuf" \
  552. "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_PACKAGE_VERSION}/${PROTOBUF_PACKAGE_BASENAME}" \
  553. "${PROTOBUF_PACKAGE_BASENAME}" \
  554. "${tmp}" \
  555. "${NETDATA_LOCAL_TARBALL_VERRIDE_PROTOBUF}"; then
  556. if run tar --no-same-owner -xf "${tmp}/${PROTOBUF_PACKAGE_BASENAME}" -C "${tmp}" &&
  557. build_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
  558. copy_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
  559. echo "${PROTOBUF_PACKAGE_VERSION}" >"${PWD}/externaldeps/protobuf/.version" &&
  560. rm -rf "${tmp}"; then
  561. run_ok "protobuf built and prepared."
  562. USE_SYSTEM_PROTOBUF=0
  563. else
  564. run_failed "Failed to build protobuf. Netdata Cloud support will not be available in this build."
  565. fi
  566. else
  567. run_failed "Unable to fetch sources for protobuf. Netdata Cloud support will not be available in this build."
  568. fi
  569. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  570. }
  571. bundle_protobuf
  572. # -----------------------------------------------------------------------------
  573. build_jsonc() {
  574. env_cmd=''
  575. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  576. env_cmd="env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  577. fi
  578. cd "${1}" > /dev/null || exit 1
  579. run eval "${env_cmd} ${cmake} ${CMAKE_OPTS} -DBUILD_SHARED_LIBS=OFF -DDISABLE_WERROR=On ."
  580. run eval "${env_cmd} ${cmake} --build . --parallel ${JOBS} -- ${BUILD_OPTS}"
  581. cd - > /dev/null || return 1
  582. }
  583. copy_jsonc() {
  584. target_dir="${PWD}/externaldeps/jsonc"
  585. run mkdir -p "${target_dir}" "${target_dir}/json-c" || return 1
  586. run cp "${1}/libjson-c.a" "${target_dir}/libjson-c.a" || return 1
  587. # shellcheck disable=SC2086
  588. run cp ${1}/*.h "${target_dir}/json-c" || return 1
  589. }
  590. bundle_jsonc() {
  591. # If --build-json-c flag or not json-c on system, then bundle our own json-c
  592. if [ -z "${NETDATA_BUILD_JSON_C}" ] && pkg-config json-c; then
  593. NETDATA_BUILD_JSON_C=0
  594. return 0
  595. fi
  596. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling JSON-C."
  597. progress "Prepare JSON-C"
  598. JSONC_PACKAGE_VERSION="$(cat packaging/jsonc.version)"
  599. tmp="$(mktemp -d -t netdata-jsonc-XXXXXX)"
  600. JSONC_PACKAGE_BASENAME="json-c-${JSONC_PACKAGE_VERSION}.tar.gz"
  601. if fetch_and_verify "jsonc" \
  602. "https://github.com/json-c/json-c/archive/${JSONC_PACKAGE_BASENAME}" \
  603. "${JSONC_PACKAGE_BASENAME}" \
  604. "${tmp}" \
  605. "${NETDATA_LOCAL_TARBALL_OVERRIDE_JSONC}"; then
  606. if run tar --no-same-owner -xf "${tmp}/${JSONC_PACKAGE_BASENAME}" -C "${tmp}" &&
  607. build_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  608. copy_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  609. rm -rf "${tmp}"; then
  610. run_ok "JSON-C built and prepared."
  611. NETDATA_BUILD_JSON_C=1
  612. else
  613. run_failed "Failed to build JSON-C, Netdata Cloud support will be disabled in this build."
  614. NETDATA_BUILD_JSON_C=0
  615. ENABLE_CLOUD=0
  616. fi
  617. else
  618. run_failed "Unable to fetch sources for JSON-C, Netdata Cloud support will be disabled in this build."
  619. NETDATA_BUILD_JSON_C=0
  620. ENABLE_CLOUD=0
  621. fi
  622. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  623. }
  624. bundle_jsonc
  625. # -----------------------------------------------------------------------------
  626. build_yaml() {
  627. env_cmd=''
  628. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  629. env_cmd="env CFLAGS='-fPIC -pipe -Wno-unused-value' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  630. fi
  631. cd "${1}" > /dev/null || return 1
  632. run eval "${env_cmd} ./configure --disable-shared --disable-dependency-tracking --with-pic"
  633. run eval "${env_cmd} ${make} ${MAKEOPTS}"
  634. cd - > /dev/null || return 1
  635. }
  636. copy_yaml() {
  637. target_dir="${PWD}/externaldeps/libyaml"
  638. run mkdir -p "${target_dir}" || return 1
  639. run cp "${1}/src/.libs/libyaml.a" "${target_dir}/libyaml.a" || return 1
  640. run cp "${1}/include/yaml.h" "${target_dir}/" || return 1
  641. }
  642. bundle_yaml() {
  643. if pkg-config yaml-0.1; then
  644. BUNDLE_YAML=0
  645. return 0
  646. fi
  647. if [ -z "${make}" ]; then
  648. fatal "Need to bundle libyaml but cannot find a copy of Make to build it with. Either install development files for libyaml, or install a usable copy fo Make." I0016
  649. fi
  650. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling YAML."
  651. progress "Prepare YAML"
  652. YAML_PACKAGE_VERSION="$(cat packaging/yaml.version)"
  653. tmp="$(mktemp -d -t netdata-yaml-XXXXXX)"
  654. YAML_PACKAGE_BASENAME="yaml-${YAML_PACKAGE_VERSION}.tar.gz"
  655. if fetch_and_verify "yaml" \
  656. "https://github.com/yaml/libyaml/releases/download/${YAML_PACKAGE_VERSION}/${YAML_PACKAGE_BASENAME}" \
  657. "${YAML_PACKAGE_BASENAME}" \
  658. "${tmp}" \
  659. "${NETDATA_LOCAL_TARBALL_OVERRIDE_YAML}"; then
  660. if run tar --no-same-owner -xf "${tmp}/${YAML_PACKAGE_BASENAME}" -C "${tmp}" &&
  661. build_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
  662. copy_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
  663. rm -rf "${tmp}"; then
  664. run_ok "YAML built and prepared."
  665. BUNDLE_YAML=1
  666. else
  667. run_failed "Failed to build YAML, critical error."
  668. BUNDLE_YAML=0
  669. fi
  670. else
  671. run_failed "Unable to fetch sources for YAML, critical error."
  672. BUNDLE_YAML=0
  673. fi
  674. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  675. }
  676. bundle_yaml
  677. # -----------------------------------------------------------------------------
  678. get_kernel_version() {
  679. r="$(uname -r | cut -f 1 -d '-')"
  680. tmpfile="$(mktemp)"
  681. echo "${r}" | tr '.' ' ' > "${tmpfile}"
  682. read -r maj min patch _ < "${tmpfile}"
  683. rm -f "${tmpfile}"
  684. printf "%03d%03d%03d" "${maj}" "${min}" "${patch}"
  685. }
  686. detect_libc() {
  687. libc=
  688. if ldd --version 2>&1 | grep -q -i glibc; then
  689. echo >&2 " Detected GLIBC"
  690. libc="glibc"
  691. elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
  692. echo >&2 " Detected GLIBC"
  693. libc="glibc"
  694. elif ldd --version 2>&1 | grep -q -i musl; then
  695. echo >&2 " Detected musl"
  696. libc="musl"
  697. else
  698. cmd=$(ldd /bin/sh | grep -w libc | cut -d" " -f 3)
  699. if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
  700. echo >&2 " Detected GLIBC"
  701. libc="glibc"
  702. fi
  703. fi
  704. if [ -z "$libc" ]; then
  705. warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
  706. return 1
  707. fi
  708. echo "${libc}"
  709. return 0
  710. }
  711. build_libbpf() {
  712. cd "${1}/src" > /dev/null || return 1
  713. mkdir root build
  714. # shellcheck disable=SC2086
  715. run env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
  716. cd - > /dev/null || return 1
  717. }
  718. copy_libbpf() {
  719. target_dir="${PWD}/externaldeps/libbpf"
  720. if [ "$(uname -m)" = x86_64 ]; then
  721. lib_subdir="lib64"
  722. else
  723. lib_subdir="lib"
  724. fi
  725. run mkdir -p "${target_dir}" || return 1
  726. run cp "${1}/usr/${lib_subdir}/libbpf.a" "${target_dir}/libbpf.a" || return 1
  727. run cp -r "${1}/usr/include" "${target_dir}" || return 1
  728. run cp -r "${1}/include/uapi" "${target_dir}/include" || return 1
  729. }
  730. bundle_libbpf() {
  731. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  732. ENABLE_EBPF=0
  733. NETDATA_DISABLE_EBPF=1
  734. return 0
  735. fi
  736. if [ -z "${make}" ]; then
  737. warning "No usable copy of Make found, which is required to bundle libbpf. Disabling eBPF support."
  738. ENABLE_EBPF=0
  739. NETDATA_DISABLE_EBPF=1
  740. return 0
  741. fi
  742. # When libc is not detected, we do not have necessity to compile libbpf and we should not do download of eBPF programs
  743. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  744. if [ -z "$libc" ]; then
  745. NETDATA_DISABLE_EBPF=1
  746. ENABLE_EBPF=0
  747. return 0
  748. fi
  749. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  750. progress "Prepare libbpf"
  751. if [ "$(get_kernel_version)" -ge "004014000" ]; then
  752. LIBBPF_PACKAGE_VERSION="$(cat packaging/current_libbpf.version)"
  753. LIBBPF_PACKAGE_COMPONENT="current_libbpf"
  754. else
  755. LIBBPF_PACKAGE_VERSION="$(cat packaging/libbpf_0_0_9.version)"
  756. LIBBPF_PACKAGE_COMPONENT="libbpf_0_0_9"
  757. fi
  758. tmp="$(mktemp -d -t netdata-libbpf-XXXXXX)"
  759. LIBBPF_PACKAGE_BASENAME="v${LIBBPF_PACKAGE_VERSION}.tar.gz"
  760. if fetch_and_verify "${LIBBPF_PACKAGE_COMPONENT}" \
  761. "https://github.com/netdata/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
  762. "${LIBBPF_PACKAGE_BASENAME}" \
  763. "${tmp}" \
  764. "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBBPF}"; then
  765. if run tar --no-same-owner -xf "${tmp}/${LIBBPF_PACKAGE_BASENAME}" -C "${tmp}" &&
  766. build_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  767. copy_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  768. rm -rf "${tmp}"; then
  769. run_ok "libbpf built and prepared."
  770. ENABLE_EBPF=1
  771. else
  772. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  773. fatal "failed to build libbpf." I0005
  774. else
  775. run_failed "Failed to build libbpf. eBPF support will be disabled"
  776. ENABLE_EBPF=0
  777. NETDATA_DISABLE_EBPF=1
  778. fi
  779. fi
  780. else
  781. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  782. fatal "Failed to fetch sources for libbpf." I0006
  783. else
  784. run_failed "Unable to fetch sources for libbpf. eBPF support will be disabled"
  785. ENABLE_EBPF=0
  786. NETDATA_DISABLE_EBPF=1
  787. fi
  788. fi
  789. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  790. }
  791. bundle_libbpf
  792. copy_co_re() {
  793. cp -R "${1}/includes" "collectors/ebpf.plugin/"
  794. }
  795. bundle_ebpf_co_re() {
  796. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  797. return 0
  798. fi
  799. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  800. progress "eBPF CO-RE"
  801. CORE_PACKAGE_VERSION="$(cat packaging/ebpf-co-re.version)"
  802. tmp="$(mktemp -d -t netdata-ebpf-co-re-XXXXXX)"
  803. CORE_PACKAGE_BASENAME="netdata-ebpf-co-re-glibc-${CORE_PACKAGE_VERSION}.tar.xz"
  804. if fetch_and_verify "ebpf-co-re" \
  805. "https://github.com/netdata/ebpf-co-re/releases/download/${CORE_PACKAGE_VERSION}/${CORE_PACKAGE_BASENAME}" \
  806. "${CORE_PACKAGE_BASENAME}" \
  807. "${tmp}" \
  808. "${NETDATA_LOCAL_TARBALL_OVERRIDE_CORE}"; then
  809. if run tar --no-same-owner -xf "${tmp}/${CORE_PACKAGE_BASENAME}" -C "${tmp}" &&
  810. copy_co_re "${tmp}" &&
  811. rm -rf "${tmp}"; then
  812. run_ok "libbpf built and prepared."
  813. ENABLE_EBPF=1
  814. else
  815. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  816. fatal "Failed to get eBPF CO-RE files." I0007
  817. else
  818. run_failed "Failed to get eBPF CO-RE files. eBPF support will be disabled"
  819. NETDATA_DISABLE_EBPF=1
  820. ENABLE_EBPF=0
  821. enable_feature PLUGIN_EBPF 0
  822. fi
  823. fi
  824. else
  825. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  826. fatal "Failed to fetch eBPF CO-RE files." I0008
  827. else
  828. run_failed "Failed to fetch eBPF CO-RE files. eBPF support will be disabled"
  829. NETDATA_DISABLE_EBPF=1
  830. ENABLE_EBPF=0
  831. enable_feature PLUGIN_EBPF 0
  832. fi
  833. fi
  834. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  835. }
  836. bundle_ebpf_co_re
  837. # -----------------------------------------------------------------------------
  838. build_fluentbit() {
  839. env_cmd="env CFLAGS='-w' CXXFLAGS='-w' LDFLAGS="
  840. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  841. env_cmd="env CFLAGS='-fPIC -pipe -w' CXXFLAGS='-fPIC -pipe -w' LDFLAGS="
  842. fi
  843. mkdir -p fluent-bit/build || return 1
  844. cd fluent-bit/build > /dev/null || return 1
  845. rm CMakeCache.txt > /dev/null 2>&1
  846. if ! run eval "${env_cmd} $1 -C ../../logsmanagement/fluent_bit_build/config.cmake -B./ -S../"; then
  847. cd - > /dev/null || return 1
  848. rm -rf fluent-bit/build > /dev/null 2>&1
  849. return 1
  850. fi
  851. if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
  852. cd - > /dev/null || return 1
  853. rm -rf fluent-bit/build > /dev/null 2>&1
  854. return 1
  855. fi
  856. cd - > /dev/null || return 1
  857. }
  858. bundle_fluentbit() {
  859. progress "Prepare Fluent-Bit"
  860. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  861. warning "You have explicitly requested to disable Netdata Logs Management support, Fluent-Bit build is skipped."
  862. return 0
  863. fi
  864. if [ ! -d "fluent-bit" ]; then
  865. warning "Missing submodule Fluent-Bit. The install process will continue, but Netdata Logs Management support will be disabled."
  866. ENABLE_LOGS_MANAGEMENT=0
  867. return 0
  868. fi
  869. patch -N -p1 fluent-bit/CMakeLists.txt -i logsmanagement/fluent_bit_build/CMakeLists.patch
  870. patch -N -p1 fluent-bit/src/flb_log.c -i logsmanagement/fluent_bit_build/flb-log-fmt.patch
  871. # If musl is used, we need to patch chunkio, providing fts has been previously installed.
  872. libc="$(detect_libc)"
  873. if [ "${libc}" = "musl" ]; then
  874. patch -N -p1 fluent-bit/lib/chunkio/src/CMakeLists.txt -i logsmanagement/fluent_bit_build/chunkio-static-lib-fts.patch
  875. patch -N -p1 fluent-bit/cmake/luajit.cmake -i logsmanagement/fluent_bit_build/exclude-luajit.patch
  876. patch -N -p1 fluent-bit/src/flb_network.c -i logsmanagement/fluent_bit_build/xsi-strerror.patch
  877. fi
  878. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling Fluent-Bit."
  879. if build_fluentbit "$cmake"; then
  880. # If Fluent-Bit built with inotify support, use it.
  881. if [ "$(grep -o '^FLB_HAVE_INOTIFY:INTERNAL=.*' fluent-bit/build/CMakeCache.txt | cut -d '=' -f 2)" ]; then
  882. CFLAGS="${CFLAGS} -DFLB_HAVE_INOTIFY"
  883. fi
  884. FLUENT_BIT_BUILD_SUCCESS=1
  885. run_ok "Fluent-Bit built successfully."
  886. else
  887. warning "Failed to build Fluent-Bit, Netdata Logs Management support will be disabled in this build."
  888. ENABLE_LOGS_MANAGEMENT=0
  889. fi
  890. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  891. }
  892. bundle_fluentbit
  893. # -----------------------------------------------------------------------------
  894. # If we have the dashboard switching logic, make sure we're on the classic
  895. # dashboard during the install (updates don't work correctly otherwise).
  896. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
  897. "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
  898. fi
  899. # -----------------------------------------------------------------------------
  900. # By default, `git` does not update local tags based on remotes. Because
  901. # we use the most recent tag as part of our version determination in
  902. # our build, this can lead to strange versions that look ancient but are
  903. # actually really recent. To avoid this, try and fetch tags if we're
  904. # working in a git checkout.
  905. if [ -d ./.git ] ; then
  906. echo >&2
  907. progress "Updating tags in git to ensure a consistent version number"
  908. run git fetch -t || true
  909. fi
  910. # -----------------------------------------------------------------------------
  911. echo >&2
  912. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
  913. NETDATA_BUILD_DIR="${NETDATA_BUILD_DIR:-./cmake-build-release/}"
  914. rm -rf "${NETDATA_BUILD_DIR}"
  915. check_for_module() {
  916. if [ -z "${pkgconf}" ]; then
  917. pkgconf="$(command -v pkgconf 2>/dev/null)"
  918. [ -z "${pkgconf}" ] && pkgconf="$(command -v pkg-config 2>/dev/null)"
  919. [ -z "${pkgconf}" ] && fatal "Unable to find a usable pkgconf/pkg-config command, cannot build Netdata." I0013
  920. fi
  921. "${pkgconf}" "${1}"
  922. return "${?}"
  923. }
  924. check_for_feature() {
  925. feature_name="${1}"
  926. feature_state="${2}"
  927. shift 2
  928. feature_modules="${*}"
  929. if [ -z "${feature_state}" ]; then
  930. # shellcheck disable=SC2086
  931. if check_for_module ${feature_modules}; then
  932. enable_feature "${feature_name}" 1
  933. else
  934. enable_feature "${feature_name}" 0
  935. fi
  936. else
  937. enable_feature "${feature_name}" "${feature_state}"
  938. fi
  939. }
  940. # function to extract values from the config file
  941. config_option() {
  942. section="${1}"
  943. key="${2}"
  944. value="${3}"
  945. if [ -x "${NETDATA_PREFIX}/usr/sbin/netdata" ] && [ -r "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  946. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  947. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  948. -W get "${section}" "${key}" "${value}" ||
  949. echo "${value}"
  950. else
  951. echo "${value}"
  952. fi
  953. }
  954. # the user netdata will run as
  955. if [ "$(id -u)" = "0" ]; then
  956. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  957. ROOT_USER="root"
  958. else
  959. NETDATA_USER="${USER}"
  960. ROOT_USER="${USER}"
  961. fi
  962. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}" 2> /dev/null)"
  963. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  964. echo >&2 "Netdata user and group set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  965. NETDATA_CMAKE_OPTIONS="-S ./ -B ${NETDATA_BUILD_DIR} ${CMAKE_OPTS} -DCMAKE_INSTALL_PREFIX=${NETDATA_PREFIX} ${NETDATA_USER:+-DNETDATA_USER=${NETDATA_USER}} ${NETDATA_CMAKE_OPTIONS} "
  966. # Feature autodetection code starts here
  967. if [ "${USE_SYSTEM_PROTOBUF}" -eq 1 ]; then
  968. enable_feature BUNDLED_PROTOBUF 0
  969. else
  970. enable_feature BUNDLED_PROTOBUF 1
  971. fi
  972. if [ -z "${ENABLE_SYSTEMD_PLUGIN}" ]; then
  973. if check_for_module libsystemd; then
  974. if check_for_module libelogind; then
  975. ENABLE_SYSTEMD_JOURNAL=0
  976. else
  977. ENABLE_SYSTEMD_JOURNAL=1
  978. fi
  979. else
  980. ENABLE_SYSTEMD_JOURNAL=0
  981. fi
  982. fi
  983. enable_feature PLUGIN_SYSTEMD_JOURNAL "${ENABLE_SYSTEMD_JOURNAL}"
  984. [ -z "${NETDATA_ENABLE_ML}" ] && NETDATA_ENABLE_ML=1
  985. enable_feature ML "${NETDATA_ENABLE_ML}"
  986. if command -v cups-config >/dev/null 2>&1 || check_for_module libcups || check_for_module cups; then
  987. ENABLE_CUPS=1
  988. else
  989. ENABLE_CUPS=0
  990. fi
  991. enable_feature PLUGIN_CUPS "${ENABLE_CUPS}"
  992. IS_LINUX=0
  993. [ "$(uname -s)" = "Linux" ] && IS_LINUX=1
  994. enable_feature PLUGIN_DEBUGFS "${IS_LINUX}"
  995. enable_feature PLUGIN_PERF "${IS_LINUX}"
  996. enable_feature PLUGIN_SLABINFO "${IS_LINUX}"
  997. enable_feature PLUGIN_CGROUP_NETWORK "${IS_LINUX}"
  998. enable_feature PLUGIN_LOCAL_LISTENERS "${IS_LINUX}"
  999. enable_feature PLUGIN_LOGS_MANAGEMENT "${ENABLE_LOGS_MANAGEMENT}"
  1000. enable_feature LOGS_MANAGEMENT_TESTS "${ENABLE_LOGS_MANAGEMENT_TESTS}"
  1001. enable_feature ACLK "${ENABLE_CLOUD}"
  1002. enable_feature CLOUD "${ENABLE_CLOUD}"
  1003. enable_feature BUNDLED_JSONC "${NETDATA_BUILD_JSON_C}"
  1004. enable_feature BUNDLED_YAML "${BUNDLE_YAML}"
  1005. enable_feature DBENGINE "${ENABLE_DBENGINE}"
  1006. enable_feature H2O "${ENABLE_H2O}"
  1007. enable_feature PLUGIN_EBPF "${ENABLE_EBPF}"
  1008. ENABLE_APPS=0
  1009. if [ "${IS_LINUX}" = 1 ] || [ "$(uname -s)" = "FreeBSD" ]; then
  1010. ENABLE_APPS=1
  1011. fi
  1012. enable_feature PLUGIN_APPS "${ENABLE_APPS}"
  1013. check_for_feature EXPORTER_PROMETHEUS_REMOTE_WRITE "${EXPORTER_PROMETHEUS}" snappy
  1014. check_for_feature EXPORTER_MONGODB "${EXPORTER_MONGODB}" libmongoc-1.0
  1015. check_for_feature PLUGIN_FREEIPMI "${ENABLE_FREEIPMI}" libipmimonitoring
  1016. check_for_feature PLUGIN_NFACCT "${ENABLE_NFACCT}" libnetfilter_acct libnml
  1017. check_for_feature PLUGIN_XENSTAT "${ENABLE_XENSTAT}" xenstat xenlight
  1018. # End of feature autodetection code
  1019. if [ -n "${NETDATA_PREPARE_ONLY}" ]; then
  1020. progress "Exiting before building Netdata as requested."
  1021. printf "Would have used the following CMake command line for configuration: %s\n" "${cmake} ${NETDATA_CMAKE_OPTIONS}"
  1022. trap - EXIT
  1023. exit 0
  1024. fi
  1025. # Let cmake know we don't want to link shared libs
  1026. if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
  1027. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DBUILD_SHARED_LIBS=Off"
  1028. fi
  1029. # shellcheck disable=SC2086
  1030. if ! run ${cmake} ${NETDATA_CMAKE_OPTIONS}; then
  1031. fatal "Failed to configure Netdata sources." I000A
  1032. fi
  1033. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1034. # remove the build_error hook
  1035. trap - EXIT
  1036. # -----------------------------------------------------------------------------
  1037. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
  1038. # -----------------------------------------------------------------------------
  1039. progress "Compile netdata"
  1040. # shellcheck disable=SC2086
  1041. if ! run ${cmake} --build "${NETDATA_BUILD_DIR}" --parallel ${JOBS} -- ${BUILD_OPTS}; then
  1042. fatal "Failed to build Netdata." I000B
  1043. fi
  1044. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1045. # -----------------------------------------------------------------------------
  1046. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
  1047. # -----------------------------------------------------------------------------
  1048. progress "Install netdata"
  1049. if ! cmake_install "${NETDATA_BUILD_DIR}"; then
  1050. fatal "Failed to install Netdata." I000C
  1051. fi
  1052. # -----------------------------------------------------------------------------
  1053. progress "Creating standard user and groups for netdata"
  1054. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  1055. NETDATA_ADDED_TO_GROUPS=""
  1056. if [ "$(id -u)" -eq 0 ]; then
  1057. progress "Adding group 'netdata'"
  1058. portable_add_group netdata || :
  1059. progress "Adding user 'netdata'"
  1060. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  1061. progress "Assign user 'netdata' to required groups"
  1062. for g in ${NETDATA_WANTED_GROUPS}; do
  1063. # shellcheck disable=SC2086
  1064. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  1065. done
  1066. # Netdata must be able to read /etc/pve/qemu-server/* and /etc/pve/lxc/*
  1067. # for reading VMs/containers names, CPU and memory limits on Proxmox.
  1068. if [ -d "/etc/pve" ]; then
  1069. portable_add_user_to_group "www-data" netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} www-data"
  1070. fi
  1071. else
  1072. run_failed "The installer does not run as root. Nothing to do for user and groups"
  1073. fi
  1074. # -----------------------------------------------------------------------------
  1075. progress "Install logrotate configuration for netdata"
  1076. install_netdata_logrotate
  1077. # -----------------------------------------------------------------------------
  1078. progress "Read installation options from netdata.conf"
  1079. # create an empty config if it does not exist
  1080. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  1081. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1082. # port
  1083. defport=19999
  1084. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  1085. # directories
  1086. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  1087. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  1088. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  1089. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  1090. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  1091. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  1092. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  1093. NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
  1094. cat << OPTIONSEOF
  1095. Permissions
  1096. - netdata user : ${NETDATA_USER}
  1097. - netdata group : ${NETDATA_GROUP}
  1098. - root user : ${ROOT_USER}
  1099. Directories
  1100. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  1101. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  1102. - netdata log dir : ${NETDATA_LOG_DIR}
  1103. - netdata run dir : ${NETDATA_RUN_DIR}
  1104. - netdata lib dir : ${NETDATA_LIB_DIR}
  1105. - netdata web dir : ${NETDATA_WEB_DIR}
  1106. - netdata cache dir : ${NETDATA_CACHE_DIR}
  1107. Other
  1108. - netdata port : ${NETDATA_PORT}
  1109. OPTIONSEOF
  1110. # -----------------------------------------------------------------------------
  1111. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  1112. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  1113. # this is needed if NETDATA_PREFIX is not empty
  1114. if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
  1115. warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
  1116. fi
  1117. fi
  1118. # --- stock conf dir ----
  1119. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  1120. [ -L "${NETDATA_USER_CONFIG_DIR}/orig" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/orig"
  1121. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/orig"
  1122. # --- web dir ----
  1123. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  1124. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  1125. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  1126. fi
  1127. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  1128. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  1129. # --- data dirs ----
  1130. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  1131. if [ ! -d "${x}" ]; then
  1132. echo >&2 "Creating directory '${x}'"
  1133. if ! run mkdir -p "${x}"; then
  1134. warning "Failed to create ${x}, it must be created by hand or the Netdata Agent will not be able to be started."
  1135. fi
  1136. fi
  1137. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  1138. #run find "${x}" -type f -exec chmod 0660 {} \;
  1139. #run find "${x}" -type d -exec chmod 0770 {} \;
  1140. done
  1141. run chmod 755 "${NETDATA_LOG_DIR}"
  1142. # --- claiming dir ----
  1143. if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
  1144. echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
  1145. if ! run mkdir -p "${NETDATA_CLAIMING_DIR}"; then
  1146. warning "failed to create ${NETDATA_CLAIMING_DIR}, it will need to be created manually."
  1147. fi
  1148. fi
  1149. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
  1150. run chmod 770 "${NETDATA_CLAIMING_DIR}"
  1151. # --- plugins ----
  1152. if [ "$(id -u)" -eq 0 ]; then
  1153. # find the admin group
  1154. admin_group=
  1155. test -z "${admin_group}" && get_group root > /dev/null 2>&1 && admin_group="root"
  1156. test -z "${admin_group}" && get_group daemon > /dev/null 2>&1 && admin_group="daemon"
  1157. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  1158. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  1159. run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1160. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1161. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  1162. # shellcheck disable=SC2086
  1163. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
  1164. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  1165. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  1166. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1167. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1168. capabilities=0
  1169. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1170. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1171. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  1172. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  1173. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  1174. fi
  1175. fi
  1176. if [ $capabilities -eq 0 ]; then
  1177. # fix apps.plugin to be setuid to root
  1178. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1179. fi
  1180. fi
  1181. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" ]; then
  1182. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  1183. capabilities=0
  1184. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1185. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  1186. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"; then
  1187. # if we managed to setcap, but we fail to execute debugfs.plugin setuid to root
  1188. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  1189. fi
  1190. fi
  1191. if [ $capabilities -eq 0 ]; then
  1192. # fix debugfs.plugin to be setuid to root
  1193. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  1194. fi
  1195. fi
  1196. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin" ]; then
  1197. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  1198. capabilities=0
  1199. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1200. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  1201. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"; then
  1202. capabilities=1
  1203. fi
  1204. fi
  1205. if [ $capabilities -eq 0 ]; then
  1206. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  1207. fi
  1208. fi
  1209. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin" ]; then
  1210. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1211. capabilities=0
  1212. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1213. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1214. if run setcap cap_dac_read_search,cap_syslog+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"; then
  1215. capabilities=1
  1216. fi
  1217. fi
  1218. if [ $capabilities -eq 0 ]; then
  1219. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1220. fi
  1221. fi
  1222. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  1223. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1224. capabilities=0
  1225. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  1226. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1227. 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
  1228. capabilities=1
  1229. fi
  1230. fi
  1231. if [ $capabilities -eq 0 ]; then
  1232. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1233. fi
  1234. fi
  1235. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
  1236. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1237. capabilities=0
  1238. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  1239. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1240. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"; then
  1241. capabilities=1
  1242. fi
  1243. fi
  1244. if [ $capabilities -eq 0 ]; then
  1245. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1246. fi
  1247. fi
  1248. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  1249. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1250. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1251. fi
  1252. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  1253. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1254. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1255. fi
  1256. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  1257. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1258. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1259. fi
  1260. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  1261. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1262. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1263. fi
  1264. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
  1265. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1266. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1267. fi
  1268. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  1269. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1270. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1271. fi
  1272. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  1273. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1274. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1275. fi
  1276. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners" ]; then
  1277. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  1278. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  1279. fi
  1280. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo" ]; then
  1281. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  1282. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  1283. fi
  1284. else
  1285. # non-privileged user installation
  1286. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  1287. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1288. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  1289. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1290. fi
  1291. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1292. # -----------------------------------------------------------------------------
  1293. # govercomp compares go.d.plugin versions. Exit codes:
  1294. # 0 - version1 == version2
  1295. # 1 - version1 > version2
  1296. # 2 - version2 > version1
  1297. # 3 - error
  1298. # shellcheck disable=SC2086
  1299. govercomp() {
  1300. # version in file:
  1301. # - v0.14.0
  1302. #
  1303. # 'go.d.plugin -v' output variants:
  1304. # - go.d.plugin, version: unknown
  1305. # - go.d.plugin, version: v0.14.1
  1306. # - go.d.plugin, version: v0.14.1-dirty
  1307. # - go.d.plugin, version: v0.14.1-1-g4c5f98c
  1308. # - go.d.plugin, version: v0.14.1-1-g4c5f98c-dirty
  1309. # we need to compare only MAJOR.MINOR.PATCH part
  1310. ver1=$(echo "$1" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
  1311. ver2=$(echo "$2" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
  1312. if [ ${#ver1} -eq 0 ] || [ ${#ver2} -eq 0 ]; then
  1313. return 3
  1314. fi
  1315. num1=$(echo $ver1 | grep -o -E '\.' | wc -l)
  1316. num2=$(echo $ver2 | grep -o -E '\.' | wc -l)
  1317. if [ ${num1} -ne ${num2} ]; then
  1318. return 3
  1319. fi
  1320. for i in $(seq 1 $((num1+1))); do
  1321. x=$(echo $ver1 | cut -d'.' -f$i)
  1322. y=$(echo $ver2 | cut -d'.' -f$i)
  1323. if [ "${x}" -gt "${y}" ]; then
  1324. return 1
  1325. elif [ "${y}" -gt "${x}" ]; then
  1326. return 2
  1327. fi
  1328. done
  1329. return 0
  1330. }
  1331. should_install_go() {
  1332. if [ -n "${NETDATA_DISABLE_GO+x}" ]; then
  1333. return 1
  1334. fi
  1335. version_in_file="$(cat packaging/go.d.version 2> /dev/null)"
  1336. binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2> /dev/null)
  1337. govercomp "$version_in_file" "$binary_version"
  1338. case $? in
  1339. 0) return 1 ;; # =
  1340. 2) return 1 ;; # <
  1341. *) return 0 ;; # >, error
  1342. esac
  1343. }
  1344. install_go() {
  1345. if ! should_install_go; then
  1346. return 0
  1347. fi
  1348. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing go.d.plugin."
  1349. # When updating this value, ensure correct checksums in packaging/go.d.checksums
  1350. GO_PACKAGE_VERSION="$(cat packaging/go.d.version)"
  1351. ARCH_MAP='
  1352. i386::386
  1353. i686::386
  1354. x86_64::amd64
  1355. aarch64::arm64
  1356. armv64::arm64
  1357. armv6l::arm
  1358. armv7l::arm
  1359. armv5tel::arm
  1360. '
  1361. progress "Install go.d.plugin"
  1362. ARCH=$(uname -m)
  1363. OS=$(uname -s | tr '[:upper:]' '[:lower:]')
  1364. for index in ${ARCH_MAP}; do
  1365. KEY="${index%%::*}"
  1366. VALUE="${index##*::}"
  1367. if [ "$KEY" = "$ARCH" ]; then
  1368. ARCH="${VALUE}"
  1369. break
  1370. fi
  1371. done
  1372. tmp="$(mktemp -d -t netdata-go-XXXXXX)"
  1373. GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}.tar.gz"
  1374. if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" ]; then
  1375. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
  1376. else
  1377. progress "Using provided go.d tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}"
  1378. run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" "${tmp}/${GO_PACKAGE_BASENAME}"
  1379. fi
  1380. if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" ]; then
  1381. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
  1382. else
  1383. progress "Using provided config file for go.d ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}"
  1384. run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" "${tmp}/config.tar.gz"
  1385. fi
  1386. if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
  1387. run_failed "go.d plugin download failed, go.d plugin will not be available"
  1388. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  1389. echo >&2
  1390. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1391. return 0
  1392. fi
  1393. grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
  1394. grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2> /dev/null
  1395. # Checksum validation
  1396. if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
  1397. echo >&2 "go.d plugin checksum validation failure."
  1398. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  1399. echo >&2
  1400. run_failed "go.d.plugin package files checksum validation failed. go.d.plugin will not be available."
  1401. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1402. return 0
  1403. fi
  1404. # Install new files
  1405. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
  1406. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
  1407. run tar --no-same-owner -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
  1408. run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
  1409. run tar --no-same-owner -xf "${tmp}/${GO_PACKAGE_BASENAME}"
  1410. run mv "${GO_PACKAGE_BASENAME%.tar.gz}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1411. if [ "$(id -u)" -eq 0 ]; then
  1412. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1413. fi
  1414. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1415. rm -rf "${tmp}"
  1416. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1417. }
  1418. install_go
  1419. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin" ]; then
  1420. if command -v setcap 1>/dev/null 2>&1; then
  1421. run setcap "cap_net_admin+epi cap_net_raw=eip" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1422. fi
  1423. fi
  1424. should_install_ebpf() {
  1425. if [ "${NETDATA_DISABLE_EBPF:=0}" -eq 1 ]; then
  1426. run_failed "eBPF has been explicitly disabled, it will not be available in this install."
  1427. return 1
  1428. fi
  1429. if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
  1430. if [ "${NETDATA_DISABLE_EBPF:=1}" -eq 0 ]; then
  1431. run_failed "Currently eBPF is only supported on Linux on X86_64."
  1432. fi
  1433. return 1
  1434. fi
  1435. # Check Kernel Config
  1436. if ! run "${INSTALLER_DIR}"/packaging/check-kernel-config.sh; then
  1437. warning "Kernel unsupported or missing required config (eBPF may not work on your system)"
  1438. fi
  1439. return 0
  1440. }
  1441. remove_old_ebpf() {
  1442. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin" ]; then
  1443. echo >&2 "Removing alpha eBPF collector."
  1444. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin"
  1445. fi
  1446. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf" ]; then
  1447. echo >&2 "Removing alpha eBPF stock file"
  1448. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf"
  1449. fi
  1450. if [ -f "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" ]; then
  1451. echo >&2 "Renaming eBPF configuration file."
  1452. mv "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" "${NETDATA_PREFIX}/etc/netdata/ebpf.d.conf"
  1453. fi
  1454. # Added to remove eBPF programs with name pattern: NAME_VERSION.SUBVERSION.PATCH
  1455. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.0.o" ]; then
  1456. echo >&2 "Removing old eBPF programs with patch."
  1457. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.*.o
  1458. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.*.o
  1459. fi
  1460. # Remove old eBPF program to store new eBPF program inside subdirectory
  1461. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.o" ]; then
  1462. echo >&2 "Removing old eBPF programs installed in old directory."
  1463. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.o
  1464. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.o
  1465. fi
  1466. # Remove old eBPF programs that did not have "rhf" suffix
  1467. if [ ! -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/pnetdata_ebpf_process.3.10.rhf.o" ]; then
  1468. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/"*.o
  1469. fi
  1470. # Remove old reject list from previous directory
  1471. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt" ]; then
  1472. echo >&2 "Removing old ebpf_kernel_reject_list.txt."
  1473. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt"
  1474. fi
  1475. # Remove old reset script
  1476. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh" ]; then
  1477. echo >&2 "Removing old reset_netdata_trace.sh."
  1478. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh"
  1479. fi
  1480. }
  1481. install_ebpf() {
  1482. if ! should_install_ebpf; then
  1483. return 0
  1484. fi
  1485. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing eBPF code."
  1486. remove_old_ebpf
  1487. progress "Installing eBPF plugin"
  1488. # Detect libc
  1489. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  1490. EBPF_VERSION="$(cat packaging/ebpf.version)"
  1491. EBPF_TARBALL="netdata-kernel-collector-${libc}-${EBPF_VERSION}.tar.xz"
  1492. tmp="$(mktemp -d -t netdata-ebpf-XXXXXX)"
  1493. if ! fetch_and_verify "ebpf" \
  1494. "https://github.com/netdata/kernel-collector/releases/download/${EBPF_VERSION}/${EBPF_TARBALL}" \
  1495. "${EBPF_TARBALL}" \
  1496. "${tmp}" \
  1497. "${NETDATA_LOCAL_TARBALL_OVERRIDE_EBPF}"; then
  1498. run_failed "Failed to download eBPF collector package"
  1499. echo 2>&" Removing temporary directory ${tmp} ..."
  1500. rm -rf "${tmp}"
  1501. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1502. return 1
  1503. fi
  1504. echo >&2 " Extracting ${EBPF_TARBALL} ..."
  1505. tar --no-same-owner -xf "${tmp}/${EBPF_TARBALL}" -C "${tmp}"
  1506. # chown everything to root:netdata before we start copying out of our package
  1507. run chown -R root:netdata "${tmp}"
  1508. if [ ! -d "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d ]; then
  1509. mkdir "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1510. RET=$?
  1511. if [ "${RET}" != "0" ]; then
  1512. rm -rf "${tmp}"
  1513. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1514. return 1
  1515. fi
  1516. fi
  1517. run cp -a -v "${tmp}"/*netdata_ebpf_*.o "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1518. rm -rf "${tmp}"
  1519. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1520. }
  1521. progress "eBPF Kernel Collector"
  1522. install_ebpf
  1523. should_install_fluentbit() {
  1524. if [ "$(uname -s)" = "Darwin" ]; then
  1525. return 1
  1526. fi
  1527. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  1528. warning "netdata-installer.sh run with --disable-logsmanagement, Fluent-Bit installation is skipped."
  1529. return 1
  1530. elif [ "${FLUENT_BIT_BUILD_SUCCESS:=0}" -eq 0 ]; then
  1531. run_failed "Fluent-Bit was not built successfully, Netdata Logs Management support will be disabled in this build."
  1532. return 1
  1533. elif [ ! -f fluent-bit/build/lib/libfluent-bit.so ]; then
  1534. run_failed "libfluent-bit.so is missing, Netdata Logs Management support will be disabled in this build."
  1535. return 1
  1536. fi
  1537. return 0
  1538. }
  1539. install_fluentbit() {
  1540. if ! should_install_fluentbit; then
  1541. enable_feature PLUGIN_LOGS_MANAGEMENT 0
  1542. return 0
  1543. fi
  1544. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Fluent-Bit."
  1545. run chown "root:${NETDATA_GROUP}" fluent-bit/build/lib
  1546. run chmod 0644 fluent-bit/build/lib/libfluent-bit.so
  1547. run cp -a -v fluent-bit/build/lib/libfluent-bit.so "${NETDATA_PREFIX}"/usr/lib/netdata
  1548. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1549. }
  1550. progress "Installing Fluent-Bit plugin"
  1551. install_fluentbit
  1552. # -----------------------------------------------------------------------------
  1553. progress "Telemetry configuration"
  1554. # Opt-out from telemetry program
  1555. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  1556. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  1557. else
  1558. 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"
  1559. fi
  1560. # -----------------------------------------------------------------------------
  1561. progress "Install netdata at system init"
  1562. # By default we assume the shutdown/startup of the Netdata Agent are effectively
  1563. # without any system supervisor/init like SystemD or SysV. So we assume the most
  1564. # basic startup/shutdown commands...
  1565. NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
  1566. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  1567. if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
  1568. # If docker runs systemd for some weird reason, let the install proceed
  1569. is_systemd_running="NO"
  1570. if command -v pidof > /dev/null 2>&1; then
  1571. is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
  1572. else
  1573. is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
  1574. fi
  1575. if [ "${is_systemd_running}" = "1" ]; then
  1576. echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
  1577. install_netdata_service || run_failed "Cannot install netdata init service."
  1578. else
  1579. echo >&2 "We are running within a docker container, will not be installing netdata service"
  1580. fi
  1581. echo >&2
  1582. else
  1583. install_netdata_service || run_failed "Cannot install netdata init service."
  1584. fi
  1585. # -----------------------------------------------------------------------------
  1586. # check if we can re-start netdata
  1587. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  1588. started=0
  1589. if [ ${DONOTSTART} -eq 1 ]; then
  1590. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1591. else
  1592. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  1593. fatal "Cannot start netdata!" I000D
  1594. fi
  1595. started=1
  1596. run_ok "netdata started!"
  1597. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  1598. fi
  1599. run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1600. if [ "$(uname)" = "Linux" ]; then
  1601. # -------------------------------------------------------------------------
  1602. progress "Check KSM (kernel memory deduper)"
  1603. ksm_is_available_but_disabled() {
  1604. cat << KSM1
  1605. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  1606. You have kernel memory de-duper (called Kernel Same-page Merging,
  1607. or KSM) available, but it is not currently enabled.
  1608. To enable it run:
  1609. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  1610. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  1611. If you enable it, you will save 40-60% of netdata memory.
  1612. KSM1
  1613. }
  1614. ksm_is_not_available() {
  1615. cat << KSM2
  1616. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  1617. It seems you do not have kernel memory de-duper (called Kernel Same-page
  1618. Merging, or KSM) available.
  1619. To enable it, you need a kernel built with CONFIG_KSM=y
  1620. If you can have it, you will save 40-60% of netdata memory.
  1621. KSM2
  1622. }
  1623. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  1624. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  1625. ksm_is_available_but_disabled
  1626. fi
  1627. else
  1628. ksm_is_not_available
  1629. fi
  1630. fi
  1631. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1632. # -----------------------------------------------------------------------------
  1633. progress "Check apps.plugin"
  1634. if [ "$(id -u)" -ne 0 ]; then
  1635. cat << SETUID_WARNING
  1636. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  1637. Since you have installed netdata as a normal user, to have apps.plugin collect
  1638. all the needed data, you have to give it the access rights it needs, by running
  1639. either of the following sets of commands:
  1640. To run apps.plugin with escalated capabilities:
  1641. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1642. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1643. ${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}
  1644. or, to run apps.plugin as root:
  1645. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1646. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1647. apps.plugin is performing a hard-coded function of data collection for all
  1648. running processes. It cannot be instructed from the netdata daemon to perform
  1649. any task, so it is pretty safe to do this.
  1650. SETUID_WARNING
  1651. fi
  1652. fi
  1653. # -----------------------------------------------------------------------------
  1654. progress "Copy uninstaller"
  1655. if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
  1656. echo >&2 "Removing uninstaller from old location"
  1657. rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
  1658. fi
  1659. 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"
  1660. chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  1661. # -----------------------------------------------------------------------------
  1662. progress "Basic netdata instructions"
  1663. cat << END
  1664. netdata by default listens on all IPs on port ${NETDATA_PORT},
  1665. so you can access it with:
  1666. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  1667. To stop netdata run:
  1668. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  1669. To start netdata run:
  1670. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  1671. END
  1672. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
  1673. echo >&2
  1674. # -----------------------------------------------------------------------------
  1675. progress "Installing (but not enabling) the netdata updater tool"
  1676. install_netdata_updater || run_failed "Cannot install netdata updater tool."
  1677. # -----------------------------------------------------------------------------
  1678. progress "Wrap up environment set up"
  1679. # Save environment variables
  1680. echo >&2 "Preparing .environment file"
  1681. cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  1682. # Created by installer
  1683. PATH="${PATH}"
  1684. CFLAGS="${CFLAGS}"
  1685. LDFLAGS="${LDFLAGS}"
  1686. MAKEOPTS="${MAKEOPTS}"
  1687. NETDATA_TMPDIR="${TMPDIR}"
  1688. NETDATA_PREFIX="${NETDATA_PREFIX}"
  1689. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS}"
  1690. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  1691. INSTALL_UID="$(id -u)"
  1692. NETDATA_GROUP="${NETDATA_GROUP}"
  1693. REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
  1694. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  1695. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
  1696. NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
  1697. EOF
  1698. run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
  1699. echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
  1700. cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  1701. new_installation
  1702. EOF
  1703. print_deferred_errors
  1704. # -----------------------------------------------------------------------------
  1705. echo >&2
  1706. progress "We are done!"
  1707. if [ ${started} -eq 1 ]; then
  1708. netdata_banner
  1709. progress "is installed and running now!"
  1710. else
  1711. netdata_banner
  1712. progress "is installed now!"
  1713. fi
  1714. echo >&2 " enjoy real-time performance and health monitoring..."
  1715. echo >&2
  1716. exit 0