netdata-installer.sh 67 KB

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