netdata-installer.sh 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009
  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. # set default make options
  392. if [ -z "${MAKEOPTS}" ]; then
  393. MAKEOPTS="-j$(find_processors)"
  394. elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
  395. MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
  396. fi
  397. if [ "$(id -u)" -ne 0 ] && [ -z "${NETDATA_PREPARE_ONLY}" ]; then
  398. if [ -z "${NETDATA_PREFIX}" ]; then
  399. netdata_banner
  400. banner_nonroot_install "${@}"
  401. exit_reason "Attempted install as non-root user to /." I0010
  402. exit 1
  403. else
  404. banner_root_notify "${@}"
  405. fi
  406. fi
  407. netdata_banner
  408. progress "real-time performance monitoring, done right!"
  409. cat << BANNER1
  410. You are about to build and install netdata to your system.
  411. The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
  412. any temporary files. You can override this by setting \$TMPDIR to a
  413. writable directory where you can execute files.
  414. It will be installed at these locations:
  415. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  416. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  417. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  418. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  419. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  420. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  421. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  422. BANNER1
  423. [ "$(id -u)" -eq 0 ] && cat << BANNER2
  424. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  425. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  426. BANNER2
  427. cat << BANNER3
  428. This installer allows you to change the installation path.
  429. Press Control-C and run the same command with --help for help.
  430. BANNER3
  431. if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
  432. cat << BANNER4
  433. ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
  434. Anonymous usage stats will be collected and sent to Netdata.
  435. To opt-out, pass --disable-telemetry option to the installer or export
  436. the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
  437. (e.g: export DISABLE_TELEMETRY=1).
  438. BANNER4
  439. fi
  440. if ! command -v cmake >/dev/null 2>&1; then
  441. fatal "Could not find CMake, which is required to build Netdata." I0012
  442. else
  443. cmake="$(command -v cmake)"
  444. progress "Found CMake at ${cmake}. CMake version: $(${cmake} --version | head -n 1)"
  445. fi
  446. if ! command -v "ninja" >/dev/null 2>&1; then
  447. progress "Could not find Ninja, will use Make instead."
  448. else
  449. ninja="$(command -v ninja)"
  450. progress "Found Ninja at ${ninja}. Ninja version: $(${ninja} --version)"
  451. progress "Will use Ninja for this build instead of Make when possible."
  452. fi
  453. make="$(command -v make 2>/dev/null)"
  454. if [ -z "${make}" ] && [ -z "${ninja}" ]; then
  455. fatal "Could not find a usable underlying build system (we support make and ninja)." I0014
  456. fi
  457. CMAKE_OPTS="${ninja:+-G Ninja}"
  458. BUILD_OPTS="VERBOSE=1"
  459. [ -n "${ninja}" ] && BUILD_OPTS="-v"
  460. if [ ${DONOTWAIT} -eq 0 ]; then
  461. if [ -n "${NETDATA_PREFIX}" ]; then
  462. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  463. else
  464. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  465. fi
  466. read -r REPLY
  467. if [ "$REPLY" != '' ]; then
  468. exit_reason "User did not accept install attempt." I0011
  469. exit 1
  470. fi
  471. fi
  472. cmake_install() {
  473. # run cmake --install ${1}
  474. # The above command should be used to replace the logic below once we no longer support
  475. # versions of CMake less than 3.15.
  476. if [ -n "${ninja}" ]; then
  477. run ${ninja} -C "${1}" install
  478. else
  479. run ${make} -C "${1}" install
  480. fi
  481. }
  482. build_error() {
  483. netdata_banner
  484. trap - EXIT
  485. fatal "Netdata failed to build for an unknown reason." I0002
  486. }
  487. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  488. shift
  489. echo >&2 "ok, assuming libs are really installed."
  490. export ZLIB_CFLAGS=" "
  491. export ZLIB_LIBS="-lz"
  492. export UUID_CFLAGS=" "
  493. export UUID_LIBS="-luuid"
  494. fi
  495. trap build_error EXIT
  496. # -----------------------------------------------------------------------------
  497. build_protobuf() {
  498. env_cmd=''
  499. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  500. env_cmd="env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  501. fi
  502. cd "${1}" > /dev/null || return 1
  503. if ! run eval "${env_cmd} ./configure --disable-shared --without-zlib --disable-dependency-tracking --with-pic"; then
  504. cd - > /dev/null || return 1
  505. return 1
  506. fi
  507. if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
  508. cd - > /dev/null || return 1
  509. return 1
  510. fi
  511. cd - > /dev/null || return 1
  512. }
  513. copy_protobuf() {
  514. target_dir="${PWD}/externaldeps/protobuf"
  515. run mkdir -p "${target_dir}" || return 1
  516. run cp -a "${1}/src" "${target_dir}" || return 1
  517. }
  518. bundle_protobuf() {
  519. if [ -n "${NETDATA_DISABLE_CLOUD}" ] && [ -n "${EXPORTER_PROMETHEUS}" ] && [ "${EXPORTER_PROMETHEUS}" -eq 0 ]; then
  520. echo "Skipping protobuf"
  521. return 0
  522. fi
  523. if [ -n "${USE_SYSTEM_PROTOBUF}" ]; then
  524. echo "Skipping protobuf"
  525. 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."
  526. return 0
  527. fi
  528. if [ -z "${make}" ]; then
  529. warning "No usable copy of Make found, which is required for bundling protobuf. Attempting to use a system copy of protobuf instead."
  530. USE_SYSTEM_PROTOBUF=1
  531. return 0
  532. fi
  533. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling protobuf."
  534. PROTOBUF_PACKAGE_VERSION="$(cat packaging/protobuf.version)"
  535. if [ -f "${PWD}/externaldeps/protobuf/.version" ] && [ "${PROTOBUF_PACKAGE_VERSION}" = "$(cat "${PWD}/externaldeps/protobuf/.version")" ]
  536. then
  537. echo >&2 "Found compiled protobuf, same version, not compiling it again. Remove file '${PWD}/externaldeps/protobuf/.version' to recompile."
  538. USE_SYSTEM_PROTOBUF=0
  539. return 0
  540. fi
  541. tmp="$(mktemp -d -t netdata-protobuf-XXXXXX)"
  542. PROTOBUF_PACKAGE_BASENAME="protobuf-cpp-${PROTOBUF_PACKAGE_VERSION}.tar.gz"
  543. if fetch_and_verify "protobuf" \
  544. "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_PACKAGE_VERSION}/${PROTOBUF_PACKAGE_BASENAME}" \
  545. "${PROTOBUF_PACKAGE_BASENAME}" \
  546. "${tmp}" \
  547. "${NETDATA_LOCAL_TARBALL_VERRIDE_PROTOBUF}"; then
  548. if run tar --no-same-owner -xf "${tmp}/${PROTOBUF_PACKAGE_BASENAME}" -C "${tmp}" &&
  549. build_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
  550. copy_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
  551. echo "${PROTOBUF_PACKAGE_VERSION}" >"${PWD}/externaldeps/protobuf/.version" &&
  552. rm -rf "${tmp}"; then
  553. run_ok "protobuf built and prepared."
  554. USE_SYSTEM_PROTOBUF=0
  555. else
  556. run_failed "Failed to build protobuf. Netdata Cloud support will not be available in this build."
  557. fi
  558. else
  559. run_failed "Unable to fetch sources for protobuf. Netdata Cloud support will not be available in this build."
  560. fi
  561. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  562. }
  563. bundle_protobuf
  564. # -----------------------------------------------------------------------------
  565. build_jsonc() {
  566. env_cmd=''
  567. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  568. env_cmd="env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  569. fi
  570. cd "${1}" > /dev/null || exit 1
  571. run eval "${env_cmd} ${cmake} ${CMAKE_OPTS} -DBUILD_SHARED_LIBS=OFF -DDISABLE_WERROR=On ."
  572. run eval "${env_cmd} ${cmake} --build . --parallel ${JOBS} -- ${BUILD_OPTS}"
  573. cd - > /dev/null || return 1
  574. }
  575. copy_jsonc() {
  576. target_dir="${PWD}/externaldeps/jsonc"
  577. run mkdir -p "${target_dir}" "${target_dir}/json-c" || return 1
  578. run cp "${1}/libjson-c.a" "${target_dir}/libjson-c.a" || return 1
  579. # shellcheck disable=SC2086
  580. run cp ${1}/*.h "${target_dir}/json-c" || return 1
  581. }
  582. bundle_jsonc() {
  583. # If --build-json-c flag or not json-c on system, then bundle our own json-c
  584. if [ -z "${NETDATA_BUILD_JSON_C}" ] && pkg-config json-c; then
  585. NETDATA_BUILD_JSON_C=0
  586. return 0
  587. fi
  588. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling JSON-C."
  589. progress "Prepare JSON-C"
  590. JSONC_PACKAGE_VERSION="$(cat packaging/jsonc.version)"
  591. tmp="$(mktemp -d -t netdata-jsonc-XXXXXX)"
  592. JSONC_PACKAGE_BASENAME="json-c-${JSONC_PACKAGE_VERSION}.tar.gz"
  593. if fetch_and_verify "jsonc" \
  594. "https://github.com/json-c/json-c/archive/${JSONC_PACKAGE_BASENAME}" \
  595. "${JSONC_PACKAGE_BASENAME}" \
  596. "${tmp}" \
  597. "${NETDATA_LOCAL_TARBALL_OVERRIDE_JSONC}"; then
  598. if run tar --no-same-owner -xf "${tmp}/${JSONC_PACKAGE_BASENAME}" -C "${tmp}" &&
  599. build_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  600. copy_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  601. rm -rf "${tmp}"; then
  602. run_ok "JSON-C built and prepared."
  603. NETDATA_BUILD_JSON_C=1
  604. else
  605. run_failed "Failed to build JSON-C, Netdata Cloud support will be disabled in this build."
  606. NETDATA_BUILD_JSON_C=0
  607. ENABLE_CLOUD=0
  608. fi
  609. else
  610. run_failed "Unable to fetch sources for JSON-C, Netdata Cloud support will be disabled in this build."
  611. NETDATA_BUILD_JSON_C=0
  612. ENABLE_CLOUD=0
  613. fi
  614. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  615. }
  616. bundle_jsonc
  617. # -----------------------------------------------------------------------------
  618. build_yaml() {
  619. env_cmd=''
  620. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  621. env_cmd="env CFLAGS='-fPIC -pipe -Wno-unused-value' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  622. fi
  623. cd "${1}" > /dev/null || return 1
  624. run eval "${env_cmd} ./configure --disable-shared --disable-dependency-tracking --with-pic"
  625. run eval "${env_cmd} ${make} ${MAKEOPTS}"
  626. cd - > /dev/null || return 1
  627. }
  628. copy_yaml() {
  629. target_dir="${PWD}/externaldeps/libyaml"
  630. run mkdir -p "${target_dir}" || return 1
  631. run cp "${1}/src/.libs/libyaml.a" "${target_dir}/libyaml.a" || return 1
  632. run cp "${1}/include/yaml.h" "${target_dir}/" || return 1
  633. }
  634. bundle_yaml() {
  635. if pkg-config yaml-0.1; then
  636. BUNDLE_YAML=0
  637. return 0
  638. fi
  639. if [ -z "${make}" ]; then
  640. 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
  641. fi
  642. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling YAML."
  643. progress "Prepare YAML"
  644. YAML_PACKAGE_VERSION="$(cat packaging/yaml.version)"
  645. tmp="$(mktemp -d -t netdata-yaml-XXXXXX)"
  646. YAML_PACKAGE_BASENAME="yaml-${YAML_PACKAGE_VERSION}.tar.gz"
  647. if fetch_and_verify "yaml" \
  648. "https://github.com/yaml/libyaml/releases/download/${YAML_PACKAGE_VERSION}/${YAML_PACKAGE_BASENAME}" \
  649. "${YAML_PACKAGE_BASENAME}" \
  650. "${tmp}" \
  651. "${NETDATA_LOCAL_TARBALL_OVERRIDE_YAML}"; then
  652. if run tar --no-same-owner -xf "${tmp}/${YAML_PACKAGE_BASENAME}" -C "${tmp}" &&
  653. build_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
  654. copy_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
  655. rm -rf "${tmp}"; then
  656. run_ok "YAML built and prepared."
  657. BUNDLE_YAML=1
  658. else
  659. run_failed "Failed to build YAML, critical error."
  660. BUNDLE_YAML=0
  661. fi
  662. else
  663. run_failed "Unable to fetch sources for YAML, critical error."
  664. BUNDLE_YAML=0
  665. fi
  666. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  667. }
  668. bundle_yaml
  669. # -----------------------------------------------------------------------------
  670. get_kernel_version() {
  671. r="$(uname -r | cut -f 1 -d '-')"
  672. tmpfile="$(mktemp)"
  673. echo "${r}" | tr '.' ' ' > "${tmpfile}"
  674. read -r maj min patch _ < "${tmpfile}"
  675. rm -f "${tmpfile}"
  676. printf "%03d%03d%03d" "${maj}" "${min}" "${patch}"
  677. }
  678. detect_libc() {
  679. libc=
  680. if ldd --version 2>&1 | grep -q -i glibc; then
  681. echo >&2 " Detected GLIBC"
  682. libc="glibc"
  683. elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
  684. echo >&2 " Detected GLIBC"
  685. libc="glibc"
  686. elif ldd --version 2>&1 | grep -q -i musl; then
  687. echo >&2 " Detected musl"
  688. libc="musl"
  689. else
  690. cmd=$(ldd /bin/sh | grep -w libc | cut -d" " -f 3)
  691. if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
  692. echo >&2 " Detected GLIBC"
  693. libc="glibc"
  694. fi
  695. fi
  696. if [ -z "$libc" ]; then
  697. warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
  698. return 1
  699. fi
  700. echo "${libc}"
  701. return 0
  702. }
  703. build_libbpf() {
  704. cd "${1}/src" > /dev/null || return 1
  705. mkdir root build
  706. # shellcheck disable=SC2086
  707. run env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
  708. cd - > /dev/null || return 1
  709. }
  710. copy_libbpf() {
  711. target_dir="${PWD}/externaldeps/libbpf"
  712. if [ "$(uname -m)" = x86_64 ]; then
  713. lib_subdir="lib64"
  714. else
  715. lib_subdir="lib"
  716. fi
  717. run mkdir -p "${target_dir}" || return 1
  718. run cp "${1}/usr/${lib_subdir}/libbpf.a" "${target_dir}/libbpf.a" || return 1
  719. run cp -r "${1}/usr/include" "${target_dir}" || return 1
  720. run cp -r "${1}/include/uapi" "${target_dir}/include" || return 1
  721. }
  722. bundle_libbpf() {
  723. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  724. ENABLE_EBPF=0
  725. NETDATA_DISABLE_EBPF=1
  726. return 0
  727. fi
  728. if [ -z "${make}" ]; then
  729. warning "No usable copy of Make found, which is required to bundle libbpf. Disabling eBPF support."
  730. ENABLE_EBPF=0
  731. NETDATA_DISABLE_EBPF=1
  732. return 0
  733. fi
  734. # When libc is not detected, we do not have necessity to compile libbpf and we should not do download of eBPF programs
  735. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  736. if [ -z "$libc" ]; then
  737. NETDATA_DISABLE_EBPF=1
  738. ENABLE_EBPF=0
  739. return 0
  740. fi
  741. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  742. progress "Prepare libbpf"
  743. if [ "$(get_kernel_version)" -ge "004014000" ]; then
  744. LIBBPF_PACKAGE_VERSION="$(cat packaging/current_libbpf.version)"
  745. LIBBPF_PACKAGE_COMPONENT="current_libbpf"
  746. else
  747. LIBBPF_PACKAGE_VERSION="$(cat packaging/libbpf_0_0_9.version)"
  748. LIBBPF_PACKAGE_COMPONENT="libbpf_0_0_9"
  749. fi
  750. tmp="$(mktemp -d -t netdata-libbpf-XXXXXX)"
  751. LIBBPF_PACKAGE_BASENAME="v${LIBBPF_PACKAGE_VERSION}.tar.gz"
  752. if fetch_and_verify "${LIBBPF_PACKAGE_COMPONENT}" \
  753. "https://github.com/netdata/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
  754. "${LIBBPF_PACKAGE_BASENAME}" \
  755. "${tmp}" \
  756. "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBBPF}"; then
  757. if run tar --no-same-owner -xf "${tmp}/${LIBBPF_PACKAGE_BASENAME}" -C "${tmp}" &&
  758. build_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  759. copy_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  760. rm -rf "${tmp}"; then
  761. run_ok "libbpf built and prepared."
  762. ENABLE_EBPF=1
  763. else
  764. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  765. fatal "failed to build libbpf." I0005
  766. else
  767. run_failed "Failed to build libbpf. eBPF support will be disabled"
  768. ENABLE_EBPF=0
  769. NETDATA_DISABLE_EBPF=1
  770. fi
  771. fi
  772. else
  773. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  774. fatal "Failed to fetch sources for libbpf." I0006
  775. else
  776. run_failed "Unable to fetch sources for libbpf. eBPF support will be disabled"
  777. ENABLE_EBPF=0
  778. NETDATA_DISABLE_EBPF=1
  779. fi
  780. fi
  781. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  782. }
  783. bundle_libbpf
  784. copy_co_re() {
  785. cp -R "${1}/includes" "collectors/ebpf.plugin/"
  786. }
  787. bundle_ebpf_co_re() {
  788. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  789. return 0
  790. fi
  791. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  792. progress "eBPF CO-RE"
  793. CORE_PACKAGE_VERSION="$(cat packaging/ebpf-co-re.version)"
  794. tmp="$(mktemp -d -t netdata-ebpf-co-re-XXXXXX)"
  795. CORE_PACKAGE_BASENAME="netdata-ebpf-co-re-glibc-${CORE_PACKAGE_VERSION}.tar.xz"
  796. if fetch_and_verify "ebpf-co-re" \
  797. "https://github.com/netdata/ebpf-co-re/releases/download/${CORE_PACKAGE_VERSION}/${CORE_PACKAGE_BASENAME}" \
  798. "${CORE_PACKAGE_BASENAME}" \
  799. "${tmp}" \
  800. "${NETDATA_LOCAL_TARBALL_OVERRIDE_CORE}"; then
  801. if run tar --no-same-owner -xf "${tmp}/${CORE_PACKAGE_BASENAME}" -C "${tmp}" &&
  802. copy_co_re "${tmp}" &&
  803. rm -rf "${tmp}"; then
  804. run_ok "libbpf built and prepared."
  805. ENABLE_EBPF=1
  806. else
  807. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  808. fatal "Failed to get eBPF CO-RE files." I0007
  809. else
  810. run_failed "Failed to get eBPF CO-RE files. eBPF support will be disabled"
  811. NETDATA_DISABLE_EBPF=1
  812. ENABLE_EBPF=0
  813. enable_feature PLUGIN_EBPF 0
  814. fi
  815. fi
  816. else
  817. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  818. fatal "Failed to fetch eBPF CO-RE files." I0008
  819. else
  820. run_failed "Failed to fetch eBPF CO-RE files. eBPF support will be disabled"
  821. NETDATA_DISABLE_EBPF=1
  822. ENABLE_EBPF=0
  823. enable_feature PLUGIN_EBPF 0
  824. fi
  825. fi
  826. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  827. }
  828. bundle_ebpf_co_re
  829. # -----------------------------------------------------------------------------
  830. build_fluentbit() {
  831. env_cmd="env CFLAGS='-w' CXXFLAGS='-w' LDFLAGS="
  832. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  833. env_cmd="env CFLAGS='-fPIC -pipe -w' CXXFLAGS='-fPIC -pipe -w' LDFLAGS="
  834. fi
  835. mkdir -p fluent-bit/build || return 1
  836. cd fluent-bit/build > /dev/null || return 1
  837. rm CMakeCache.txt > /dev/null 2>&1
  838. if ! run eval "${env_cmd} $1 -C ../../logsmanagement/fluent_bit_build/config.cmake -B./ -S../"; then
  839. cd - > /dev/null || return 1
  840. rm -rf fluent-bit/build > /dev/null 2>&1
  841. return 1
  842. fi
  843. if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
  844. cd - > /dev/null || return 1
  845. rm -rf fluent-bit/build > /dev/null 2>&1
  846. return 1
  847. fi
  848. cd - > /dev/null || return 1
  849. }
  850. bundle_fluentbit() {
  851. progress "Prepare Fluent-Bit"
  852. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  853. warning "You have explicitly requested to disable Netdata Logs Management support, Fluent-Bit build is skipped."
  854. return 0
  855. fi
  856. if [ ! -d "fluent-bit" ]; then
  857. warning "Missing submodule Fluent-Bit. The install process will continue, but Netdata Logs Management support will be disabled."
  858. ENABLE_LOGS_MANAGEMENT=0
  859. return 0
  860. fi
  861. patch -N -p1 fluent-bit/CMakeLists.txt -i logsmanagement/fluent_bit_build/CMakeLists.patch
  862. patch -N -p1 fluent-bit/src/flb_log.c -i logsmanagement/fluent_bit_build/flb-log-fmt.patch
  863. # If musl is used, we need to patch chunkio, providing fts has been previously installed.
  864. libc="$(detect_libc)"
  865. if [ "${libc}" = "musl" ]; then
  866. patch -N -p1 fluent-bit/lib/chunkio/src/CMakeLists.txt -i logsmanagement/fluent_bit_build/chunkio-static-lib-fts.patch
  867. patch -N -p1 fluent-bit/cmake/luajit.cmake -i logsmanagement/fluent_bit_build/exclude-luajit.patch
  868. patch -N -p1 fluent-bit/src/flb_network.c -i logsmanagement/fluent_bit_build/xsi-strerror.patch
  869. fi
  870. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling Fluent-Bit."
  871. if build_fluentbit "$cmake"; then
  872. # If Fluent-Bit built with inotify support, use it.
  873. if [ "$(grep -o '^FLB_HAVE_INOTIFY:INTERNAL=.*' fluent-bit/build/CMakeCache.txt | cut -d '=' -f 2)" ]; then
  874. CFLAGS="${CFLAGS} -DFLB_HAVE_INOTIFY"
  875. fi
  876. FLUENT_BIT_BUILD_SUCCESS=1
  877. run_ok "Fluent-Bit built successfully."
  878. else
  879. warning "Failed to build Fluent-Bit, Netdata Logs Management support will be disabled in this build."
  880. ENABLE_LOGS_MANAGEMENT=0
  881. fi
  882. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  883. }
  884. bundle_fluentbit
  885. # -----------------------------------------------------------------------------
  886. # If we have the dashboard switching logic, make sure we're on the classic
  887. # dashboard during the install (updates don't work correctly otherwise).
  888. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
  889. "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
  890. fi
  891. # -----------------------------------------------------------------------------
  892. # By default, `git` does not update local tags based on remotes. Because
  893. # we use the most recent tag as part of our version determination in
  894. # our build, this can lead to strange versions that look ancient but are
  895. # actually really recent. To avoid this, try and fetch tags if we're
  896. # working in a git checkout.
  897. if [ -d ./.git ] ; then
  898. echo >&2
  899. progress "Updating tags in git to ensure a consistent version number"
  900. run git fetch -t || true
  901. fi
  902. # -----------------------------------------------------------------------------
  903. echo >&2
  904. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
  905. NETDATA_BUILD_DIR="${NETDATA_BUILD_DIR:-./build/}"
  906. rm -rf "${NETDATA_BUILD_DIR}"
  907. # function to extract values from the config file
  908. config_option() {
  909. section="${1}"
  910. key="${2}"
  911. value="${3}"
  912. if [ -x "${NETDATA_PREFIX}/usr/sbin/netdata" ] && [ -r "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  913. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  914. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  915. -W get "${section}" "${key}" "${value}" ||
  916. echo "${value}"
  917. else
  918. echo "${value}"
  919. fi
  920. }
  921. # the user netdata will run as
  922. if [ "$(id -u)" = "0" ]; then
  923. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  924. ROOT_USER="root"
  925. else
  926. NETDATA_USER="${USER}"
  927. ROOT_USER="${USER}"
  928. fi
  929. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}" 2> /dev/null)"
  930. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  931. echo >&2 "Netdata user and group set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  932. prepare_cmake_options
  933. if [ -n "${NETDATA_PREPARE_ONLY}" ]; then
  934. progress "Exiting before building Netdata as requested."
  935. printf "Would have used the following CMake command line for configuration: %s\n" "${cmake} ${NETDATA_CMAKE_OPTIONS}"
  936. trap - EXIT
  937. exit 0
  938. fi
  939. # Let cmake know we don't want to link shared libs
  940. if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
  941. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DBUILD_SHARED_LIBS=Off"
  942. fi
  943. # shellcheck disable=SC2086
  944. if ! run ${cmake} ${NETDATA_CMAKE_OPTIONS}; then
  945. fatal "Failed to configure Netdata sources." I000A
  946. fi
  947. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  948. # remove the build_error hook
  949. trap - EXIT
  950. # -----------------------------------------------------------------------------
  951. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
  952. # -----------------------------------------------------------------------------
  953. progress "Compile netdata"
  954. # shellcheck disable=SC2086
  955. if ! run ${cmake} --build "${NETDATA_BUILD_DIR}" --parallel ${JOBS} -- ${BUILD_OPTS}; then
  956. fatal "Failed to build Netdata." I000B
  957. fi
  958. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  959. # -----------------------------------------------------------------------------
  960. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
  961. # -----------------------------------------------------------------------------
  962. progress "Install netdata"
  963. if ! cmake_install "${NETDATA_BUILD_DIR}"; then
  964. fatal "Failed to install Netdata." I000C
  965. fi
  966. # -----------------------------------------------------------------------------
  967. progress "Creating standard user and groups for netdata"
  968. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  969. NETDATA_ADDED_TO_GROUPS=""
  970. if [ "$(id -u)" -eq 0 ]; then
  971. progress "Adding group 'netdata'"
  972. portable_add_group netdata || :
  973. progress "Adding user 'netdata'"
  974. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  975. progress "Assign user 'netdata' to required groups"
  976. for g in ${NETDATA_WANTED_GROUPS}; do
  977. # shellcheck disable=SC2086
  978. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  979. done
  980. # Netdata must be able to read /etc/pve/qemu-server/* and /etc/pve/lxc/*
  981. # for reading VMs/containers names, CPU and memory limits on Proxmox.
  982. if [ -d "/etc/pve" ]; then
  983. portable_add_user_to_group "www-data" netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} www-data"
  984. fi
  985. else
  986. run_failed "The installer does not run as root. Nothing to do for user and groups"
  987. fi
  988. # -----------------------------------------------------------------------------
  989. progress "Install logrotate configuration for netdata"
  990. install_netdata_logrotate
  991. # -----------------------------------------------------------------------------
  992. progress "Read installation options from netdata.conf"
  993. # create an empty config if it does not exist
  994. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  995. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  996. # port
  997. defport=19999
  998. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  999. # directories
  1000. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  1001. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  1002. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  1003. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  1004. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  1005. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  1006. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  1007. NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
  1008. cat << OPTIONSEOF
  1009. Permissions
  1010. - netdata user : ${NETDATA_USER}
  1011. - netdata group : ${NETDATA_GROUP}
  1012. - root user : ${ROOT_USER}
  1013. Directories
  1014. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  1015. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  1016. - netdata log dir : ${NETDATA_LOG_DIR}
  1017. - netdata run dir : ${NETDATA_RUN_DIR}
  1018. - netdata lib dir : ${NETDATA_LIB_DIR}
  1019. - netdata web dir : ${NETDATA_WEB_DIR}
  1020. - netdata cache dir : ${NETDATA_CACHE_DIR}
  1021. Other
  1022. - netdata port : ${NETDATA_PORT}
  1023. OPTIONSEOF
  1024. # -----------------------------------------------------------------------------
  1025. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  1026. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  1027. # this is needed if NETDATA_PREFIX is not empty
  1028. if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
  1029. warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
  1030. fi
  1031. fi
  1032. # --- stock conf dir ----
  1033. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  1034. [ -L "${NETDATA_USER_CONFIG_DIR}/orig" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/orig"
  1035. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/orig"
  1036. # --- web dir ----
  1037. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  1038. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  1039. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  1040. fi
  1041. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  1042. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  1043. # --- data dirs ----
  1044. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  1045. if [ ! -d "${x}" ]; then
  1046. echo >&2 "Creating directory '${x}'"
  1047. if ! run mkdir -p "${x}"; then
  1048. warning "Failed to create ${x}, it must be created by hand or the Netdata Agent will not be able to be started."
  1049. fi
  1050. fi
  1051. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  1052. #run find "${x}" -type f -exec chmod 0660 {} \;
  1053. #run find "${x}" -type d -exec chmod 0770 {} \;
  1054. done
  1055. run chmod 755 "${NETDATA_LOG_DIR}"
  1056. # --- claiming dir ----
  1057. if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
  1058. echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
  1059. if ! run mkdir -p "${NETDATA_CLAIMING_DIR}"; then
  1060. warning "failed to create ${NETDATA_CLAIMING_DIR}, it will need to be created manually."
  1061. fi
  1062. fi
  1063. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
  1064. run chmod 770 "${NETDATA_CLAIMING_DIR}"
  1065. # --- plugins ----
  1066. if [ "$(id -u)" -eq 0 ]; then
  1067. # find the admin group
  1068. admin_group=
  1069. test -z "${admin_group}" && get_group root > /dev/null 2>&1 && admin_group="root"
  1070. test -z "${admin_group}" && get_group daemon > /dev/null 2>&1 && admin_group="daemon"
  1071. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  1072. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  1073. run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1074. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1075. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  1076. # shellcheck disable=SC2086
  1077. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
  1078. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  1079. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  1080. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1081. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1082. capabilities=0
  1083. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1084. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1085. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  1086. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  1087. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  1088. fi
  1089. fi
  1090. if [ $capabilities -eq 0 ]; then
  1091. # fix apps.plugin to be setuid to root
  1092. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1093. fi
  1094. fi
  1095. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" ]; then
  1096. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  1097. capabilities=0
  1098. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1099. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  1100. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"; then
  1101. # if we managed to setcap, but we fail to execute debugfs.plugin setuid to root
  1102. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  1103. fi
  1104. fi
  1105. if [ $capabilities -eq 0 ]; then
  1106. # fix debugfs.plugin to be setuid to root
  1107. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  1108. fi
  1109. fi
  1110. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin" ]; then
  1111. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  1112. capabilities=0
  1113. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1114. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  1115. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"; then
  1116. capabilities=1
  1117. fi
  1118. fi
  1119. if [ $capabilities -eq 0 ]; then
  1120. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  1121. fi
  1122. fi
  1123. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin" ]; then
  1124. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1125. capabilities=0
  1126. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1127. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1128. if run setcap cap_dac_read_search,cap_syslog+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"; then
  1129. capabilities=1
  1130. fi
  1131. fi
  1132. if [ $capabilities -eq 0 ]; then
  1133. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1134. fi
  1135. fi
  1136. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  1137. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1138. capabilities=0
  1139. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  1140. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1141. 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
  1142. capabilities=1
  1143. fi
  1144. fi
  1145. if [ $capabilities -eq 0 ]; then
  1146. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1147. fi
  1148. fi
  1149. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
  1150. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1151. capabilities=0
  1152. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  1153. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1154. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"; then
  1155. capabilities=1
  1156. fi
  1157. fi
  1158. if [ $capabilities -eq 0 ]; then
  1159. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1160. fi
  1161. fi
  1162. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  1163. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1164. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1165. fi
  1166. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  1167. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1168. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1169. fi
  1170. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  1171. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1172. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1173. fi
  1174. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  1175. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1176. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1177. fi
  1178. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
  1179. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1180. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1181. fi
  1182. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  1183. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1184. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1185. fi
  1186. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  1187. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1188. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1189. fi
  1190. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners" ]; then
  1191. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  1192. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  1193. fi
  1194. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo" ]; then
  1195. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  1196. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  1197. fi
  1198. else
  1199. # non-privileged user installation
  1200. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  1201. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1202. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  1203. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1204. fi
  1205. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1206. # -----------------------------------------------------------------------------
  1207. # govercomp compares go.d.plugin versions. Exit codes:
  1208. # 0 - version1 == version2
  1209. # 1 - version1 > version2
  1210. # 2 - version2 > version1
  1211. # 3 - error
  1212. # shellcheck disable=SC2086
  1213. govercomp() {
  1214. # version in file:
  1215. # - v0.14.0
  1216. #
  1217. # 'go.d.plugin -v' output variants:
  1218. # - go.d.plugin, version: unknown
  1219. # - go.d.plugin, version: v0.14.1
  1220. # - go.d.plugin, version: v0.14.1-dirty
  1221. # - go.d.plugin, version: v0.14.1-1-g4c5f98c
  1222. # - go.d.plugin, version: v0.14.1-1-g4c5f98c-dirty
  1223. # we need to compare only MAJOR.MINOR.PATCH part
  1224. ver1=$(echo "$1" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
  1225. ver2=$(echo "$2" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
  1226. if [ ${#ver1} -eq 0 ] || [ ${#ver2} -eq 0 ]; then
  1227. return 3
  1228. fi
  1229. num1=$(echo $ver1 | grep -o -E '\.' | wc -l)
  1230. num2=$(echo $ver2 | grep -o -E '\.' | wc -l)
  1231. if [ ${num1} -ne ${num2} ]; then
  1232. return 3
  1233. fi
  1234. for i in $(seq 1 $((num1+1))); do
  1235. x=$(echo $ver1 | cut -d'.' -f$i)
  1236. y=$(echo $ver2 | cut -d'.' -f$i)
  1237. if [ "${x}" -gt "${y}" ]; then
  1238. return 1
  1239. elif [ "${y}" -gt "${x}" ]; then
  1240. return 2
  1241. fi
  1242. done
  1243. return 0
  1244. }
  1245. should_install_go() {
  1246. if [ -n "${NETDATA_DISABLE_GO+x}" ]; then
  1247. return 1
  1248. fi
  1249. version_in_file="$(cat packaging/go.d.version 2> /dev/null)"
  1250. binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2> /dev/null)
  1251. govercomp "$version_in_file" "$binary_version"
  1252. case $? in
  1253. 0) return 1 ;; # =
  1254. 2) return 1 ;; # <
  1255. *) return 0 ;; # >, error
  1256. esac
  1257. }
  1258. install_go() {
  1259. if ! should_install_go; then
  1260. return 0
  1261. fi
  1262. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing go.d.plugin."
  1263. # When updating this value, ensure correct checksums in packaging/go.d.checksums
  1264. GO_PACKAGE_VERSION="$(cat packaging/go.d.version)"
  1265. ARCH_MAP='
  1266. i386::386
  1267. i686::386
  1268. x86_64::amd64
  1269. aarch64::arm64
  1270. armv64::arm64
  1271. armv6l::arm
  1272. armv7l::arm
  1273. armv5tel::arm
  1274. '
  1275. progress "Install go.d.plugin"
  1276. ARCH=$(uname -m)
  1277. OS=$(uname -s | tr '[:upper:]' '[:lower:]')
  1278. for index in ${ARCH_MAP}; do
  1279. KEY="${index%%::*}"
  1280. VALUE="${index##*::}"
  1281. if [ "$KEY" = "$ARCH" ]; then
  1282. ARCH="${VALUE}"
  1283. break
  1284. fi
  1285. done
  1286. tmp="$(mktemp -d -t netdata-go-XXXXXX)"
  1287. GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}.tar.gz"
  1288. if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" ]; then
  1289. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
  1290. else
  1291. progress "Using provided go.d tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}"
  1292. run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" "${tmp}/${GO_PACKAGE_BASENAME}"
  1293. fi
  1294. if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" ]; then
  1295. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
  1296. else
  1297. progress "Using provided config file for go.d ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}"
  1298. run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" "${tmp}/config.tar.gz"
  1299. fi
  1300. if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
  1301. run_failed "go.d plugin download failed, go.d plugin will not be available"
  1302. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  1303. echo >&2
  1304. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1305. return 0
  1306. fi
  1307. grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
  1308. grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2> /dev/null
  1309. # Checksum validation
  1310. if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
  1311. echo >&2 "go.d plugin checksum validation failure."
  1312. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  1313. echo >&2
  1314. run_failed "go.d.plugin package files checksum validation failed. go.d.plugin will not be available."
  1315. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1316. return 0
  1317. fi
  1318. # Install new files
  1319. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
  1320. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
  1321. run tar --no-same-owner -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
  1322. run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
  1323. run tar --no-same-owner -xf "${tmp}/${GO_PACKAGE_BASENAME}"
  1324. run mv "${GO_PACKAGE_BASENAME%.tar.gz}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1325. if [ "$(id -u)" -eq 0 ]; then
  1326. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1327. fi
  1328. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1329. rm -rf "${tmp}"
  1330. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1331. }
  1332. install_go
  1333. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin" ]; then
  1334. if command -v setcap 1>/dev/null 2>&1; then
  1335. 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"
  1336. fi
  1337. fi
  1338. should_install_ebpf() {
  1339. if [ "${NETDATA_DISABLE_EBPF:=0}" -eq 1 ]; then
  1340. run_failed "eBPF has been explicitly disabled, it will not be available in this install."
  1341. return 1
  1342. fi
  1343. if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
  1344. if [ "${NETDATA_DISABLE_EBPF:=1}" -eq 0 ]; then
  1345. run_failed "Currently eBPF is only supported on Linux on X86_64."
  1346. fi
  1347. return 1
  1348. fi
  1349. # Check Kernel Config
  1350. if ! run "${INSTALLER_DIR}"/packaging/check-kernel-config.sh; then
  1351. warning "Kernel unsupported or missing required config (eBPF may not work on your system)"
  1352. fi
  1353. return 0
  1354. }
  1355. remove_old_ebpf() {
  1356. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin" ]; then
  1357. echo >&2 "Removing alpha eBPF collector."
  1358. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin"
  1359. fi
  1360. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf" ]; then
  1361. echo >&2 "Removing alpha eBPF stock file"
  1362. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf"
  1363. fi
  1364. if [ -f "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" ]; then
  1365. echo >&2 "Renaming eBPF configuration file."
  1366. mv "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" "${NETDATA_PREFIX}/etc/netdata/ebpf.d.conf"
  1367. fi
  1368. # Added to remove eBPF programs with name pattern: NAME_VERSION.SUBVERSION.PATCH
  1369. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.0.o" ]; then
  1370. echo >&2 "Removing old eBPF programs with patch."
  1371. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.*.o
  1372. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.*.o
  1373. fi
  1374. # Remove old eBPF program to store new eBPF program inside subdirectory
  1375. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.o" ]; then
  1376. echo >&2 "Removing old eBPF programs installed in old directory."
  1377. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.o
  1378. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.o
  1379. fi
  1380. # Remove old eBPF programs that did not have "rhf" suffix
  1381. if [ ! -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/pnetdata_ebpf_process.3.10.rhf.o" ]; then
  1382. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/"*.o
  1383. fi
  1384. # Remove old reject list from previous directory
  1385. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt" ]; then
  1386. echo >&2 "Removing old ebpf_kernel_reject_list.txt."
  1387. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt"
  1388. fi
  1389. # Remove old reset script
  1390. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh" ]; then
  1391. echo >&2 "Removing old reset_netdata_trace.sh."
  1392. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh"
  1393. fi
  1394. }
  1395. install_ebpf() {
  1396. if ! should_install_ebpf; then
  1397. return 0
  1398. fi
  1399. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing eBPF code."
  1400. remove_old_ebpf
  1401. progress "Installing eBPF plugin"
  1402. # Detect libc
  1403. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  1404. EBPF_VERSION="$(cat packaging/ebpf.version)"
  1405. EBPF_TARBALL="netdata-kernel-collector-${libc}-${EBPF_VERSION}.tar.xz"
  1406. tmp="$(mktemp -d -t netdata-ebpf-XXXXXX)"
  1407. if ! fetch_and_verify "ebpf" \
  1408. "https://github.com/netdata/kernel-collector/releases/download/${EBPF_VERSION}/${EBPF_TARBALL}" \
  1409. "${EBPF_TARBALL}" \
  1410. "${tmp}" \
  1411. "${NETDATA_LOCAL_TARBALL_OVERRIDE_EBPF}"; then
  1412. run_failed "Failed to download eBPF collector package"
  1413. echo 2>&" Removing temporary directory ${tmp} ..."
  1414. rm -rf "${tmp}"
  1415. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1416. return 1
  1417. fi
  1418. echo >&2 " Extracting ${EBPF_TARBALL} ..."
  1419. tar --no-same-owner -xf "${tmp}/${EBPF_TARBALL}" -C "${tmp}"
  1420. # chown everything to root:netdata before we start copying out of our package
  1421. run chown -R root:netdata "${tmp}"
  1422. if [ ! -d "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d ]; then
  1423. mkdir "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1424. RET=$?
  1425. if [ "${RET}" != "0" ]; then
  1426. rm -rf "${tmp}"
  1427. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1428. return 1
  1429. fi
  1430. fi
  1431. run cp -a -v "${tmp}"/*netdata_ebpf_*.o "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1432. rm -rf "${tmp}"
  1433. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1434. }
  1435. progress "eBPF Kernel Collector"
  1436. install_ebpf
  1437. should_install_fluentbit() {
  1438. if [ "$(uname -s)" = "Darwin" ]; then
  1439. return 1
  1440. fi
  1441. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  1442. warning "netdata-installer.sh run with --disable-logsmanagement, Fluent-Bit installation is skipped."
  1443. return 1
  1444. elif [ "${FLUENT_BIT_BUILD_SUCCESS:=0}" -eq 0 ]; then
  1445. run_failed "Fluent-Bit was not built successfully, Netdata Logs Management support will be disabled in this build."
  1446. return 1
  1447. elif [ ! -f fluent-bit/build/lib/libfluent-bit.so ]; then
  1448. run_failed "libfluent-bit.so is missing, Netdata Logs Management support will be disabled in this build."
  1449. return 1
  1450. fi
  1451. return 0
  1452. }
  1453. install_fluentbit() {
  1454. if ! should_install_fluentbit; then
  1455. enable_feature PLUGIN_LOGS_MANAGEMENT 0
  1456. return 0
  1457. fi
  1458. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Fluent-Bit."
  1459. run chown "root:${NETDATA_GROUP}" fluent-bit/build/lib
  1460. run chmod 0644 fluent-bit/build/lib/libfluent-bit.so
  1461. run cp -a -v fluent-bit/build/lib/libfluent-bit.so "${NETDATA_PREFIX}"/usr/lib/netdata
  1462. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1463. }
  1464. progress "Installing Fluent-Bit plugin"
  1465. install_fluentbit
  1466. # -----------------------------------------------------------------------------
  1467. progress "Telemetry configuration"
  1468. # Opt-out from telemetry program
  1469. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  1470. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  1471. else
  1472. 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"
  1473. fi
  1474. # -----------------------------------------------------------------------------
  1475. progress "Install netdata at system init"
  1476. # By default we assume the shutdown/startup of the Netdata Agent are effectively
  1477. # without any system supervisor/init like SystemD or SysV. So we assume the most
  1478. # basic startup/shutdown commands...
  1479. NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
  1480. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  1481. if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
  1482. # If docker runs systemd for some weird reason, let the install proceed
  1483. is_systemd_running="NO"
  1484. if command -v pidof > /dev/null 2>&1; then
  1485. is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
  1486. else
  1487. is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
  1488. fi
  1489. if [ "${is_systemd_running}" = "1" ]; then
  1490. echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
  1491. install_netdata_service || run_failed "Cannot install netdata init service."
  1492. else
  1493. echo >&2 "We are running within a docker container, will not be installing netdata service"
  1494. fi
  1495. echo >&2
  1496. else
  1497. install_netdata_service || run_failed "Cannot install netdata init service."
  1498. fi
  1499. # -----------------------------------------------------------------------------
  1500. # check if we can re-start netdata
  1501. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  1502. started=0
  1503. if [ ${DONOTSTART} -eq 1 ]; then
  1504. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1505. else
  1506. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  1507. fatal "Cannot start netdata!" I000D
  1508. fi
  1509. started=1
  1510. run_ok "netdata started!"
  1511. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  1512. fi
  1513. run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1514. if [ "$(uname)" = "Linux" ]; then
  1515. # -------------------------------------------------------------------------
  1516. progress "Check KSM (kernel memory deduper)"
  1517. ksm_is_available_but_disabled() {
  1518. cat << KSM1
  1519. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  1520. You have kernel memory de-duper (called Kernel Same-page Merging,
  1521. or KSM) available, but it is not currently enabled.
  1522. To enable it run:
  1523. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  1524. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  1525. If you enable it, you will save 40-60% of netdata memory.
  1526. KSM1
  1527. }
  1528. ksm_is_not_available() {
  1529. cat << KSM2
  1530. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  1531. It seems you do not have kernel memory de-duper (called Kernel Same-page
  1532. Merging, or KSM) available.
  1533. To enable it, you need a kernel built with CONFIG_KSM=y
  1534. If you can have it, you will save 40-60% of netdata memory.
  1535. KSM2
  1536. }
  1537. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  1538. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  1539. ksm_is_available_but_disabled
  1540. fi
  1541. else
  1542. ksm_is_not_available
  1543. fi
  1544. fi
  1545. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1546. # -----------------------------------------------------------------------------
  1547. progress "Check apps.plugin"
  1548. if [ "$(id -u)" -ne 0 ]; then
  1549. cat << SETUID_WARNING
  1550. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  1551. Since you have installed netdata as a normal user, to have apps.plugin collect
  1552. all the needed data, you have to give it the access rights it needs, by running
  1553. either of the following sets of commands:
  1554. To run apps.plugin with escalated capabilities:
  1555. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1556. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1557. ${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}
  1558. or, to run apps.plugin as root:
  1559. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1560. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1561. apps.plugin is performing a hard-coded function of data collection for all
  1562. running processes. It cannot be instructed from the netdata daemon to perform
  1563. any task, so it is pretty safe to do this.
  1564. SETUID_WARNING
  1565. fi
  1566. fi
  1567. # -----------------------------------------------------------------------------
  1568. progress "Copy uninstaller"
  1569. if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
  1570. echo >&2 "Removing uninstaller from old location"
  1571. rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
  1572. fi
  1573. 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"
  1574. chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  1575. # -----------------------------------------------------------------------------
  1576. progress "Basic netdata instructions"
  1577. cat << END
  1578. netdata by default listens on all IPs on port ${NETDATA_PORT},
  1579. so you can access it with:
  1580. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  1581. To stop netdata run:
  1582. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  1583. To start netdata run:
  1584. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  1585. END
  1586. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
  1587. echo >&2
  1588. # -----------------------------------------------------------------------------
  1589. progress "Installing (but not enabling) the netdata updater tool"
  1590. install_netdata_updater || run_failed "Cannot install netdata updater tool."
  1591. # -----------------------------------------------------------------------------
  1592. progress "Wrap up environment set up"
  1593. # Save environment variables
  1594. echo >&2 "Preparing .environment file"
  1595. cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  1596. # Created by installer
  1597. PATH="${PATH}"
  1598. CFLAGS="${CFLAGS}"
  1599. LDFLAGS="${LDFLAGS}"
  1600. MAKEOPTS="${MAKEOPTS}"
  1601. NETDATA_TMPDIR="${TMPDIR}"
  1602. NETDATA_PREFIX="${NETDATA_PREFIX}"
  1603. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS}"
  1604. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  1605. INSTALL_UID="$(id -u)"
  1606. NETDATA_GROUP="${NETDATA_GROUP}"
  1607. REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
  1608. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  1609. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
  1610. NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
  1611. EOF
  1612. run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
  1613. echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
  1614. cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  1615. new_installation
  1616. EOF
  1617. print_deferred_errors
  1618. # -----------------------------------------------------------------------------
  1619. echo >&2
  1620. progress "We are done!"
  1621. if [ ${started} -eq 1 ]; then
  1622. netdata_banner
  1623. progress "is installed and running now!"
  1624. else
  1625. netdata_banner
  1626. progress "is installed now!"
  1627. fi
  1628. echo >&2 " enjoy real-time performance and health monitoring..."
  1629. echo >&2
  1630. exit 0