netdata-installer.sh 69 KB

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