netdata-installer.sh 74 KB

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