netdata-installer.sh 68 KB

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