netdata-installer.sh 69 KB

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