netdata-installer.sh 69 KB

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