netdata-installer.sh 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701
  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. # make sure we save all commands we run
  87. # Variable is used by code in the packaging/installer/functions.sh
  88. # shellcheck disable=SC2034
  89. run_logfile="netdata-installer.log"
  90. # -----------------------------------------------------------------------------
  91. # fix PKG_CHECK_MODULES error
  92. if [ -d /usr/share/aclocal ]; then
  93. ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
  94. export ACLOCAL_PATH
  95. fi
  96. export LC_ALL=C
  97. umask 002
  98. # Be nice on production environments
  99. renice 19 $$ > /dev/null 2> /dev/null
  100. # you can set CFLAGS before running installer
  101. # shellcheck disable=SC2269
  102. LDFLAGS="${LDFLAGS}"
  103. CFLAGS="${CFLAGS-"-O2 -pipe"}"
  104. [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
  105. # shellcheck disable=SC2269
  106. ACLK="${ACLK}"
  107. # keep a log of this command
  108. {
  109. printf "\n# "
  110. date
  111. printf 'CFLAGS="%s" ' "${CFLAGS}"
  112. printf 'LDFLAGS="%s" ' "${LDFLAGS}"
  113. printf "%s" "${PROGRAM}" "${@}"
  114. printf "\n"
  115. } >> netdata-installer.log
  116. REINSTALL_OPTIONS="$(
  117. printf "%s" "${*}"
  118. printf "\n"
  119. )"
  120. # remove options that shown not be inherited by netdata-updater.sh
  121. REINSTALL_OPTIONS="$(echo "${REINSTALL_OPTIONS}" | sed 's/--dont-wait//g' | sed 's/--dont-start-it//g')"
  122. banner_nonroot_install() {
  123. cat << NONROOTNOPREFIX
  124. ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
  125. You are attempting to install netdata as a non-root user, but you plan
  126. to install it in system paths.
  127. Please set an installation prefix, like this:
  128. $PROGRAM ${@} --install-prefix /tmp
  129. or, run the installer as root:
  130. sudo $PROGRAM ${@}
  131. We suggest to install it as root, or certain data collectors will
  132. not be able to work. Netdata drops root privileges when running.
  133. So, if you plan to keep it, install it as root to get the full
  134. functionality.
  135. NONROOTNOPREFIX
  136. }
  137. banner_root_notify() {
  138. cat << NONROOT
  139. ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
  140. You are about to install netdata as a non-root user.
  141. Netdata will work, but a few data collection modules that
  142. require root access will fail.
  143. If you are installing netdata permanently on your system, run
  144. the installer like this:
  145. ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
  146. NONROOT
  147. }
  148. usage() {
  149. netdata_banner
  150. progress "installer command line options"
  151. cat << HEREDOC
  152. USAGE: ${PROGRAM} [options]
  153. where options include:
  154. --install-prefix <path> Install netdata in <path>. Ex. --install-prefix /opt will put netdata in /opt/netdata.
  155. --dont-start-it Do not (re)start netdata after installation.
  156. --dont-wait Run installation in non-interactive mode.
  157. --stable-channel Use packages from GitHub release pages instead of nightly updates.
  158. This results in less frequent updates.
  159. --nightly-channel Use most recent nightly updates instead of GitHub releases.
  160. This results in more frequent updates.
  161. --disable-ebpf Disable eBPF Kernel plugin. Default: enabled.
  162. --disable-cloud Disable all Netdata Cloud functionality.
  163. --require-cloud Fail the install if it can't build Netdata Cloud support.
  164. --force-legacy-cxx Force usage of an older C++ standard to allow building on older systems. This will usually be autodetected.
  165. --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
  166. --disable-plugin-freeipmi Explicitly disable the FreeIPMI plugin.
  167. --disable-https Explicitly disable TLS support.
  168. --disable-dbengine Explicitly disable DB engine support.
  169. --enable-plugin-go Enable the Go plugin. Default: Enabled when possible.
  170. --disable-plugin-go Disable the Go plugin.
  171. --disable-go Equivalent to --disable-go-plugin
  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 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_GO=1
  212. ENABLE_H2O=1
  213. ENABLE_CLOUD=1
  214. ENABLE_LOGS_MANAGEMENT=1
  215. ENABLE_LOGS_MANAGEMENT_TESTS=0
  216. FORCE_LEGACY_CXX=0
  217. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS-}"
  218. RELEASE_CHANNEL="nightly" # valid values are 'nightly' and 'stable'
  219. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY:-"no"}"
  220. while [ -n "${1}" ]; do
  221. case "${1}" in
  222. "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
  223. "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
  224. "--use-system-protobuf") USE_SYSTEM_PROTOBUF=1 ;;
  225. "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
  226. "--dont-start-it") DONOTSTART=1 ;;
  227. "--dont-wait") DONOTWAIT=1 ;;
  228. "--auto-update" | "-u") ;;
  229. "--auto-update-type") ;;
  230. "--stable-channel") RELEASE_CHANNEL="stable" ;;
  231. "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
  232. "--force-legacy-cxx") FORCE_LEGACY_CXX=1 ;;
  233. "--enable-plugin-freeipmi") ENABLE_FREEIPMI=1 ;;
  234. "--disable-plugin-freeipmi") ENABLE_FREEIPMI=0 ;;
  235. "--disable-https")
  236. ENABLE_DBENGINE=0
  237. ENABLE_H2O=0
  238. ENABLE_CLOUD=0
  239. ;;
  240. "--disable-dbengine") ENABLE_DBENGINE=0 ;;
  241. "--enable-plugin-go") ENABLE_GO=1 ;;
  242. "--disable-plugin-go") ENABLE_GO=0 ;;
  243. "--disable-go") ENABLE_GO=0 ;;
  244. "--enable-plugin-nfacct") ENABLE_NFACCT=1 ;;
  245. "--disable-plugin-nfacct") ENABLE_NFACCT=0 ;;
  246. "--enable-plugin-xenstat") ENABLE_XENSTAT=1 ;;
  247. "--disable-plugin-xenstat") ENABLE_XENSTAT=0 ;;
  248. "--enable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=1 ;;
  249. "--disable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=0 ;;
  250. "--enable-exporting-kinesis" | "--enable-backend-kinesis")
  251. # TODO: Needs CMake Support
  252. ;;
  253. "--disable-exporting-kinesis" | "--disable-backend-kinesis")
  254. # TODO: Needs CMake Support
  255. ;;
  256. "--enable-exporting-prometheus-remote-write" | "--enable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=1 ;;
  257. "--disable-exporting-prometheus-remote-write" | "--disable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=0 ;;
  258. "--enable-exporting-mongodb" | "--enable-backend-mongodb") EXPORTER_MONGODB=1 ;;
  259. "--disable-exporting-mongodb" | "--disable-backend-mongodb") EXPORTER_MONGODB=0 ;;
  260. "--enable-exporting-pubsub")
  261. # TODO: Needs CMake support
  262. ;;
  263. "--disable-exporting-pubsub")
  264. # TODO: Needs CMake support
  265. ;;
  266. "--enable-ml") NETDATA_ENABLE_ML=1 ;;
  267. "--disable-ml") NETDATA_ENABLE_ML=0 ;;
  268. "--enable-lto")
  269. # TODO: Needs CMake support
  270. ;;
  271. "--enable-logs-management") ENABLE_LOGS_MANAGEMENT=1 ;;
  272. "--disable-logsmanagement") ENABLE_LOGS_MANAGEMENT=0 ;;
  273. "--enable-logsmanagement-tests") ENABLE_LOGS_MANAGEMENT_TESTS=1 ;;
  274. "--disable-lto")
  275. # TODO: Needs CMake support
  276. ;;
  277. "--disable-x86-sse")
  278. # XXX: No longer supported.
  279. ;;
  280. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
  281. "--enable-ebpf")
  282. ENABLE_EBPF=1
  283. NETDATA_DISABLE_EBPF=0
  284. ;;
  285. "--disable-ebpf")
  286. ENABLE_EBPF=0
  287. NETDATA_DISABLE_EBPF=1
  288. ;;
  289. "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
  290. "--one-time-build")
  291. # XXX: No longer supported
  292. ;;
  293. "--disable-cloud")
  294. if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
  295. warning "Cloud explicitly enabled, ignoring --disable-cloud."
  296. else
  297. ENABLE_CLOUD=0
  298. NETDATA_DISABLE_CLOUD=1
  299. fi
  300. ;;
  301. "--require-cloud")
  302. if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
  303. warning "Cloud explicitly disabled, ignoring --require-cloud."
  304. else
  305. ENABLE_CLOUD=1
  306. NETDATA_REQUIRE_CLOUD=1
  307. fi
  308. ;;
  309. "--build-json-c")
  310. NETDATA_BUILD_JSON_C=1
  311. ;;
  312. "--install-prefix")
  313. NETDATA_PREFIX="${2}/netdata"
  314. shift 1
  315. ;;
  316. "--install-no-prefix")
  317. NETDATA_PREFIX="${2}"
  318. shift 1
  319. ;;
  320. "--prepare-only")
  321. NETDATA_DISABLE_TELEMETRY=1
  322. NETDATA_PREPARE_ONLY=1
  323. DONOTWAIT=1
  324. ;;
  325. "--help" | "-h")
  326. usage
  327. exit 1
  328. ;;
  329. *)
  330. echo >&2 "Unrecognized option '${1}'."
  331. exit_reason "Unrecognized option '${1}'." I000E
  332. usage
  333. exit 1
  334. ;;
  335. esac
  336. shift 1
  337. done
  338. if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
  339. [ -n "$DISABLE_TELEMETRY" ] ||
  340. [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
  341. [ -n "$DO_NOT_TRACK" ]; then
  342. NETDATA_DISABLE_TELEMETRY=1
  343. fi
  344. if [ -n "${MAKEOPTS}" ]; then
  345. JOBS="$(echo "${MAKEOPTS}" | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
  346. else
  347. JOBS="$(find_processors)"
  348. fi
  349. if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
  350. mega="$((1024 * 1024))"
  351. base=1024
  352. scale=256
  353. target_ram="$((base * mega + (scale * mega * (JOBS - 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_ENABLE_ML=0
  358. fi
  359. if [ -z "${MAKEOPTS}" ]; then
  360. MAKEOPTS="-j${JOBS}"
  361. while [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ]; do
  362. JOBS="$((JOBS - 1))"
  363. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  364. MAKEOPTS="-j${JOBS}"
  365. done
  366. else
  367. if [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
  368. target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  369. total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  370. 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."
  371. exit_reason "Insufficient RAM to safely install." I000F
  372. exit 2
  373. fi
  374. fi
  375. fi
  376. # set default make options
  377. if [ -z "${MAKEOPTS}" ]; then
  378. MAKEOPTS="-j$(find_processors)"
  379. elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
  380. MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
  381. fi
  382. if [ "$(id -u)" -ne 0 ] && [ -z "${NETDATA_PREPARE_ONLY}" ]; then
  383. if [ -z "${NETDATA_PREFIX}" ]; then
  384. netdata_banner
  385. banner_nonroot_install "${@}"
  386. exit_reason "Attempted install as non-root user to /." I0010
  387. exit 1
  388. else
  389. banner_root_notify "${@}"
  390. fi
  391. fi
  392. netdata_banner
  393. progress "real-time performance monitoring, done right!"
  394. cat << BANNER1
  395. You are about to build and install netdata to your system.
  396. The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
  397. any temporary files. You can override this by setting \$TMPDIR to a
  398. writable directory where you can execute files.
  399. It will be installed at these locations:
  400. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  401. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  402. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  403. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  404. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  405. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  406. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  407. BANNER1
  408. [ "$(id -u)" -eq 0 ] && cat << BANNER2
  409. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  410. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  411. BANNER2
  412. cat << BANNER3
  413. This installer allows you to change the installation path.
  414. Press Control-C and run the same command with --help for help.
  415. BANNER3
  416. if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
  417. cat << BANNER4
  418. ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
  419. Anonymous usage stats will be collected and sent to Netdata.
  420. To opt-out, pass --disable-telemetry option to the installer or export
  421. the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
  422. (e.g: export DISABLE_TELEMETRY=1).
  423. BANNER4
  424. fi
  425. if ! command -v cmake >/dev/null 2>&1; then
  426. fatal "Could not find CMake, which is required to build Netdata." I0012
  427. else
  428. cmake="$(command -v cmake)"
  429. progress "Found CMake at ${cmake}. CMake version: $(${cmake} --version | head -n 1)"
  430. fi
  431. if ! command -v "ninja" >/dev/null 2>&1; then
  432. progress "Could not find Ninja, will use Make instead."
  433. else
  434. ninja="$(command -v ninja)"
  435. progress "Found Ninja at ${ninja}. Ninja version: $(${ninja} --version)"
  436. progress "Will use Ninja for this build instead of Make when possible."
  437. fi
  438. make="$(command -v make 2>/dev/null)"
  439. if [ -z "${make}" ] && [ -z "${ninja}" ]; then
  440. fatal "Could not find a usable underlying build system (we support make and ninja)." I0014
  441. fi
  442. CMAKE_OPTS="${ninja:+-G Ninja}"
  443. BUILD_OPTS="VERBOSE=1"
  444. [ -n "${ninja}" ] && BUILD_OPTS="-v"
  445. if [ ${DONOTWAIT} -eq 0 ]; then
  446. if [ -n "${NETDATA_PREFIX}" ]; then
  447. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  448. else
  449. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  450. fi
  451. read -r REPLY
  452. if [ "$REPLY" != '' ]; then
  453. exit_reason "User did not accept install attempt." I0011
  454. exit 1
  455. fi
  456. fi
  457. cmake_install() {
  458. # run cmake --install ${1}
  459. # The above command should be used to replace the logic below once we no longer support
  460. # versions of CMake less than 3.15.
  461. if [ -n "${ninja}" ]; then
  462. run ${ninja} -C "${1}" install
  463. else
  464. run ${make} -C "${1}" install
  465. fi
  466. }
  467. build_error() {
  468. netdata_banner
  469. trap - EXIT
  470. fatal "Netdata failed to build for an unknown reason." I0002
  471. }
  472. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  473. shift
  474. echo >&2 "ok, assuming libs are really installed."
  475. export ZLIB_CFLAGS=" "
  476. export ZLIB_LIBS="-lz"
  477. export UUID_CFLAGS=" "
  478. export UUID_LIBS="-luuid"
  479. fi
  480. trap build_error EXIT
  481. # -----------------------------------------------------------------------------
  482. build_jsonc() {
  483. env_cmd=''
  484. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  485. env_cmd="env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  486. fi
  487. cd "${1}" > /dev/null || exit 1
  488. run eval "${env_cmd} ${cmake} ${CMAKE_OPTS} -DBUILD_SHARED_LIBS=OFF -DDISABLE_WERROR=On ."
  489. run eval "${env_cmd} ${cmake} --build . --parallel ${JOBS} -- ${BUILD_OPTS}"
  490. cd - > /dev/null || return 1
  491. }
  492. copy_jsonc() {
  493. target_dir="${PWD}/externaldeps/jsonc"
  494. run mkdir -p "${target_dir}" "${target_dir}/json-c" || return 1
  495. run cp "${1}/libjson-c.a" "${target_dir}/libjson-c.a" || return 1
  496. # shellcheck disable=SC2086
  497. run cp ${1}/*.h "${target_dir}/json-c" || return 1
  498. }
  499. bundle_jsonc() {
  500. # If --build-json-c flag or not json-c on system, then bundle our own json-c
  501. if [ -z "${NETDATA_BUILD_JSON_C}" ] && pkg-config json-c; then
  502. NETDATA_BUILD_JSON_C=0
  503. return 0
  504. fi
  505. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling JSON-C."
  506. progress "Prepare JSON-C"
  507. JSONC_PACKAGE_VERSION="$(cat packaging/jsonc.version)"
  508. tmp="$(mktemp -d -t netdata-jsonc-XXXXXX)"
  509. JSONC_PACKAGE_BASENAME="json-c-${JSONC_PACKAGE_VERSION}.tar.gz"
  510. if fetch_and_verify "jsonc" \
  511. "https://github.com/json-c/json-c/archive/${JSONC_PACKAGE_BASENAME}" \
  512. "${JSONC_PACKAGE_BASENAME}" \
  513. "${tmp}" \
  514. "${NETDATA_LOCAL_TARBALL_OVERRIDE_JSONC}"; then
  515. if run tar --no-same-owner -xf "${tmp}/${JSONC_PACKAGE_BASENAME}" -C "${tmp}" &&
  516. build_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  517. copy_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  518. rm -rf "${tmp}"; then
  519. run_ok "JSON-C built and prepared."
  520. NETDATA_BUILD_JSON_C=1
  521. else
  522. run_failed "Failed to build JSON-C, Netdata Cloud support will be disabled in this build."
  523. NETDATA_BUILD_JSON_C=0
  524. ENABLE_CLOUD=0
  525. fi
  526. else
  527. run_failed "Unable to fetch sources for JSON-C, Netdata Cloud support will be disabled in this build."
  528. NETDATA_BUILD_JSON_C=0
  529. ENABLE_CLOUD=0
  530. fi
  531. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  532. }
  533. bundle_jsonc
  534. # -----------------------------------------------------------------------------
  535. get_kernel_version() {
  536. r="$(uname -r | cut -f 1 -d '-')"
  537. tmpfile="$(mktemp)"
  538. echo "${r}" | tr '.' ' ' > "${tmpfile}"
  539. read -r maj min patch _ < "${tmpfile}"
  540. rm -f "${tmpfile}"
  541. printf "%03d%03d%03d" "${maj}" "${min}" "${patch}"
  542. }
  543. detect_libc() {
  544. libc=
  545. if ldd --version 2>&1 | grep -q -i glibc; then
  546. echo >&2 " Detected GLIBC"
  547. libc="glibc"
  548. elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
  549. echo >&2 " Detected GLIBC"
  550. libc="glibc"
  551. elif ldd --version 2>&1 | grep -q -i musl; then
  552. echo >&2 " Detected musl"
  553. libc="musl"
  554. else
  555. cmd=$(ldd /bin/sh | grep -w libc | cut -d" " -f 3)
  556. if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
  557. echo >&2 " Detected GLIBC"
  558. libc="glibc"
  559. fi
  560. fi
  561. if [ -z "$libc" ]; then
  562. warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
  563. return 1
  564. fi
  565. echo "${libc}"
  566. return 0
  567. }
  568. build_libbpf() {
  569. cd "${1}/src" > /dev/null || return 1
  570. mkdir root build
  571. # shellcheck disable=SC2086
  572. run env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
  573. cd - > /dev/null || return 1
  574. }
  575. copy_libbpf() {
  576. target_dir="${PWD}/externaldeps/libbpf"
  577. if [ "$(uname -m)" = x86_64 ]; then
  578. lib_subdir="lib64"
  579. else
  580. lib_subdir="lib"
  581. fi
  582. run mkdir -p "${target_dir}" || return 1
  583. run cp "${1}/usr/${lib_subdir}/libbpf.a" "${target_dir}/libbpf.a" || return 1
  584. run cp -r "${1}/usr/include" "${target_dir}" || return 1
  585. run cp -r "${1}/include/uapi" "${target_dir}/include" || return 1
  586. }
  587. bundle_libbpf() {
  588. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  589. ENABLE_EBPF=0
  590. NETDATA_DISABLE_EBPF=1
  591. return 0
  592. fi
  593. if [ -z "${make}" ]; then
  594. warning "No usable copy of Make found, which is required to bundle libbpf. Disabling eBPF support."
  595. ENABLE_EBPF=0
  596. NETDATA_DISABLE_EBPF=1
  597. return 0
  598. fi
  599. # When libc is not detected, we do not have necessity to compile libbpf and we should not do download of eBPF programs
  600. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  601. if [ -z "$libc" ]; then
  602. NETDATA_DISABLE_EBPF=1
  603. ENABLE_EBPF=0
  604. return 0
  605. fi
  606. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  607. progress "Prepare libbpf"
  608. if [ "$(get_kernel_version)" -ge "004014000" ]; then
  609. LIBBPF_PACKAGE_VERSION="$(cat packaging/current_libbpf.version)"
  610. LIBBPF_PACKAGE_COMPONENT="current_libbpf"
  611. else
  612. LIBBPF_PACKAGE_VERSION="$(cat packaging/libbpf_0_0_9.version)"
  613. LIBBPF_PACKAGE_COMPONENT="libbpf_0_0_9"
  614. fi
  615. tmp="$(mktemp -d -t netdata-libbpf-XXXXXX)"
  616. LIBBPF_PACKAGE_BASENAME="v${LIBBPF_PACKAGE_VERSION}.tar.gz"
  617. if fetch_and_verify "${LIBBPF_PACKAGE_COMPONENT}" \
  618. "https://github.com/netdata/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
  619. "${LIBBPF_PACKAGE_BASENAME}" \
  620. "${tmp}" \
  621. "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBBPF}"; then
  622. if run tar --no-same-owner -xf "${tmp}/${LIBBPF_PACKAGE_BASENAME}" -C "${tmp}" &&
  623. build_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  624. copy_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  625. rm -rf "${tmp}"; then
  626. run_ok "libbpf built and prepared."
  627. ENABLE_EBPF=1
  628. else
  629. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  630. fatal "failed to build libbpf." I0005
  631. else
  632. run_failed "Failed to build libbpf. eBPF support will be disabled"
  633. ENABLE_EBPF=0
  634. NETDATA_DISABLE_EBPF=1
  635. fi
  636. fi
  637. else
  638. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  639. fatal "Failed to fetch sources for libbpf." I0006
  640. else
  641. run_failed "Unable to fetch sources for libbpf. eBPF support will be disabled"
  642. ENABLE_EBPF=0
  643. NETDATA_DISABLE_EBPF=1
  644. fi
  645. fi
  646. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  647. }
  648. bundle_libbpf
  649. copy_co_re() {
  650. cp -R "${1}/includes" "src/libnetdata/ebpf/"
  651. }
  652. bundle_ebpf_co_re() {
  653. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  654. return 0
  655. fi
  656. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  657. progress "eBPF CO-RE"
  658. CORE_PACKAGE_VERSION="$(cat packaging/ebpf-co-re.version)"
  659. tmp="$(mktemp -d -t netdata-ebpf-co-re-XXXXXX)"
  660. CORE_PACKAGE_BASENAME="netdata-ebpf-co-re-glibc-${CORE_PACKAGE_VERSION}.tar.xz"
  661. if fetch_and_verify "ebpf-co-re" \
  662. "https://github.com/netdata/ebpf-co-re/releases/download/${CORE_PACKAGE_VERSION}/${CORE_PACKAGE_BASENAME}" \
  663. "${CORE_PACKAGE_BASENAME}" \
  664. "${tmp}" \
  665. "${NETDATA_LOCAL_TARBALL_OVERRIDE_CORE}"; then
  666. if run tar --no-same-owner -xf "${tmp}/${CORE_PACKAGE_BASENAME}" -C "${tmp}" &&
  667. copy_co_re "${tmp}" &&
  668. rm -rf "${tmp}"; then
  669. run_ok "libbpf built and prepared."
  670. ENABLE_EBPF=1
  671. else
  672. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  673. fatal "Failed to get eBPF CO-RE files." I0007
  674. else
  675. run_failed "Failed to get eBPF CO-RE files. eBPF support will be disabled"
  676. NETDATA_DISABLE_EBPF=1
  677. ENABLE_EBPF=0
  678. enable_feature PLUGIN_EBPF 0
  679. fi
  680. fi
  681. else
  682. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  683. fatal "Failed to fetch eBPF CO-RE files." I0008
  684. else
  685. run_failed "Failed to fetch eBPF CO-RE files. eBPF support will be disabled"
  686. NETDATA_DISABLE_EBPF=1
  687. ENABLE_EBPF=0
  688. enable_feature PLUGIN_EBPF 0
  689. fi
  690. fi
  691. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  692. }
  693. bundle_ebpf_co_re
  694. # -----------------------------------------------------------------------------
  695. build_fluentbit() {
  696. env_cmd="env CFLAGS='-w' CXXFLAGS='-w' LDFLAGS="
  697. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  698. env_cmd="env CFLAGS='-fPIC -pipe -w' CXXFLAGS='-fPIC -pipe -w' LDFLAGS="
  699. fi
  700. mkdir -p src/fluent-bit/build || return 1
  701. cd src/fluent-bit/build > /dev/null || return 1
  702. rm CMakeCache.txt > /dev/null 2>&1
  703. if ! run eval "${env_cmd} $1 -C ../../logsmanagement/fluent_bit_build/config.cmake -B./ -S../"; then
  704. cd - > /dev/null || return 1
  705. rm -rf src/fluent-bit/build > /dev/null 2>&1
  706. return 1
  707. fi
  708. if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
  709. cd - > /dev/null || return 1
  710. rm -rf src/fluent-bit/build > /dev/null 2>&1
  711. return 1
  712. fi
  713. cd - > /dev/null || return 1
  714. }
  715. bundle_fluentbit() {
  716. progress "Prepare Fluent-Bit"
  717. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  718. warning "You have explicitly requested to disable Netdata Logs Management support, Fluent-Bit build is skipped."
  719. return 0
  720. fi
  721. if [ ! -d "src/fluent-bit" ]; then
  722. warning "Missing submodule Fluent-Bit. The install process will continue, but Netdata Logs Management support will be disabled."
  723. ENABLE_LOGS_MANAGEMENT=0
  724. return 0
  725. fi
  726. patch -N -p1 src/fluent-bit/CMakeLists.txt -i src/logsmanagement/fluent_bit_build/CMakeLists.patch
  727. patch -N -p1 src/fluent-bit/src/flb_log.c -i src/logsmanagement/fluent_bit_build/flb-log-fmt.patch
  728. # If musl is used, we need to patch chunkio, providing fts has been previously installed.
  729. libc="$(detect_libc)"
  730. if [ "${libc}" = "musl" ]; then
  731. patch -N -p1 src/fluent-bit/lib/chunkio/src/CMakeLists.txt -i src/logsmanagement/fluent_bit_build/chunkio-static-lib-fts.patch
  732. patch -N -p1 src/fluent-bit/cmake/luajit.cmake -i src/logsmanagement/fluent_bit_build/exclude-luajit.patch
  733. patch -N -p1 src/fluent-bit/src/flb_network.c -i src/logsmanagement/fluent_bit_build/xsi-strerror.patch
  734. fi
  735. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling Fluent-Bit."
  736. if build_fluentbit "$cmake"; then
  737. # If Fluent-Bit built with inotify support, use it.
  738. if [ "$(grep -o '^FLB_HAVE_INOTIFY:INTERNAL=.*' src/fluent-bit/build/CMakeCache.txt | cut -d '=' -f 2)" ]; then
  739. CFLAGS="${CFLAGS} -DFLB_HAVE_INOTIFY"
  740. fi
  741. FLUENT_BIT_BUILD_SUCCESS=1
  742. run_ok "Fluent-Bit built successfully."
  743. else
  744. warning "Failed to build Fluent-Bit, Netdata Logs Management support will be disabled in this build."
  745. ENABLE_LOGS_MANAGEMENT=0
  746. fi
  747. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  748. }
  749. bundle_fluentbit
  750. # -----------------------------------------------------------------------------
  751. # If we’re installing the Go plugin, ensure a working Go toolchain is installed.
  752. if [ "${ENABLE_GO}" -eq 1 ]; then
  753. progress "Checking for a usable Go toolchain and attempting to install one to /usr/local/go if needed."
  754. . "${NETDATA_SOURCE_DIR}/packaging/check-for-go-toolchain.sh"
  755. if ! ensure_go_toolchain; then
  756. warning "Go ${GOLANG_MIN_VERSION} needed to build Go plugin, but could not find or install a usable toolchain: ${GOLANG_FAILURE_REASON}"
  757. ENABLE_GO=0
  758. fi
  759. fi
  760. # -----------------------------------------------------------------------------
  761. # If we have the dashboard switching logic, make sure we're on the classic
  762. # dashboard during the install (updates don't work correctly otherwise).
  763. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
  764. "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
  765. fi
  766. # -----------------------------------------------------------------------------
  767. # By default, `git` does not update local tags based on remotes. Because
  768. # we use the most recent tag as part of our version determination in
  769. # our build, this can lead to strange versions that look ancient but are
  770. # actually really recent. To avoid this, try and fetch tags if we're
  771. # working in a git checkout.
  772. if [ -d ./.git ] ; then
  773. echo >&2
  774. progress "Updating tags in git to ensure a consistent version number"
  775. run git fetch -t || true
  776. fi
  777. # -----------------------------------------------------------------------------
  778. echo >&2
  779. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
  780. NETDATA_BUILD_DIR="${NETDATA_BUILD_DIR:-./build/}"
  781. rm -rf "${NETDATA_BUILD_DIR}"
  782. # function to extract values from the config file
  783. config_option() {
  784. section="${1}"
  785. key="${2}"
  786. value="${3}"
  787. if [ -x "${NETDATA_PREFIX}/usr/sbin/netdata" ] && [ -r "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  788. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  789. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  790. -W get "${section}" "${key}" "${value}" ||
  791. echo "${value}"
  792. else
  793. echo "${value}"
  794. fi
  795. }
  796. # the user netdata will run as
  797. if [ "$(id -u)" = "0" ]; then
  798. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  799. ROOT_USER="root"
  800. else
  801. NETDATA_USER="${USER}"
  802. ROOT_USER="${USER}"
  803. fi
  804. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}" 2> /dev/null)"
  805. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  806. echo >&2 "Netdata user and group set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  807. prepare_cmake_options
  808. if [ -n "${NETDATA_PREPARE_ONLY}" ]; then
  809. progress "Exiting before building Netdata as requested."
  810. printf "Would have used the following CMake command line for configuration: %s\n" "${cmake} ${NETDATA_CMAKE_OPTIONS}"
  811. trap - EXIT
  812. exit 0
  813. fi
  814. # Let cmake know we don't want to link shared libs
  815. if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
  816. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DBUILD_SHARED_LIBS=Off"
  817. fi
  818. # shellcheck disable=SC2086
  819. if ! run ${cmake} ${NETDATA_CMAKE_OPTIONS}; then
  820. fatal "Failed to configure Netdata sources." I000A
  821. fi
  822. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  823. # remove the build_error hook
  824. trap - EXIT
  825. # -----------------------------------------------------------------------------
  826. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
  827. # -----------------------------------------------------------------------------
  828. progress "Compile netdata"
  829. # shellcheck disable=SC2086
  830. if ! run ${cmake} --build "${NETDATA_BUILD_DIR}" --parallel ${JOBS} -- ${BUILD_OPTS}; then
  831. fatal "Failed to build Netdata." I000B
  832. fi
  833. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  834. # -----------------------------------------------------------------------------
  835. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
  836. # -----------------------------------------------------------------------------
  837. progress "Install netdata"
  838. if ! cmake_install "${NETDATA_BUILD_DIR}"; then
  839. fatal "Failed to install Netdata." I000C
  840. fi
  841. # -----------------------------------------------------------------------------
  842. progress "Creating standard user and groups for netdata"
  843. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  844. NETDATA_ADDED_TO_GROUPS=""
  845. if [ "$(id -u)" -eq 0 ]; then
  846. progress "Adding group 'netdata'"
  847. portable_add_group netdata || :
  848. progress "Adding user 'netdata'"
  849. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  850. progress "Assign user 'netdata' to required groups"
  851. for g in ${NETDATA_WANTED_GROUPS}; do
  852. # shellcheck disable=SC2086
  853. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  854. done
  855. # Netdata must be able to read /etc/pve/qemu-server/* and /etc/pve/lxc/*
  856. # for reading VMs/containers names, CPU and memory limits on Proxmox.
  857. if [ -d "/etc/pve" ]; then
  858. portable_add_user_to_group "www-data" netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} www-data"
  859. fi
  860. else
  861. run_failed "The installer does not run as root. Nothing to do for user and groups"
  862. fi
  863. # -----------------------------------------------------------------------------
  864. progress "Install logrotate configuration for netdata"
  865. install_netdata_logrotate
  866. # -----------------------------------------------------------------------------
  867. progress "Read installation options from netdata.conf"
  868. # create an empty config if it does not exist
  869. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  870. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  871. # port
  872. defport=19999
  873. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  874. # directories
  875. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  876. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  877. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  878. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  879. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  880. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  881. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  882. NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
  883. cat << OPTIONSEOF
  884. Permissions
  885. - netdata user : ${NETDATA_USER}
  886. - netdata group : ${NETDATA_GROUP}
  887. - root user : ${ROOT_USER}
  888. Directories
  889. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  890. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  891. - netdata log dir : ${NETDATA_LOG_DIR}
  892. - netdata run dir : ${NETDATA_RUN_DIR}
  893. - netdata lib dir : ${NETDATA_LIB_DIR}
  894. - netdata web dir : ${NETDATA_WEB_DIR}
  895. - netdata cache dir : ${NETDATA_CACHE_DIR}
  896. Other
  897. - netdata port : ${NETDATA_PORT}
  898. OPTIONSEOF
  899. # -----------------------------------------------------------------------------
  900. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  901. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  902. # this is needed if NETDATA_PREFIX is not empty
  903. if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
  904. warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
  905. fi
  906. fi
  907. # --- stock conf dir ----
  908. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  909. [ -L "${NETDATA_USER_CONFIG_DIR}/orig" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/orig"
  910. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/orig"
  911. # --- web dir ----
  912. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  913. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  914. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  915. fi
  916. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  917. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  918. # --- data dirs ----
  919. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  920. if [ ! -d "${x}" ]; then
  921. echo >&2 "Creating directory '${x}'"
  922. if ! run mkdir -p "${x}"; then
  923. warning "Failed to create ${x}, it must be created by hand or the Netdata Agent will not be able to be started."
  924. fi
  925. fi
  926. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  927. #run find "${x}" -type f -exec chmod 0660 {} \;
  928. #run find "${x}" -type d -exec chmod 0770 {} \;
  929. done
  930. run chmod 755 "${NETDATA_LOG_DIR}"
  931. # --- claiming dir ----
  932. if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
  933. echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
  934. if ! run mkdir -p "${NETDATA_CLAIMING_DIR}"; then
  935. warning "failed to create ${NETDATA_CLAIMING_DIR}, it will need to be created manually."
  936. fi
  937. fi
  938. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
  939. run chmod 770 "${NETDATA_CLAIMING_DIR}"
  940. # --- plugins ----
  941. if [ "$(id -u)" -eq 0 ]; then
  942. # find the admin group
  943. admin_group=
  944. test -z "${admin_group}" && get_group root > /dev/null 2>&1 && admin_group="root"
  945. test -z "${admin_group}" && get_group daemon > /dev/null 2>&1 && admin_group="daemon"
  946. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  947. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  948. run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  949. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  950. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  951. # shellcheck disable=SC2086
  952. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
  953. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  954. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  955. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  956. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  957. capabilities=0
  958. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  959. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  960. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  961. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  962. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  963. fi
  964. fi
  965. if [ $capabilities -eq 0 ]; then
  966. # fix apps.plugin to be setuid to root
  967. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  968. fi
  969. fi
  970. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" ]; then
  971. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  972. capabilities=0
  973. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  974. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  975. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"; then
  976. # if we managed to setcap, but we fail to execute debugfs.plugin setuid to root
  977. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  978. fi
  979. fi
  980. if [ $capabilities -eq 0 ]; then
  981. # fix debugfs.plugin to be setuid to root
  982. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  983. fi
  984. fi
  985. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin" ]; then
  986. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  987. capabilities=0
  988. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  989. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  990. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"; then
  991. capabilities=1
  992. fi
  993. fi
  994. if [ $capabilities -eq 0 ]; then
  995. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  996. fi
  997. fi
  998. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin" ]; then
  999. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1000. capabilities=0
  1001. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1002. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1003. if run setcap cap_dac_read_search,cap_syslog+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"; then
  1004. capabilities=1
  1005. fi
  1006. fi
  1007. if [ $capabilities -eq 0 ]; then
  1008. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  1009. fi
  1010. fi
  1011. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  1012. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1013. capabilities=0
  1014. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  1015. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1016. 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
  1017. capabilities=1
  1018. fi
  1019. fi
  1020. if [ $capabilities -eq 0 ]; then
  1021. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1022. fi
  1023. fi
  1024. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
  1025. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1026. capabilities=0
  1027. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  1028. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1029. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"; then
  1030. capabilities=1
  1031. fi
  1032. fi
  1033. if [ $capabilities -eq 0 ]; then
  1034. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1035. fi
  1036. fi
  1037. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  1038. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1039. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1040. fi
  1041. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  1042. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1043. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1044. fi
  1045. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  1046. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1047. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1048. fi
  1049. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  1050. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1051. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1052. fi
  1053. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
  1054. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1055. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1056. fi
  1057. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  1058. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1059. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1060. fi
  1061. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  1062. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1063. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1064. fi
  1065. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners" ]; then
  1066. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  1067. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  1068. fi
  1069. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin" ]; then
  1070. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
  1071. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
  1072. fi
  1073. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo" ]; then
  1074. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  1075. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  1076. fi
  1077. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin" ]; then
  1078. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1079. capabilities=1
  1080. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1081. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1082. if ! 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"; then
  1083. capabilities=0
  1084. fi
  1085. fi
  1086. if [ $capabilities -eq 0 ]; then
  1087. # fix go.d.plugin to be setuid to root
  1088. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1089. fi
  1090. fi
  1091. else
  1092. # non-privileged user installation
  1093. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  1094. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1095. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  1096. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1097. fi
  1098. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1099. should_install_ebpf() {
  1100. if [ "${NETDATA_DISABLE_EBPF:=0}" -eq 1 ]; then
  1101. run_failed "eBPF has been explicitly disabled, it will not be available in this install."
  1102. return 1
  1103. fi
  1104. if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
  1105. if [ "${NETDATA_DISABLE_EBPF:=1}" -eq 0 ]; then
  1106. run_failed "Currently eBPF is only supported on Linux on X86_64."
  1107. fi
  1108. return 1
  1109. fi
  1110. # Check Kernel Config
  1111. if ! run "${INSTALLER_DIR}"/packaging/check-kernel-config.sh; then
  1112. warning "Kernel unsupported or missing required config (eBPF may not work on your system)"
  1113. fi
  1114. return 0
  1115. }
  1116. remove_old_ebpf() {
  1117. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin" ]; then
  1118. echo >&2 "Removing alpha eBPF collector."
  1119. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin"
  1120. fi
  1121. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf" ]; then
  1122. echo >&2 "Removing alpha eBPF stock file"
  1123. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf"
  1124. fi
  1125. if [ -f "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" ]; then
  1126. echo >&2 "Renaming eBPF configuration file."
  1127. mv "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" "${NETDATA_PREFIX}/etc/netdata/ebpf.d.conf"
  1128. fi
  1129. # Added to remove eBPF programs with name pattern: NAME_VERSION.SUBVERSION.PATCH
  1130. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.0.o" ]; then
  1131. echo >&2 "Removing old eBPF programs with patch."
  1132. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.*.o
  1133. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.*.o
  1134. fi
  1135. # Remove old eBPF program to store new eBPF program inside subdirectory
  1136. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.o" ]; then
  1137. echo >&2 "Removing old eBPF programs installed in old directory."
  1138. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.o
  1139. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.o
  1140. fi
  1141. # Remove old eBPF programs that did not have "rhf" suffix
  1142. if [ ! -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/pnetdata_ebpf_process.3.10.rhf.o" ]; then
  1143. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/"*.o
  1144. fi
  1145. # Remove old reject list from previous directory
  1146. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt" ]; then
  1147. echo >&2 "Removing old ebpf_kernel_reject_list.txt."
  1148. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt"
  1149. fi
  1150. # Remove old reset script
  1151. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh" ]; then
  1152. echo >&2 "Removing old reset_netdata_trace.sh."
  1153. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh"
  1154. fi
  1155. }
  1156. install_ebpf() {
  1157. if ! should_install_ebpf; then
  1158. return 0
  1159. fi
  1160. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing eBPF code."
  1161. remove_old_ebpf
  1162. progress "Installing eBPF plugin"
  1163. # Detect libc
  1164. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  1165. EBPF_VERSION="$(cat packaging/ebpf.version)"
  1166. EBPF_TARBALL="netdata-kernel-collector-${libc}-${EBPF_VERSION}.tar.xz"
  1167. tmp="$(mktemp -d -t netdata-ebpf-XXXXXX)"
  1168. if ! fetch_and_verify "ebpf" \
  1169. "https://github.com/netdata/kernel-collector/releases/download/${EBPF_VERSION}/${EBPF_TARBALL}" \
  1170. "${EBPF_TARBALL}" \
  1171. "${tmp}" \
  1172. "${NETDATA_LOCAL_TARBALL_OVERRIDE_EBPF}"; then
  1173. run_failed "Failed to download eBPF collector package"
  1174. echo 2>&" Removing temporary directory ${tmp} ..."
  1175. rm -rf "${tmp}"
  1176. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1177. return 1
  1178. fi
  1179. echo >&2 " Extracting ${EBPF_TARBALL} ..."
  1180. tar --no-same-owner -xf "${tmp}/${EBPF_TARBALL}" -C "${tmp}"
  1181. # chown everything to root:netdata before we start copying out of our package
  1182. run chown -R root:netdata "${tmp}"
  1183. if [ ! -d "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d ]; then
  1184. mkdir "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1185. RET=$?
  1186. if [ "${RET}" != "0" ]; then
  1187. rm -rf "${tmp}"
  1188. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1189. return 1
  1190. fi
  1191. fi
  1192. run cp -a -v "${tmp}"/*netdata_ebpf_*.o "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1193. rm -rf "${tmp}"
  1194. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1195. }
  1196. progress "eBPF Kernel Collector"
  1197. install_ebpf
  1198. should_install_fluentbit() {
  1199. if [ "$(uname -s)" = "Darwin" ]; then
  1200. return 1
  1201. fi
  1202. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  1203. warning "netdata-installer.sh run with --disable-logsmanagement, Fluent-Bit installation is skipped."
  1204. return 1
  1205. elif [ "${FLUENT_BIT_BUILD_SUCCESS:=0}" -eq 0 ]; then
  1206. run_failed "Fluent-Bit was not built successfully, Netdata Logs Management support will be disabled in this build."
  1207. return 1
  1208. elif [ ! -f src/fluent-bit/build/lib/libfluent-bit.so ]; then
  1209. run_failed "libfluent-bit.so is missing, Netdata Logs Management support will be disabled in this build."
  1210. return 1
  1211. fi
  1212. return 0
  1213. }
  1214. install_fluentbit() {
  1215. if ! should_install_fluentbit; then
  1216. enable_feature PLUGIN_LOGS_MANAGEMENT 0
  1217. return 0
  1218. fi
  1219. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Fluent-Bit."
  1220. run chown "root:${NETDATA_GROUP}" src/fluent-bit/build/lib
  1221. run chmod 0644 src/fluent-bit/build/lib/libfluent-bit.so
  1222. run cp -a -v src/fluent-bit/build/lib/libfluent-bit.so "${NETDATA_PREFIX}"/usr/lib/netdata
  1223. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1224. }
  1225. progress "Installing Fluent-Bit plugin"
  1226. install_fluentbit
  1227. # -----------------------------------------------------------------------------
  1228. progress "Telemetry configuration"
  1229. # Opt-out from telemetry program
  1230. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  1231. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  1232. else
  1233. 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"
  1234. fi
  1235. # -----------------------------------------------------------------------------
  1236. progress "Install netdata at system init"
  1237. # By default we assume the shutdown/startup of the Netdata Agent are effectively
  1238. # without any system supervisor/init like SystemD or SysV. So we assume the most
  1239. # basic startup/shutdown commands...
  1240. NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
  1241. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  1242. if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
  1243. # If docker runs systemd for some weird reason, let the install proceed
  1244. is_systemd_running="NO"
  1245. if command -v pidof > /dev/null 2>&1; then
  1246. is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
  1247. else
  1248. is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
  1249. fi
  1250. if [ "${is_systemd_running}" = "1" ]; then
  1251. echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
  1252. install_netdata_service || run_failed "Cannot install netdata init service."
  1253. else
  1254. echo >&2 "We are running within a docker container, will not be installing netdata service"
  1255. fi
  1256. echo >&2
  1257. else
  1258. install_netdata_service || run_failed "Cannot install netdata init service."
  1259. fi
  1260. # -----------------------------------------------------------------------------
  1261. # check if we can re-start netdata
  1262. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  1263. started=0
  1264. if [ ${DONOTSTART} -eq 1 ]; then
  1265. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1266. else
  1267. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  1268. fatal "Cannot start netdata!" I000D
  1269. fi
  1270. started=1
  1271. run_ok "netdata started!"
  1272. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  1273. fi
  1274. run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1275. if [ "$(uname)" = "Linux" ]; then
  1276. # -------------------------------------------------------------------------
  1277. progress "Check KSM (kernel memory deduper)"
  1278. ksm_is_available_but_disabled() {
  1279. cat << KSM1
  1280. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  1281. You have kernel memory de-duper (called Kernel Same-page Merging,
  1282. or KSM) available, but it is not currently enabled.
  1283. To enable it run:
  1284. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  1285. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  1286. If you enable it, you will save 40-60% of netdata memory.
  1287. KSM1
  1288. }
  1289. ksm_is_not_available() {
  1290. cat << KSM2
  1291. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  1292. It seems you do not have kernel memory de-duper (called Kernel Same-page
  1293. Merging, or KSM) available.
  1294. To enable it, you need a kernel built with CONFIG_KSM=y
  1295. If you can have it, you will save 40-60% of netdata memory.
  1296. KSM2
  1297. }
  1298. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  1299. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  1300. ksm_is_available_but_disabled
  1301. fi
  1302. else
  1303. ksm_is_not_available
  1304. fi
  1305. fi
  1306. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1307. # -----------------------------------------------------------------------------
  1308. progress "Check apps.plugin"
  1309. if [ "$(id -u)" -ne 0 ]; then
  1310. cat << SETUID_WARNING
  1311. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  1312. Since you have installed netdata as a normal user, to have apps.plugin collect
  1313. all the needed data, you have to give it the access rights it needs, by running
  1314. either of the following sets of commands:
  1315. To run apps.plugin with escalated capabilities:
  1316. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1317. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1318. ${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}
  1319. or, to run apps.plugin as root:
  1320. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1321. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1322. apps.plugin is performing a hard-coded function of data collection for all
  1323. running processes. It cannot be instructed from the netdata daemon to perform
  1324. any task, so it is pretty safe to do this.
  1325. SETUID_WARNING
  1326. fi
  1327. fi
  1328. # -----------------------------------------------------------------------------
  1329. progress "Copy uninstaller"
  1330. if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
  1331. echo >&2 "Removing uninstaller from old location"
  1332. rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
  1333. fi
  1334. 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"
  1335. chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  1336. # -----------------------------------------------------------------------------
  1337. progress "Basic netdata instructions"
  1338. cat << END
  1339. netdata by default listens on all IPs on port ${NETDATA_PORT},
  1340. so you can access it with:
  1341. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  1342. To stop netdata run:
  1343. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  1344. To start netdata run:
  1345. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  1346. END
  1347. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
  1348. echo >&2
  1349. # -----------------------------------------------------------------------------
  1350. progress "Installing (but not enabling) the netdata updater tool"
  1351. install_netdata_updater || run_failed "Cannot install netdata updater tool."
  1352. # -----------------------------------------------------------------------------
  1353. progress "Wrap up environment set up"
  1354. # Save environment variables
  1355. echo >&2 "Preparing .environment file"
  1356. cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  1357. # Created by installer
  1358. PATH="${PATH}"
  1359. CFLAGS="${CFLAGS}"
  1360. LDFLAGS="${LDFLAGS}"
  1361. MAKEOPTS="${MAKEOPTS}"
  1362. NETDATA_TMPDIR="${TMPDIR}"
  1363. NETDATA_PREFIX="${NETDATA_PREFIX}"
  1364. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS}"
  1365. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  1366. INSTALL_UID="$(id -u)"
  1367. NETDATA_GROUP="${NETDATA_GROUP}"
  1368. REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
  1369. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  1370. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
  1371. NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
  1372. EOF
  1373. run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
  1374. echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
  1375. cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  1376. new_installation
  1377. EOF
  1378. print_deferred_errors
  1379. # -----------------------------------------------------------------------------
  1380. echo >&2
  1381. progress "We are done!"
  1382. if [ ${started} -eq 1 ]; then
  1383. netdata_banner
  1384. progress "is installed and running now!"
  1385. else
  1386. netdata_banner
  1387. progress "is installed now!"
  1388. fi
  1389. echo >&2 " enjoy real-time performance and health monitoring..."
  1390. echo >&2
  1391. exit 0