netdata-installer.sh 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
  4. uniquepath() {
  5. path=""
  6. tmp="$(mktemp)"
  7. (echo "${PATH}" | tr ":" "\n") > "$tmp"
  8. while read -r REPLY;
  9. do
  10. if echo "${path}" | grep -v "(^|:)${REPLY}(:|$)"; then
  11. [ -n "${path}" ] && path="${path}:"
  12. path="${path}${REPLY}"
  13. fi
  14. done < "$tmp"
  15. rm "$tmp"
  16. [ -n "${path}" ]
  17. export PATH="${path%:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin}"
  18. } > /dev/null
  19. uniquepath
  20. PROGRAM="$0"
  21. NETDATA_SOURCE_DIR="$(pwd)"
  22. INSTALLER_DIR="$(dirname "${PROGRAM}")"
  23. if [ "${NETDATA_SOURCE_DIR}" != "${INSTALLER_DIR}" ] && [ "${INSTALLER_DIR}" != "." ]; then
  24. echo >&2 "Warning: you are currently in '${NETDATA_SOURCE_DIR}' but the installer is in '${INSTALLER_DIR}'."
  25. fi
  26. # -----------------------------------------------------------------------------
  27. # reload the user profile
  28. # shellcheck source=/dev/null
  29. [ -f /etc/profile ] && . /etc/profile
  30. # make sure /etc/profile does not change our current directory
  31. cd "${NETDATA_SOURCE_DIR}" || exit 1
  32. # -----------------------------------------------------------------------------
  33. # figure out an appropriate temporary directory
  34. _cannot_use_tmpdir() {
  35. testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
  36. ret=0
  37. if [ -z "${testfile}" ]; then
  38. return "${ret}"
  39. fi
  40. if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then
  41. if chmod +x "${testfile}"; then
  42. if [ "$("${testfile}")" = "SUCCESS" ]; then
  43. ret=1
  44. fi
  45. fi
  46. fi
  47. rm -f "${testfile}"
  48. return "${ret}"
  49. }
  50. if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
  51. if _cannot_use_tmpdir /tmp; then
  52. if _cannot_use_tmpdir "${PWD}"; then
  53. echo >&2
  54. echo >&2 "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."
  55. exit 1
  56. else
  57. TMPDIR="${PWD}"
  58. fi
  59. else
  60. TMPDIR="/tmp"
  61. fi
  62. fi
  63. # -----------------------------------------------------------------------------
  64. # set up handling for deferred error messages
  65. NETDATA_DEFERRED_ERRORS=""
  66. defer_error() {
  67. NETDATA_DEFERRED_ERRORS="${NETDATA_DEFERRED_ERRORS}\n* ${1}"
  68. }
  69. defer_error_highlighted() {
  70. NETDATA_DEFERRED_ERRORS="${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_DEFERRED_ERRORS}\n* ${1}${TPUT_RESET}"
  71. }
  72. print_deferred_errors() {
  73. if [ -n "${NETDATA_DEFERRED_ERRORS}" ]; then
  74. echo >&2
  75. echo >&2 "The following non-fatal errors were encountered during the installation process:"
  76. printf '%s' >&2 "${NETDATA_DEFERRED_ERRORS}"
  77. echo >&2
  78. fi
  79. }
  80. # -----------------------------------------------------------------------------
  81. # load the required functions
  82. if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
  83. # shellcheck source=packaging/installer/functions.sh
  84. . "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
  85. else
  86. # shellcheck source=packaging/installer/functions.sh
  87. . "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
  88. fi
  89. download_go() {
  90. download_file "${1}" "${2}" "go.d plugin" "go"
  91. }
  92. # make sure we save all commands we run
  93. # Variable is used by code in the packaging/installer/functions.sh
  94. # shellcheck disable=SC2034
  95. run_logfile="netdata-installer.log"
  96. # -----------------------------------------------------------------------------
  97. # fix PKG_CHECK_MODULES error
  98. if [ -d /usr/share/aclocal ]; then
  99. ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
  100. export ACLOCAL_PATH
  101. fi
  102. export LC_ALL=C
  103. umask 002
  104. # Be nice on production environments
  105. renice 19 $$ > /dev/null 2> /dev/null
  106. # you can set CFLAGS before running installer
  107. # shellcheck disable=SC2269
  108. LDFLAGS="${LDFLAGS}"
  109. CFLAGS="${CFLAGS--O2}"
  110. [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
  111. # shellcheck disable=SC2269
  112. ACLK="${ACLK}"
  113. # keep a log of this command
  114. {
  115. printf "\n# "
  116. date
  117. printf 'CFLAGS="%s" ' "${CFLAGS}"
  118. printf 'LDFLAGS="%s" ' "${LDFLAGS}"
  119. printf "%s" "${PROGRAM}" "${@}"
  120. printf "\n"
  121. } >> netdata-installer.log
  122. REINSTALL_OPTIONS="$(
  123. printf "%s" "${*}"
  124. printf "\n"
  125. )"
  126. # remove options that shown not be inherited by netdata-updater.sh
  127. REINSTALL_OPTIONS="$(echo "${REINSTALL_OPTIONS}" | sed 's/--dont-wait//g' | sed 's/--dont-start-it//g')"
  128. banner_nonroot_install() {
  129. cat << NONROOTNOPREFIX
  130. ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
  131. You are attempting to install netdata as non-root, but you plan
  132. to install it in system paths.
  133. Please set an installation prefix, like this:
  134. $PROGRAM ${@} --install /tmp
  135. or, run the installer as root:
  136. sudo $PROGRAM ${@}
  137. We suggest to install it as root, or certain data collectors will
  138. not be able to work. Netdata drops root privileges when running.
  139. So, if you plan to keep it, install it as root to get the full
  140. functionality.
  141. NONROOTNOPREFIX
  142. }
  143. banner_root_notify() {
  144. cat << NONROOT
  145. ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
  146. You are about to install netdata as a non-root user.
  147. Netdata will work, but a few data collection modules that
  148. require root access will fail.
  149. If you are installing netdata permanently on your system, run
  150. the installer like this:
  151. ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
  152. NONROOT
  153. }
  154. usage() {
  155. netdata_banner
  156. progress "installer command line options"
  157. cat << HEREDOC
  158. USAGE: ${PROGRAM} [options]
  159. where options include:
  160. --install <path> Install netdata in <path>. Ex. --install /opt will put netdata in /opt/netdata.
  161. --dont-start-it Do not (re)start netdata after installation.
  162. --dont-wait Run installation in non-interactive mode.
  163. --stable-channel Use packages from GitHub release pages instead of nightly updates.
  164. This results in less frequent updates.
  165. --nightly-channel Use most recent nightly updates instead of GitHub releases.
  166. This results in more frequent updates.
  167. --disable-go Disable installation of go.d.plugin.
  168. --disable-ebpf Disable eBPF Kernel plugin. Default: enabled.
  169. --disable-cloud Disable all Netdata Cloud functionality.
  170. --require-cloud Fail the install if it can't build Netdata Cloud support.
  171. --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
  172. --disable-plugin-freeipmi Explicitly disable the FreeIPMI plugin.
  173. --disable-https Explicitly disable TLS support.
  174. --disable-dbengine Explicitly disable DB engine support.
  175. --enable-plugin-nfacct Enable nfacct plugin. Default: enable it when libmnl and libnetfilter_acct are available.
  176. --disable-plugin-nfacct Explicitly disable the nfacct plugin.
  177. --enable-plugin-xenstat Enable the xenstat plugin. Default: enable it when libxenstat and libyajl are available.
  178. --disable-plugin-xenstat Explicitly disable the xenstat plugin.
  179. --enable-exporting-kinesis Enable AWS Kinesis exporting connector. Default: enable it when libaws_cpp_sdk_kinesis
  180. and its dependencies are available.
  181. --disable-exporting-kinesis Explicitly disable AWS Kinesis exporting connector.
  182. --enable-exporting-prometheus-remote-write Enable Prometheus remote write exporting connector. Default: enable it
  183. when libprotobuf and libsnappy are available.
  184. --disable-exporting-prometheus-remote-write Explicitly disable Prometheus remote write exporting connector.
  185. --enable-exporting-mongodb Enable MongoDB exporting connector. Default: enable it when libmongoc is available.
  186. --disable-exporting-mongodb Explicitly disable MongoDB exporting connector.
  187. --enable-exporting-pubsub Enable Google Cloud PubSub exporting connector. Default: enable it when
  188. libgoogle_cloud_cpp_pubsub_protos and its dependencies are available.
  189. --disable-exporting-pubsub Explicitly disable Google Cloud PubSub exporting connector.
  190. --enable-lto Enable link-time optimization. Default: disabled.
  191. --disable-lto Explicitly disable link-time optimization.
  192. --enable-ml Enable anomaly detection with machine learning. Default: autodetect.
  193. --disable-ml Explicitly disable anomaly detection with machine learning.
  194. --disable-x86-sse Disable SSE instructions & optimizations. Default: enabled.
  195. --use-system-lws Use a system copy of libwebsockets instead of bundled copy. Default: bundled.
  196. --use-system-protobuf Use a system copy of libprotobuf instead of bundled copy. Default: bundled.
  197. --zlib-is-really-here
  198. --libs-are-really-here If you see errors about missing zlib or libuuid but you know it is available, you might
  199. have a broken pkg-config. Use this option to proceed without checking pkg-config.
  200. --disable-telemetry Opt-out from our anonymous telemetry program. (DISABLE_TELEMETRY=1)
  201. --skip-available-ram-check Skip checking the amount of RAM the system has and pretend it has enough to build safely.
  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, bash v4+, python v2 or v3, node.js
  219. HEREDOC
  220. }
  221. DONOTSTART=0
  222. DONOTWAIT=0
  223. NETDATA_PREFIX=
  224. LIBS_ARE_HERE=0
  225. NETDATA_ENABLE_ML=""
  226. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
  227. RELEASE_CHANNEL="nightly" # valid values are 'nightly' and 'stable'
  228. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY:-"no"}"
  229. while [ -n "${1}" ]; do
  230. case "${1}" in
  231. "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
  232. "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
  233. "--use-system-protobuf")
  234. USE_SYSTEM_PROTOBUF=1
  235. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--without-bundled-protobuf}" | sed 's/$/ --without-bundled-protobuf/g')"
  236. ;;
  237. "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
  238. "--dont-start-it") DONOTSTART=1 ;;
  239. "--dont-wait") DONOTWAIT=1 ;;
  240. "--auto-update" | "-u") ;;
  241. "--auto-update-type") ;;
  242. "--stable-channel") RELEASE_CHANNEL="stable" ;;
  243. "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
  244. "--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-freeipmi)}" | sed 's/$/ --enable-plugin-freeipmi/g')" ;;
  245. "--disable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-freeipmi)}" | sed 's/$/ --disable-plugin-freeipmi/g')" ;;
  246. "--disable-https") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-https)}" | sed 's/$/ --disable-plugin-https/g')" ;;
  247. "--disable-dbengine")
  248. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-dbengine)}" | sed 's/$/ --disable-dbengine/g')"
  249. NETDATA_DISABLE_DBENGINE=1
  250. ;;
  251. "--enable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-nfacct)}" | sed 's/$/ --enable-plugin-nfacct/g')" ;;
  252. "--disable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-nfacct)}" | sed 's/$/ --disable-plugin-nfacct/g')" ;;
  253. "--enable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-xenstat)}" | sed 's/$/ --enable-plugin-xenstat/g')" ;;
  254. "--disable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-xenstat)}" | sed 's/$/ --disable-plugin-xenstat/g')" ;;
  255. "--enable-exporting-kinesis" | "--enable-backend-kinesis")
  256. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-kinesis)}" | sed 's/$/ --enable-exporting-kinesis/g')" ;;
  257. "--disable-exporting-kinesis" | "--disable-backend-kinesis")
  258. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-kinesis)}" | sed 's/$/ --disable-exporting-kinesis/g')" ;;
  259. "--enable-exporting-prometheus-remote-write" | "--enable-backend-prometheus-remote-write")
  260. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-prometheus-remote-write)}" | sed 's/$/ --enable-exporting-prometheus-remote-write/g')" ;;
  261. "--disable-exporting-prometheus-remote-write" | "--disable-backend-prometheus-remote-write")
  262. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-prometheus-remote-write)}" | sed 's/$/ --disable-exporting-prometheus-remote-write/g')"
  263. NETDATA_DISABLE_PROMETHEUS=1
  264. ;;
  265. "--enable-exporting-mongodb" | "--enable-backend-mongodb")
  266. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-mongodb)}" | sed 's/$/ --enable-exporting-mongodb/g')" ;;
  267. "--disable-exporting-mongodb" | "--disable-backend-mongodb")
  268. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-mongodb)}" | sed 's/$/ --disable-exporting-mongodb/g')" ;;
  269. "--enable-exporting-pubsub") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-pubsub)}" | sed 's/$/ --enable-exporting-pubsub/g')" ;;
  270. "--disable-exporting-pubsub") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-pubsub)}" | sed 's/$/ --disable-exporting-pubsub/g')" ;;
  271. "--enable-lto") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-lto)}" | sed 's/$/ --enable-lto/g')" ;;
  272. "--enable-ml")
  273. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-ml)}" | sed 's/$/ --enable-ml/g')"
  274. NETDATA_ENABLE_ML=1
  275. ;;
  276. "--disable-ml")
  277. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ml)}" | sed 's/$/ --disable-ml/g')"
  278. NETDATA_ENABLE_ML=0
  279. ;;
  280. "--enable-ml-tests") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-ml-tests)}" | sed 's/$/ --enable-ml-tests/g')" ;;
  281. "--disable-ml-tests") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ml-tests)}" | sed 's/$/ --disable-ml-tests/g')" ;;
  282. "--disable-lto") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-lto)}" | sed 's/$/ --disable-lto/g')" ;;
  283. "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-x86-sse)}" | sed 's/$/ --disable-x86-sse/g')" ;;
  284. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
  285. "--disable-go") NETDATA_DISABLE_GO=1 ;;
  286. "--enable-ebpf") NETDATA_DISABLE_EBPF=0 ;;
  287. "--disable-ebpf") NETDATA_DISABLE_EBPF=1 NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')" ;;
  288. "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
  289. "--disable-cloud")
  290. if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
  291. echo "Cloud explicitly enabled, ignoring --disable-cloud."
  292. else
  293. NETDATA_DISABLE_CLOUD=1
  294. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-cloud)}" | sed 's/$/ --disable-cloud/g')"
  295. fi
  296. ;;
  297. "--require-cloud")
  298. if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
  299. echo "Cloud explicitly disabled, ignoring --require-cloud."
  300. else
  301. NETDATA_REQUIRE_CLOUD=1
  302. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-cloud)}" | sed 's/$/ --enable-cloud/g')"
  303. fi
  304. ;;
  305. "--build-json-c")
  306. NETDATA_BUILD_JSON_C=1
  307. ;;
  308. "--build-judy")
  309. NETDATA_BUILD_JUDY=1
  310. ;;
  311. "--install")
  312. NETDATA_PREFIX="${2}/netdata"
  313. shift 1
  314. ;;
  315. "--install-no-prefix")
  316. NETDATA_PREFIX="${2}"
  317. shift 1
  318. ;;
  319. "--help" | "-h")
  320. usage
  321. exit 1
  322. ;;
  323. *)
  324. run_failed "I cannot understand option '$1'."
  325. usage
  326. exit 1
  327. ;;
  328. esac
  329. shift 1
  330. done
  331. if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
  332. [ -n "$DISABLE_TELEMETRY" ] ||
  333. [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
  334. [ -n "$DO_NOT_TRACK" ]; then
  335. NETDATA_DISABLE_TELEMETRY=1
  336. fi
  337. make="make"
  338. # See: https://github.com/netdata/netdata/issues/9163
  339. if [ "$(uname -s)" = "FreeBSD" ]; then
  340. make="gmake"
  341. NETDATA_CONFIGURE_OPTIONS="$NETDATA_CONFIGURE_OPTIONS --disable-dependency-tracking"
  342. fi
  343. if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
  344. mega="$((1024 * 1024))"
  345. base=1024
  346. scale=256
  347. # shellcheck disable=SC2086
  348. if [ -n "${MAKEOPTS}" ]; then
  349. proc_count="$(echo ${MAKEOPTS} | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
  350. else
  351. proc_count="$(find_processors)"
  352. fi
  353. target_ram="$((base * mega + (scale * mega * (proc_count - 1))))"
  354. total_ram="$(grep MemTotal /proc/meminfo | cut -d ':' -f 2 | tr -d ' kB')"
  355. total_ram="$((total_ram * 1024))"
  356. if [ "${total_ram}" -le "$((base * mega))" ] && [ -z "${NETDATA_ENABLE_ML}" ]; then
  357. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ml)}" | sed 's/$/ --disable-ml/g')"
  358. NETDATA_ENABLE_ML=0
  359. fi
  360. if [ -z "${MAKEOPTS}" ]; then
  361. MAKEOPTS="-j${proc_count}"
  362. while [ "${target_ram}" -gt "${total_ram}" ] && [ "${proc_count}" -gt 1 ]; do
  363. proc_count="$((proc_count - 1))"
  364. target_ram="$((base * mega + (scale * mega * (proc_count - 1))))"
  365. MAKEOPTS="-j${proc_count}"
  366. done
  367. else
  368. if [ "${target_ram}" -gt "${total_ram}" ] && [ "${proc_count}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
  369. target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  370. total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  371. run_failed "Netdata needs ${target_ram} of RAM to safely install, but this system only has ${total_ram}."
  372. run_failed "Insufficient RAM available for an install. Try reducing the number of processes used for the install using the \$MAKEOPTS variable."
  373. exit 2
  374. fi
  375. fi
  376. fi
  377. # set default make options
  378. if [ -z "${MAKEOPTS}" ]; then
  379. MAKEOPTS="-j$(find_processors)"
  380. elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
  381. MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
  382. fi
  383. if [ "$(id -u)" -ne 0 ]; then
  384. if [ -z "${NETDATA_PREFIX}" ]; then
  385. netdata_banner
  386. progress "wrong command line options!"
  387. banner_nonroot_install "${@}"
  388. exit 1
  389. else
  390. banner_root_notify "${@}"
  391. fi
  392. fi
  393. netdata_banner
  394. progress "real-time performance monitoring, done right!"
  395. cat << BANNER1
  396. You are about to build and install netdata to your system.
  397. The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
  398. any temporary files. You can override this by setting \$TMPDIR to a
  399. writable directory where you can execute files.
  400. It will be installed at these locations:
  401. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  402. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  403. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  404. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  405. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  406. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  407. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  408. BANNER1
  409. [ "$(id -u)" -eq 0 ] && cat << BANNER2
  410. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  411. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  412. BANNER2
  413. cat << BANNER3
  414. This installer allows you to change the installation path.
  415. Press Control-C and run the same command with --help for help.
  416. BANNER3
  417. if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
  418. cat << BANNER4
  419. ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
  420. Anonymous usage stats will be collected and sent to Netdata.
  421. To opt-out, pass --disable-telemetry option to the installer or export
  422. the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
  423. (e.g: export DISABLE_TELEMETRY=1).
  424. BANNER4
  425. fi
  426. have_autotools=
  427. if [ "$(type autoreconf 2> /dev/null)" ]; then
  428. autoconf_maj_min() {
  429. OLDIFS=$IFS
  430. IFS=.-
  431. maj=$1
  432. min=$2
  433. # shellcheck disable=SC2046
  434. set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
  435. # shellcheck disable=SC2086
  436. eval $maj=\$1 $min=\$2
  437. IFS=$OLDIFS
  438. }
  439. autoconf_maj_min AMAJ AMIN
  440. if [ "$AMAJ" -gt 2 ]; then
  441. have_autotools=Y
  442. elif [ "$AMAJ" -eq 2 ] && [ "$AMIN" -ge 60 ]; then
  443. have_autotools=Y
  444. else
  445. echo "Found autotools $AMAJ.$AMIN"
  446. fi
  447. else
  448. echo "No autotools found"
  449. fi
  450. if [ ! "$have_autotools" ]; then
  451. if [ -f configure ]; then
  452. echo "Will skip autoreconf step"
  453. else
  454. netdata_banner
  455. progress "autotools v2.60 required"
  456. cat << "EOF"
  457. -------------------------------------------------------------------------------
  458. autotools 2.60 or later is required
  459. Sorry, you do not seem to have autotools 2.60 or later, which is
  460. required to build from the git sources of netdata.
  461. EOF
  462. exit 1
  463. fi
  464. fi
  465. if [ ${DONOTWAIT} -eq 0 ]; then
  466. if [ -n "${NETDATA_PREFIX}" ]; then
  467. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  468. else
  469. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  470. fi
  471. read -r REPLY
  472. if [ "$REPLY" != '' ]; then
  473. exit 1
  474. fi
  475. fi
  476. build_error() {
  477. netdata_banner
  478. progress "sorry, it failed to build..."
  479. cat << EOF
  480. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  481. Sorry! netdata failed to build...
  482. You may need to check these:
  483. 1. The package uuid-dev (or libuuid-devel) has to be installed.
  484. If your system cannot find libuuid, although it is installed
  485. run me with the option: --libs-are-really-here
  486. 2. The package zlib1g-dev (or zlib-devel) has to be installed.
  487. If your system cannot find zlib, although it is installed
  488. run me with the option: --libs-are-really-here
  489. 3. The package json-c-dev (or json-c-devel) has to be installed.
  490. If your system cannot find json-c, although it is installed
  491. run me with the option: --libs-are-really-here
  492. 4. You need basic build tools installed, like:
  493. gcc make autoconf automake pkg-config
  494. Autoconf version 2.60 or higher is required.
  495. If you still cannot get it to build, ask for help at github:
  496. https://github.com/netdata/netdata/issues
  497. EOF
  498. trap - EXIT
  499. exit 1
  500. }
  501. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  502. shift
  503. echo >&2 "ok, assuming libs are really installed."
  504. export ZLIB_CFLAGS=" "
  505. export ZLIB_LIBS="-lz"
  506. export UUID_CFLAGS=" "
  507. export UUID_LIBS="-luuid"
  508. fi
  509. trap build_error EXIT
  510. # -----------------------------------------------------------------------------
  511. build_protobuf() {
  512. env_cmd=''
  513. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  514. env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
  515. fi
  516. cd "${1}" > /dev/null || return 1
  517. # shellcheck disable=SC2086
  518. if ! run ${env_cmd} ./configure --disable-shared --without-zlib --disable-dependency-tracking --with-pic; then
  519. cd - > /dev/null || return 1
  520. return 1
  521. fi
  522. # shellcheck disable=SC2086
  523. if ! run ${env_cmd} $make ${MAKEOPTS}; then
  524. cd - > /dev/null || return 1
  525. return 1
  526. fi
  527. cd - > /dev/null || return 1
  528. }
  529. copy_protobuf() {
  530. target_dir="${PWD}/externaldeps/protobuf"
  531. run mkdir -p "${target_dir}" || return 1
  532. run cp -a "${1}/src" "${target_dir}" || return 1
  533. }
  534. bundle_protobuf() {
  535. if [ -n "${NETDATA_DISABLE_CLOUD}" ] && [ -n "${NETDATA_DISABLE_PROMETHEUS}" ]; then
  536. echo "Skipping protobuf"
  537. return 0
  538. fi
  539. if [ -n "${USE_SYSTEM_PROTOBUF}" ]; then
  540. echo "Skipping protobuf"
  541. defer_error "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."
  542. return 0
  543. fi
  544. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling protobuf."
  545. PROTOBUF_PACKAGE_VERSION="$(cat packaging/protobuf.version)"
  546. tmp="$(mktemp -d -t netdata-protobuf-XXXXXX)"
  547. PROTOBUF_PACKAGE_BASENAME="protobuf-cpp-${PROTOBUF_PACKAGE_VERSION}.tar.gz"
  548. if fetch_and_verify "protobuf" \
  549. "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_PACKAGE_VERSION}/${PROTOBUF_PACKAGE_BASENAME}" \
  550. "${PROTOBUF_PACKAGE_BASENAME}" \
  551. "${tmp}" \
  552. "${NETDATA_LOCAL_TARBALL_VERRIDE_PROTOBUF}"; then
  553. if run tar --no-same-owner -xf "${tmp}/${PROTOBUF_PACKAGE_BASENAME}" -C "${tmp}" &&
  554. build_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
  555. copy_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
  556. rm -rf "${tmp}"; then
  557. run_ok "protobuf built and prepared."
  558. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-protobuf"
  559. else
  560. run_failed "Failed to build protobuf."
  561. defer_error_highlighted "Failed to build protobuf. You may not be able to connect this node to Netdata Cloud."
  562. fi
  563. else
  564. run_failed "Unable to fetch sources for protobuf."
  565. defer_error_highlighted "Unable to fetch sources for protobuf. You may not be able to connect this node to Netdata Cloud."
  566. fi
  567. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  568. }
  569. bundle_protobuf
  570. # -----------------------------------------------------------------------------
  571. build_judy() {
  572. env_cmd=''
  573. libtoolize="libtoolize"
  574. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  575. env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
  576. fi
  577. if [ "$(uname)" = "Darwin" ]; then
  578. libtoolize="glibtoolize"
  579. fi
  580. cd "${1}" > /dev/null || return 1
  581. # shellcheck disable=SC2086
  582. if run ${env_cmd} ${libtoolize} --force --copy &&
  583. run ${env_cmd} aclocal &&
  584. run ${env_cmd} autoheader &&
  585. run ${env_cmd} automake --add-missing --force --copy --include-deps &&
  586. run ${env_cmd} autoconf &&
  587. run ${env_cmd} ./configure &&
  588. run ${env_cmd} ${make} ${MAKEOPTS} -C src &&
  589. run ${env_cmd} ar -r src/libJudy.a src/Judy*/*.o; then
  590. cd - > /dev/null || return 1
  591. else
  592. cd - > /dev/null || return 1
  593. return 1
  594. fi
  595. }
  596. copy_judy() {
  597. target_dir="${PWD}/externaldeps/libJudy"
  598. run mkdir -p "${target_dir}" || return 1
  599. run cp "${1}/src/libJudy.a" "${target_dir}/libJudy.a" || return 1
  600. run cp "${1}/src/Judy.h" "${target_dir}/Judy.h" || return 1
  601. }
  602. bundle_judy() {
  603. # If --build-judy flag or no Judy on the system and we're building the dbengine, bundle our own libJudy.
  604. # shellcheck disable=SC2235,SC2030,SC2031
  605. if [ -n "${NETDATA_DISABLE_DBENGINE}" ] || ([ -z "${NETDATA_BUILD_JUDY}" ] && [ -e /usr/include/Judy.h ]); then
  606. return 0
  607. elif [ -n "${NETDATA_BUILD_JUDY}" ]; then
  608. progress "User requested bundling of libJudy, building it now"
  609. elif [ ! -e /usr/include/Judy.h ]; then
  610. progress "/usr/include/Judy.h does not exist, but we need libJudy, building our own copy"
  611. fi
  612. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libJudy."
  613. progress "Prepare libJudy"
  614. JUDY_PACKAGE_VERSION="$(cat packaging/judy.version)"
  615. tmp="$(mktemp -d -t netdata-judy-XXXXXX)"
  616. JUDY_PACKAGE_BASENAME="v${JUDY_PACKAGE_VERSION}.tar.gz"
  617. if fetch_and_verify "judy" \
  618. "https://github.com/netdata/libjudy/archive/${JUDY_PACKAGE_BASENAME}" \
  619. "${JUDY_PACKAGE_BASENAME}" \
  620. "${tmp}" \
  621. "${NETDATA_LOCAL_TARBALL_OVERRIDE_JUDY}"; then
  622. if run tar --no-same-owner -xf "${tmp}/${JUDY_PACKAGE_BASENAME}" -C "${tmp}" &&
  623. build_judy "${tmp}/libjudy-${JUDY_PACKAGE_VERSION}" &&
  624. copy_judy "${tmp}/libjudy-${JUDY_PACKAGE_VERSION}" &&
  625. rm -rf "${tmp}"; then
  626. run_ok "libJudy built and prepared."
  627. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-libJudy"
  628. else
  629. run_failed "Failed to build libJudy."
  630. if [ -n "${NETDATA_BUILD_JUDY}" ]; then
  631. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  632. exit 1
  633. else
  634. defer_error_highlighted "Failed to build libJudy. dbengine support will be disabled."
  635. fi
  636. fi
  637. else
  638. run_failed "Unable to fetch sources for libJudy."
  639. if [ -n "${NETDATA_BUILD_JUDY}" ]; then
  640. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  641. exit 1
  642. else
  643. defer_error_highlighted "Unable to fetch sources for libJudy. dbengine support will be disabled."
  644. fi
  645. fi
  646. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  647. }
  648. bundle_judy
  649. # -----------------------------------------------------------------------------
  650. build_jsonc() {
  651. env_cmd=''
  652. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  653. env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
  654. fi
  655. cd "${1}" > /dev/null || exit 1
  656. # shellcheck disable=SC2086
  657. run ${env_cmd} cmake -DBUILD_SHARED_LIBS=OFF .
  658. # shellcheck disable=SC2086
  659. run ${env_cmd} ${make} ${MAKEOPTS}
  660. cd - > /dev/null || exit 1
  661. }
  662. copy_jsonc() {
  663. target_dir="${PWD}/externaldeps/jsonc"
  664. run mkdir -p "${target_dir}" "${target_dir}/json-c" || return 1
  665. run cp "${1}/libjson-c.a" "${target_dir}/libjson-c.a" || return 1
  666. # shellcheck disable=SC2086
  667. run cp ${1}/*.h "${target_dir}/json-c" || return 1
  668. }
  669. bundle_jsonc() {
  670. # If --build-json-c flag or not json-c on system, then bundle our own json-c
  671. if [ -z "${NETDATA_BUILD_JSON_C}" ] && pkg-config json-c; then
  672. return 0
  673. fi
  674. if [ -z "$(command -v cmake)" ]; then
  675. run_failed "Could not find cmake, which is required to build JSON-C. The install process will continue, but Netdata Cloud support will be disabled."
  676. defer_error_highlighted "Could not find cmake, which is required to build JSON-C. The install process will continue, but Netdata Cloud support will be disabled."
  677. return 0
  678. fi
  679. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling JSON-C."
  680. progress "Prepare JSON-C"
  681. JSONC_PACKAGE_VERSION="$(cat packaging/jsonc.version)"
  682. tmp="$(mktemp -d -t netdata-jsonc-XXXXXX)"
  683. JSONC_PACKAGE_BASENAME="json-c-${JSONC_PACKAGE_VERSION}.tar.gz"
  684. if fetch_and_verify "jsonc" \
  685. "https://github.com/json-c/json-c/archive/${JSONC_PACKAGE_BASENAME}" \
  686. "${JSONC_PACKAGE_BASENAME}" \
  687. "${tmp}" \
  688. "${NETDATA_LOCAL_TARBALL_OVERRIDE_JSONC}"; then
  689. if run tar --no-same-owner -xf "${tmp}/${JSONC_PACKAGE_BASENAME}" -C "${tmp}" &&
  690. build_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  691. copy_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  692. rm -rf "${tmp}"; then
  693. run_ok "JSON-C built and prepared."
  694. else
  695. run_failed "Failed to build JSON-C."
  696. defer_error_highlighted "Failed to build JSON-C. Netdata Cloud support will be disabled."
  697. fi
  698. else
  699. run_failed "Unable to fetch sources for JSON-C."
  700. defer_error_highlighted "Unable to fetch sources for JSON-C. Netdata Cloud support will be disabled."
  701. fi
  702. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  703. }
  704. bundle_jsonc
  705. # -----------------------------------------------------------------------------
  706. get_kernel_version() {
  707. r="$(uname -r | cut -f 1 -d '-')"
  708. tmpfile="$(mktemp)"
  709. echo "${r}" | tr '.' ' ' > "${tmpfile}"
  710. read -r maj min patch _ < "${tmpfile}"
  711. rm -f "${tmpfile}"
  712. printf "%03d%03d%03d" "${maj}" "${min}" "${patch}"
  713. }
  714. detect_libc() {
  715. libc=
  716. if ldd --version 2>&1 | grep -q -i glibc; then
  717. echo >&2 " Detected GLIBC"
  718. libc="glibc"
  719. elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
  720. echo >&2 " Detected GLIBC"
  721. libc="glibc"
  722. elif ldd --version 2>&1 | grep -q -i musl; then
  723. echo >&2 " Detected musl"
  724. libc="musl"
  725. else
  726. ls_path=$(command -v ls)
  727. if [ -n "${ls_path}" ] ; then
  728. cmd=$(ldd "$ls_path" | grep -w libc | cut -d" " -f 3)
  729. if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
  730. echo >&2 " Detected GLIBC"
  731. libc="glibc"
  732. fi
  733. fi
  734. fi
  735. if [ -z "$libc" ]; then
  736. echo >&2 " ERROR: Cannot detect a supported libc on your system!"
  737. return 1
  738. fi
  739. echo "${libc}"
  740. return 0
  741. }
  742. rename_libbpf_packaging() {
  743. if [ "$(get_kernel_version)" -ge "004014000" ]; then
  744. cp packaging/current_libbpf.checksums packaging/libbpf.checksums
  745. cp packaging/current_libbpf.version packaging/libbpf.version
  746. else
  747. cp packaging/libbpf_0_0_9.checksums packaging/libbpf.checksums
  748. cp packaging/libbpf_0_0_9.version packaging/libbpf.version
  749. fi
  750. }
  751. build_libbpf() {
  752. cd "${1}/src" > /dev/null || exit 1
  753. mkdir root build
  754. # shellcheck disable=SC2086
  755. run env CFLAGS=-fPIC CXXFLAGS= LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
  756. cd - > /dev/null || exit 1
  757. }
  758. copy_libbpf() {
  759. target_dir="${PWD}/externaldeps/libbpf"
  760. if [ "$(uname -m)" = x86_64 ]; then
  761. lib_subdir="lib64"
  762. else
  763. lib_subdir="lib"
  764. fi
  765. run mkdir -p "${target_dir}" || return 1
  766. run cp "${1}/usr/${lib_subdir}/libbpf.a" "${target_dir}/libbpf.a" || return 1
  767. run cp -r "${1}/usr/include" "${target_dir}" || return 1
  768. run cp -r "${1}/include/uapi" "${target_dir}/include" || return 1
  769. }
  770. bundle_libbpf() {
  771. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  772. return 0
  773. fi
  774. # When libc is not detected, we do not have necessity to compile libbpf and we should not do download of eBPF programs
  775. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  776. if [ -z "$libc" ]; then
  777. NETDATA_DISABLE_EBPF=1
  778. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')"
  779. return 0
  780. fi
  781. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  782. rename_libbpf_packaging
  783. progress "Prepare libbpf"
  784. LIBBPF_PACKAGE_VERSION="$(cat packaging/libbpf.version)"
  785. tmp="$(mktemp -d -t netdata-libbpf-XXXXXX)"
  786. LIBBPF_PACKAGE_BASENAME="v${LIBBPF_PACKAGE_VERSION}.tar.gz"
  787. if fetch_and_verify "libbpf" \
  788. "https://github.com/netdata/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
  789. "${LIBBPF_PACKAGE_BASENAME}" \
  790. "${tmp}" \
  791. "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBBPF}"; then
  792. if run tar --no-same-owner -xf "${tmp}/${LIBBPF_PACKAGE_BASENAME}" -C "${tmp}" &&
  793. build_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  794. copy_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  795. rm -rf "${tmp}"; then
  796. run_ok "libbpf built and prepared."
  797. else
  798. run_failed "Failed to build libbpf."
  799. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
  800. exit 1
  801. else
  802. defer_error_highlighted "Failed to build libbpf. You may not be able to use eBPF plugin."
  803. fi
  804. fi
  805. else
  806. run_failed "Unable to fetch sources for libbpf."
  807. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
  808. exit 1
  809. else
  810. defer_error_highlighted "Unable to fetch sources for libbpf. You may not be able to use eBPF plugin."
  811. fi
  812. fi
  813. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  814. }
  815. bundle_libbpf
  816. copy_co_re() {
  817. cp -R "${1}/includes" "collectors/ebpf.plugin/"
  818. }
  819. bundle_ebpf_co_re() {
  820. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  821. return 0
  822. fi
  823. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  824. progress "eBPF CO-RE"
  825. CORE_PACKAGE_VERSION="$(cat packaging/ebpf-co-re.version)"
  826. tmp="$(mktemp -d -t netdata-ebpf-co-re-XXXXXX)"
  827. CORE_PACKAGE_BASENAME="netdata-ebpf-co-re-glibc-${CORE_PACKAGE_VERSION}.tar.xz"
  828. if fetch_and_verify "ebpf-co-re" \
  829. "https://github.com/netdata/ebpf-co-re/releases/download/${CORE_PACKAGE_VERSION}/${CORE_PACKAGE_BASENAME}" \
  830. "${CORE_PACKAGE_BASENAME}" \
  831. "${tmp}" \
  832. "${NETDATA_LOCAL_TARBALL_OVERRIDE_CORE}"; then
  833. if run tar --no-same-owner -xf "${tmp}/${CORE_PACKAGE_BASENAME}" -C "${tmp}" &&
  834. copy_co_re "${tmp}" &&
  835. rm -rf "${tmp}"; then
  836. run_ok "libbpf built and prepared."
  837. else
  838. run_failed "Failed to get eBPF CO-RE files."
  839. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
  840. exit 1
  841. else
  842. defer_error_highlighted "Failed to get CO-RE. You will not be able to use eBPF plugin."
  843. NETDATA_DISABLE_EBPF=1
  844. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')"
  845. fi
  846. fi
  847. else
  848. run_failed "Unable to fetch sources for libbpf."
  849. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ ${NETDATA_DISABLE_EBPF} = 0 ]; then
  850. exit 1
  851. else
  852. defer_error_highlighted "Unable to fetch sources for eBPF CO-RE. You will not be able to use eBPF plugin."
  853. NETDATA_DISABLE_EBPF=1
  854. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')"
  855. fi
  856. fi
  857. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  858. }
  859. bundle_ebpf_co_re
  860. # -----------------------------------------------------------------------------
  861. # If we have the dashboard switching logic, make sure we're on the classic
  862. # dashboard during the install (updates don't work correctly otherwise).
  863. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
  864. "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
  865. fi
  866. # -----------------------------------------------------------------------------
  867. # By default, `git` does not update local tags based on remotes. Because
  868. # we use the most recent tag as part of our version determination in
  869. # our build, this can lead to strange versions that look ancient but are
  870. # actually really recent. To avoid this, try and fetch tags if we're
  871. # working in a git checkout.
  872. if [ -d ./.git ] ; then
  873. echo >&2
  874. progress "Updating tags in git to ensure a consistent version number"
  875. run git fetch -t || true
  876. fi
  877. # -----------------------------------------------------------------------------
  878. echo >&2
  879. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
  880. progress "Run autotools to configure the build environment"
  881. if [ "$have_autotools" ]; then
  882. run autoreconf -ivf || exit 1
  883. fi
  884. # shellcheck disable=SC2086
  885. run ./configure \
  886. --prefix="${NETDATA_PREFIX}/usr" \
  887. --sysconfdir="${NETDATA_PREFIX}/etc" \
  888. --localstatedir="${NETDATA_PREFIX}/var" \
  889. --libexecdir="${NETDATA_PREFIX}/usr/libexec" \
  890. --libdir="${NETDATA_PREFIX}/usr/lib" \
  891. --with-zlib \
  892. --with-math \
  893. --with-user=netdata \
  894. ${NETDATA_CONFIGURE_OPTIONS} \
  895. CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" || exit 1
  896. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  897. # remove the build_error hook
  898. trap - EXIT
  899. # -----------------------------------------------------------------------------
  900. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
  901. progress "Cleanup compilation directory"
  902. run $make clean
  903. # -----------------------------------------------------------------------------
  904. progress "Compile netdata"
  905. # shellcheck disable=SC2086
  906. run $make ${MAKEOPTS} || exit 1
  907. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  908. # -----------------------------------------------------------------------------
  909. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
  910. progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
  911. # migrate existing configuration files
  912. # for node.d and charts.d
  913. if [ -d "${NETDATA_PREFIX}/etc/netdata" ]; then
  914. # the configuration directory exists
  915. if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]; then
  916. run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
  917. fi
  918. # move the charts.d config files
  919. for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat; do
  920. for y in "" ".old" ".orig"; do
  921. if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" ] && [ ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]; then
  922. run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
  923. fi
  924. done
  925. done
  926. if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]; then
  927. run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
  928. fi
  929. fi
  930. # -----------------------------------------------------------------------------
  931. # shellcheck disable=SC2230
  932. md5sum="$(command -v md5sum 2> /dev/null || command -v md5 2> /dev/null)"
  933. deleted_stock_configs=0
  934. if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" ]; then
  935. progress "Backup existing netdata configuration before installing it"
  936. config_signature_matches() {
  937. md5="${1}"
  938. file="${2}"
  939. if [ -f "configs.signatures" ]; then
  940. grep "\['${md5}'\]='${file}'" "configs.signatures" > /dev/null
  941. return $?
  942. fi
  943. return 1
  944. }
  945. # clean up stock config files from the user configuration directory
  946. (find -L "${NETDATA_PREFIX}/etc/netdata" -type f -not -path '*/\.*' -not -path "${NETDATA_PREFIX}/etc/netdata/orig/*" \( -name '*.conf.old' -o -name '*.conf' -o -name '*.conf.orig' -o -name '*.conf.installer_backup.*' \)) | while IFS= read -r x; do
  947. if [ -f "${x}" ]; then
  948. # find it relative filename
  949. f=$("$x" | sed "${NETDATA_PREFIX}/etc/netdata/")
  950. # find the stock filename
  951. t=$("${f}" | sed ".conf.installer_backup.*/.conf")
  952. t=$("${t}" | sed ".conf.old/.conf")
  953. t=$("${t}" | sed ".conf.orig/.conf")
  954. t=$("${t}" | sed "orig//")
  955. if [ -z "${md5sum}" ] || [ ! -x "${md5sum}" ]; then
  956. # we don't have md5sum - keep it
  957. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED}is not known to distribution${TPUT_RESET}. Keeping it."
  958. else
  959. # find its checksum
  960. md5="$(${md5sum} < "${x}" | cut -d ' ' -f 1)"
  961. if config_signature_matches "${md5}" "${t}"; then
  962. # it is a stock version - remove it
  963. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version of '${t}'."
  964. run rm -f "${x}"
  965. # shellcheck disable=SC2030
  966. deleted_stock_configs=$((deleted_stock_configs + 1))
  967. else
  968. # edited by user - keep it
  969. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} does not match stock of${TPUT_RESET} ${TPUT_CYAN}'${t}'${TPUT_RESET}. Keeping it."
  970. fi
  971. fi
  972. fi
  973. done
  974. fi
  975. touch "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done"
  976. # -----------------------------------------------------------------------------
  977. progress "Install netdata"
  978. run $make install || exit 1
  979. # -----------------------------------------------------------------------------
  980. progress "Fix generated files permissions"
  981. run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.timer -a \! -name \*.logrotate -a \! -name \.install-type -exec chmod 755 {} \;
  982. # -----------------------------------------------------------------------------
  983. progress "Creating standard user and groups for netdata"
  984. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  985. NETDATA_ADDED_TO_GROUPS=""
  986. if [ "$(id -u)" -eq 0 ]; then
  987. progress "Adding group 'netdata'"
  988. portable_add_group netdata || :
  989. progress "Adding user 'netdata'"
  990. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  991. progress "Assign user 'netdata' to required groups"
  992. for g in ${NETDATA_WANTED_GROUPS}; do
  993. # shellcheck disable=SC2086
  994. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  995. done
  996. else
  997. run_failed "The installer does not run as root. Nothing to do for user and groups"
  998. fi
  999. # -----------------------------------------------------------------------------
  1000. progress "Install logrotate configuration for netdata"
  1001. install_netdata_logrotate
  1002. # -----------------------------------------------------------------------------
  1003. progress "Read installation options from netdata.conf"
  1004. # create an empty config if it does not exist
  1005. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  1006. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1007. # function to extract values from the config file
  1008. config_option() {
  1009. section="${1}"
  1010. key="${2}"
  1011. value="${3}"
  1012. if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  1013. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  1014. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  1015. -W get "${section}" "${key}" "${value}" ||
  1016. echo "${value}"
  1017. else
  1018. echo "${value}"
  1019. fi
  1020. }
  1021. # the user netdata will run as
  1022. if [ "$(id -u)" = "0" ]; then
  1023. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  1024. ROOT_USER="root"
  1025. else
  1026. NETDATA_USER="${USER}"
  1027. ROOT_USER="${USER}"
  1028. fi
  1029. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}")"
  1030. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  1031. echo >&2 "Netdata user and group is finally set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  1032. # port
  1033. defport=19999
  1034. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  1035. # directories
  1036. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  1037. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  1038. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  1039. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  1040. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  1041. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  1042. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  1043. NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
  1044. cat << OPTIONSEOF
  1045. Permissions
  1046. - netdata user : ${NETDATA_USER}
  1047. - netdata group : ${NETDATA_GROUP}
  1048. - root user : ${ROOT_USER}
  1049. Directories
  1050. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  1051. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  1052. - netdata log dir : ${NETDATA_LOG_DIR}
  1053. - netdata run dir : ${NETDATA_RUN_DIR}
  1054. - netdata lib dir : ${NETDATA_LIB_DIR}
  1055. - netdata web dir : ${NETDATA_WEB_DIR}
  1056. - netdata cache dir : ${NETDATA_CACHE_DIR}
  1057. Other
  1058. - netdata port : ${NETDATA_PORT}
  1059. OPTIONSEOF
  1060. # -----------------------------------------------------------------------------
  1061. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  1062. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  1063. # this is needed if NETDATA_PREFIX is not empty
  1064. run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
  1065. fi
  1066. # --- stock conf dir ----
  1067. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  1068. helplink="000.-.USE.THE.orig.LINK.TO.COPY.AND.EDIT.STOCK.CONFIG.FILES"
  1069. # shellcheck disable=SC2031
  1070. [ ${deleted_stock_configs} -eq 0 ] && helplink=""
  1071. for link in "orig" "${helplink}"; do
  1072. if [ -n "${link}" ]; then
  1073. [ -L "${NETDATA_USER_CONFIG_DIR}/${link}" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/${link}"
  1074. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/${link}"
  1075. fi
  1076. done
  1077. # --- web dir ----
  1078. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  1079. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  1080. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  1081. fi
  1082. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  1083. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  1084. # --- data dirs ----
  1085. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  1086. if [ ! -d "${x}" ]; then
  1087. echo >&2 "Creating directory '${x}'"
  1088. run mkdir -p "${x}" || exit 1
  1089. fi
  1090. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  1091. #run find "${x}" -type f -exec chmod 0660 {} \;
  1092. #run find "${x}" -type d -exec chmod 0770 {} \;
  1093. done
  1094. run chmod 755 "${NETDATA_LOG_DIR}"
  1095. # --- claiming dir ----
  1096. if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
  1097. echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
  1098. run mkdir -p "${NETDATA_CLAIMING_DIR}" || exit 1
  1099. fi
  1100. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
  1101. run chmod 770 "${NETDATA_CLAIMING_DIR}"
  1102. # --- plugins ----
  1103. if [ "$(id -u)" -eq 0 ]; then
  1104. # find the admin group
  1105. admin_group=
  1106. test -z "${admin_group}" && getent group root > /dev/null 2>&1 && admin_group="root"
  1107. test -z "${admin_group}" && getent group daemon > /dev/null 2>&1 && admin_group="daemon"
  1108. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  1109. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  1110. run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1111. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1112. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  1113. # shellcheck disable=SC2086
  1114. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
  1115. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  1116. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  1117. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1118. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1119. capabilities=0
  1120. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1121. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1122. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  1123. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  1124. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  1125. fi
  1126. fi
  1127. if [ $capabilities -eq 0 ]; then
  1128. # fix apps.plugin to be setuid to root
  1129. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1130. fi
  1131. fi
  1132. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  1133. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1134. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1135. fi
  1136. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  1137. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1138. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1139. fi
  1140. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  1141. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1142. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1143. fi
  1144. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  1145. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1146. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1147. 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\""
  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. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1152. run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1153. fi
  1154. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  1155. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1156. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1157. fi
  1158. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
  1159. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1160. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1161. fi
  1162. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  1163. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1164. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1165. fi
  1166. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  1167. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1168. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1169. fi
  1170. else
  1171. # non-privileged user installation
  1172. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  1173. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1174. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  1175. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1176. fi
  1177. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1178. # -----------------------------------------------------------------------------
  1179. # govercomp compares go.d.plugin versions. Exit codes:
  1180. # 0 - version1 == version2
  1181. # 1 - version1 > version2
  1182. # 2 - version2 > version1
  1183. # 3 - error
  1184. # shellcheck disable=SC2086
  1185. govercomp() {
  1186. # version in file:
  1187. # - v0.14.0
  1188. #
  1189. # 'go.d.plugin -v' output variants:
  1190. # - go.d.plugin, version: unknown
  1191. # - go.d.plugin, version: v0.14.1
  1192. # - go.d.plugin, version: v0.14.1-dirty
  1193. # - go.d.plugin, version: v0.14.1-1-g4c5f98c
  1194. # - go.d.plugin, version: v0.14.1-1-g4c5f98c-dirty
  1195. # we need to compare only MAJOR.MINOR.PATCH part
  1196. ver1=$(echo "$1" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
  1197. ver2=$(echo "$2" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
  1198. if [ ${#ver1} -eq 0 ] || [ ${#ver2} -eq 0 ]; then
  1199. return 3
  1200. fi
  1201. num1=$(echo $ver1 | grep -o -E '\.' | wc -l)
  1202. num2=$(echo $ver2 | grep -o -E '\.' | wc -l)
  1203. if [ ${num1} -ne ${num2} ]; then
  1204. return 3
  1205. fi
  1206. for i in $(seq 1 $((num1+1))); do
  1207. x=$(echo $ver1 | cut -d'.' -f$i)
  1208. y=$(echo $ver2 | cut -d'.' -f$i)
  1209. if [ "${x}" -gt "${y}" ]; then
  1210. return 1
  1211. elif [ "${y}" -gt "${x}" ]; then
  1212. return 2
  1213. fi
  1214. done
  1215. return 0
  1216. }
  1217. should_install_go() {
  1218. if [ -n "${NETDATA_DISABLE_GO+x}" ]; then
  1219. return 1
  1220. fi
  1221. version_in_file="$(cat packaging/go.d.version 2> /dev/null)"
  1222. binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2> /dev/null)
  1223. govercomp "$version_in_file" "$binary_version"
  1224. case $? in
  1225. 0) return 1 ;; # =
  1226. 2) return 1 ;; # <
  1227. *) return 0 ;; # >, error
  1228. esac
  1229. }
  1230. install_go() {
  1231. if ! should_install_go; then
  1232. return 0
  1233. fi
  1234. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing go.d.plugin."
  1235. # When updating this value, ensure correct checksums in packaging/go.d.checksums
  1236. GO_PACKAGE_VERSION="$(cat packaging/go.d.version)"
  1237. ARCH_MAP='
  1238. i386::386
  1239. i686::386
  1240. x86_64::amd64
  1241. aarch64::arm64
  1242. armv64::arm64
  1243. armv6l::arm
  1244. armv7l::arm
  1245. armv5tel::arm
  1246. '
  1247. progress "Install go.d.plugin"
  1248. ARCH=$(uname -m)
  1249. OS=$(uname -s | tr '[:upper:]' '[:lower:]')
  1250. for index in ${ARCH_MAP}; do
  1251. KEY="${index%%::*}"
  1252. VALUE="${index##*::}"
  1253. if [ "$KEY" = "$ARCH" ]; then
  1254. ARCH="${VALUE}"
  1255. break
  1256. fi
  1257. done
  1258. tmp="$(mktemp -d -t netdata-go-XXXXXX)"
  1259. GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}.tar.gz"
  1260. if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" ]; then
  1261. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
  1262. else
  1263. progress "Using provided go.d tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}"
  1264. run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" "${tmp}/${GO_PACKAGE_BASENAME}"
  1265. fi
  1266. if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" ]; then
  1267. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
  1268. else
  1269. progress "Using provided config file for go.d ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}"
  1270. run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" "${tmp}/config.tar.gz"
  1271. fi
  1272. if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
  1273. run_failed "go.d plugin download failed, go.d plugin will not be available"
  1274. defer_error "go.d plugin download failed, go.d plugin will not be available"
  1275. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  1276. echo >&2
  1277. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1278. return 0
  1279. fi
  1280. grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
  1281. grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2> /dev/null
  1282. # Checksum validation
  1283. if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
  1284. echo >&2 "go.d plugin checksum validation failure."
  1285. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  1286. echo >&2
  1287. run_failed "go.d.plugin package files checksum validation failed."
  1288. defer_error "go.d.plugin package files checksum validation failed, go.d.plugin will not be available"
  1289. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1290. return 0
  1291. fi
  1292. # Install new files
  1293. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
  1294. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
  1295. run tar --no-same-owner -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
  1296. run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
  1297. run tar --no-same-owner -xf "${tmp}/${GO_PACKAGE_BASENAME}"
  1298. run mv "${GO_PACKAGE_BASENAME%.tar.gz}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1299. if [ "$(id -u)" -eq 0 ]; then
  1300. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1301. fi
  1302. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1303. rm -rf "${tmp}"
  1304. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1305. }
  1306. install_go
  1307. should_install_ebpf() {
  1308. if [ "${NETDATA_DISABLE_EBPF:=0}" -eq 1 ]; then
  1309. run_failed "eBPF explicitly disabled."
  1310. defer_error "eBPF explicitly disabled."
  1311. return 1
  1312. fi
  1313. if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
  1314. run_failed "Currently eBPF is only supported on Linux on X86_64."
  1315. defer_error "Currently eBPF is only supported on Linux on X86_64."
  1316. return 1
  1317. fi
  1318. # Check Kernel Config
  1319. if ! run "${INSTALLER_DIR}"/packaging/check-kernel-config.sh; then
  1320. echo >&2 "Warning: Kernel unsupported or missing required config (eBPF may not work on your system)"
  1321. fi
  1322. return 0
  1323. }
  1324. remove_old_ebpf() {
  1325. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin" ]; then
  1326. echo >&2 "Removing alpha eBPF collector."
  1327. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin"
  1328. fi
  1329. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf" ]; then
  1330. echo >&2 "Removing alpha eBPF stock file"
  1331. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf"
  1332. fi
  1333. if [ -f "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" ]; then
  1334. echo >&2 "Renaming eBPF configuration file."
  1335. mv "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" "${NETDATA_PREFIX}/etc/netdata/ebpf.d.conf"
  1336. fi
  1337. # Added to remove eBPF programs with name pattern: NAME_VERSION.SUBVERSION.PATCH
  1338. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.0.o" ]; then
  1339. echo >&2 "Removing old eBPF programs with patch."
  1340. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.*.o
  1341. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.*.o
  1342. fi
  1343. # Remove old eBPF program to store new eBPF program inside subdirectory
  1344. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.o" ]; then
  1345. echo >&2 "Removing old eBPF programs installed in old directory."
  1346. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.o
  1347. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.o
  1348. fi
  1349. # Remove old reject list from previous directory
  1350. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt" ]; then
  1351. echo >&2 "Removing old ebpf_kernel_reject_list.txt."
  1352. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt"
  1353. fi
  1354. # Remove old reset script
  1355. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh" ]; then
  1356. echo >&2 "Removing old reset_netdata_trace.sh."
  1357. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh"
  1358. fi
  1359. }
  1360. install_ebpf() {
  1361. if ! should_install_ebpf; then
  1362. return 0
  1363. fi
  1364. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing eBPF code."
  1365. remove_old_ebpf
  1366. progress "Installing eBPF plugin"
  1367. # Detect libc
  1368. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  1369. EBPF_VERSION="$(cat packaging/ebpf.version)"
  1370. EBPF_TARBALL="netdata-kernel-collector-${libc}-${EBPF_VERSION}.tar.xz"
  1371. tmp="$(mktemp -d -t netdata-ebpf-XXXXXX)"
  1372. if ! fetch_and_verify "ebpf" \
  1373. "https://github.com/netdata/kernel-collector/releases/download/${EBPF_VERSION}/${EBPF_TARBALL}" \
  1374. "${EBPF_TARBALL}" \
  1375. "${tmp}" \
  1376. "${NETDATA_LOCAL_TARBALL_OVERRIDE_EBPF}"; then
  1377. run_failed "Failed to download eBPF collector package"
  1378. echo 2>&" Removing temporary directory ${tmp} ..."
  1379. rm -rf "${tmp}"
  1380. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1381. return 1
  1382. fi
  1383. echo >&2 " Extracting ${EBPF_TARBALL} ..."
  1384. tar --no-same-owner -xf "${tmp}/${EBPF_TARBALL}" -C "${tmp}"
  1385. # chown everything to root:netdata before we start copying out of our package
  1386. run chown -R root:netdata "${tmp}"
  1387. if [ ! -d "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d ]; then
  1388. mkdir "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1389. RET=$?
  1390. if [ "${RET}" != "0" ]; then
  1391. rm -rf "${tmp}"
  1392. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1393. return 1
  1394. fi
  1395. fi
  1396. run cp -a -v "${tmp}"/*netdata_ebpf_*.o "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1397. rm -rf "${tmp}"
  1398. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1399. }
  1400. progress "eBPF Kernel Collector"
  1401. install_ebpf
  1402. # -----------------------------------------------------------------------------
  1403. progress "Telemetry configuration"
  1404. # Opt-out from telemetry program
  1405. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  1406. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  1407. else
  1408. 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"
  1409. fi
  1410. # -----------------------------------------------------------------------------
  1411. progress "Install netdata at system init"
  1412. # By default we assume the shutdown/startup of the Netdata Agent are effectively
  1413. # without any system supervisor/init like SystemD or SysV. So we assume the most
  1414. # basic startup/shutdown commands...
  1415. NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
  1416. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  1417. if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
  1418. # If docker runs systemd for some weird reason, let the install proceed
  1419. is_systemd_running="NO"
  1420. if command -v pidof > /dev/null 2>&1; then
  1421. is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
  1422. else
  1423. is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
  1424. fi
  1425. if [ "${is_systemd_running}" = "1" ]; then
  1426. echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
  1427. install_netdata_service || run_failed "Cannot install netdata init service."
  1428. else
  1429. echo >&2 "We are running within a docker container, will not be installing netdata service"
  1430. fi
  1431. echo >&2
  1432. else
  1433. install_netdata_service || run_failed "Cannot install netdata init service."
  1434. fi
  1435. # -----------------------------------------------------------------------------
  1436. # check if we can re-start netdata
  1437. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  1438. started=0
  1439. if [ ${DONOTSTART} -eq 1 ]; then
  1440. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1441. else
  1442. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  1443. fatal "Cannot start netdata!"
  1444. fi
  1445. started=1
  1446. run_ok "netdata started!"
  1447. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  1448. fi
  1449. run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1450. if [ "$(uname)" = "Linux" ]; then
  1451. # -------------------------------------------------------------------------
  1452. progress "Check KSM (kernel memory deduper)"
  1453. ksm_is_available_but_disabled() {
  1454. cat << KSM1
  1455. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  1456. You have kernel memory de-duper (called Kernel Same-page Merging,
  1457. or KSM) available, but it is not currently enabled.
  1458. To enable it run:
  1459. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  1460. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  1461. If you enable it, you will save 40-60% of netdata memory.
  1462. KSM1
  1463. }
  1464. ksm_is_not_available() {
  1465. cat << KSM2
  1466. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  1467. It seems you do not have kernel memory de-duper (called Kernel Same-page
  1468. Merging, or KSM) available.
  1469. To enable it, you need a kernel built with CONFIG_KSM=y
  1470. If you can have it, you will save 40-60% of netdata memory.
  1471. KSM2
  1472. }
  1473. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  1474. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  1475. ksm_is_available_but_disabled
  1476. fi
  1477. else
  1478. ksm_is_not_available
  1479. fi
  1480. fi
  1481. # -----------------------------------------------------------------------------
  1482. progress "Check version.txt"
  1483. if [ ! -s web/gui/version.txt ]; then
  1484. cat << VERMSG
  1485. ${TPUT_BOLD}Version update check warning${TPUT_RESET}
  1486. The way you downloaded netdata, we cannot find its version. This means the
  1487. Update check on the dashboard, will not work.
  1488. If you want to have version update check, please re-install it
  1489. following the procedure in:
  1490. https://docs.netdata.cloud/packaging/installer/
  1491. VERMSG
  1492. fi
  1493. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1494. # -----------------------------------------------------------------------------
  1495. progress "Check apps.plugin"
  1496. if [ "$(id -u)" -ne 0 ]; then
  1497. cat << SETUID_WARNING
  1498. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  1499. Since you have installed netdata as a normal user, to have apps.plugin collect
  1500. all the needed data, you have to give it the access rights it needs, by running
  1501. either of the following sets of commands:
  1502. To run apps.plugin with escalated capabilities:
  1503. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1504. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1505. ${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}
  1506. or, to run apps.plugin as root:
  1507. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1508. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1509. apps.plugin is performing a hard-coded function of data collection for all
  1510. running processes. It cannot be instructed from the netdata daemon to perform
  1511. any task, so it is pretty safe to do this.
  1512. SETUID_WARNING
  1513. fi
  1514. fi
  1515. # -----------------------------------------------------------------------------
  1516. progress "Copy uninstaller"
  1517. if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
  1518. echo >&2 "Removing uninstaller from old location"
  1519. rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
  1520. fi
  1521. 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"
  1522. chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  1523. # -----------------------------------------------------------------------------
  1524. progress "Basic netdata instructions"
  1525. cat << END
  1526. netdata by default listens on all IPs on port ${NETDATA_PORT},
  1527. so you can access it with:
  1528. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  1529. To stop netdata run:
  1530. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  1531. To start netdata run:
  1532. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  1533. END
  1534. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
  1535. echo >&2
  1536. # -----------------------------------------------------------------------------
  1537. progress "Installing (but not enabling) the netdata updater tool"
  1538. cleanup_old_netdata_updater || run_failed "Cannot cleanup old netdata updater tool."
  1539. install_netdata_updater || run_failed "Cannot install netdata updater tool."
  1540. # -----------------------------------------------------------------------------
  1541. progress "Wrap up environment set up"
  1542. # Save environment variables
  1543. echo >&2 "Preparing .environment file"
  1544. cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  1545. # Created by installer
  1546. PATH="${PATH}"
  1547. CFLAGS="${CFLAGS}"
  1548. LDFLAGS="${LDFLAGS}"
  1549. MAKEOPTS="${MAKEOPTS}"
  1550. NETDATA_TMPDIR="${TMPDIR}"
  1551. NETDATA_PREFIX="${NETDATA_PREFIX}"
  1552. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
  1553. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  1554. INSTALL_UID="$(id -u)"
  1555. NETDATA_GROUP="${NETDATA_GROUP}"
  1556. REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
  1557. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  1558. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
  1559. NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
  1560. EOF
  1561. run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
  1562. echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
  1563. cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  1564. new_installation
  1565. EOF
  1566. print_deferred_errors
  1567. # -----------------------------------------------------------------------------
  1568. echo >&2
  1569. progress "We are done!"
  1570. if [ ${started} -eq 1 ]; then
  1571. netdata_banner
  1572. progress "is installed and running now!"
  1573. else
  1574. netdata_banner
  1575. progress "is installed now!"
  1576. fi
  1577. echo >&2 " enjoy real-time performance and health monitoring..."
  1578. echo >&2
  1579. exit 0