netdata-installer.sh 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  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 Disable all Go components.
  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. if [ "$(uname -s)" = "Linux" ]; then
  205. case "$(uname -m)" in
  206. x86_64|i?86) ENABLE_EBPF=1 ;;
  207. esac
  208. fi
  209. DONOTSTART=0
  210. DONOTWAIT=0
  211. NETDATA_PREFIX=
  212. LIBS_ARE_HERE=0
  213. NETDATA_ENABLE_ML=""
  214. ENABLE_DBENGINE=1
  215. ENABLE_GO=1
  216. ENABLE_H2O=1
  217. ENABLE_CLOUD=1
  218. ENABLE_LOGS_MANAGEMENT=1
  219. ENABLE_LOGS_MANAGEMENT_TESTS=0
  220. FORCE_LEGACY_CXX=0
  221. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS-}"
  222. RELEASE_CHANNEL="nightly" # valid values are 'nightly' and 'stable'
  223. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY:-"no"}"
  224. while [ -n "${1}" ]; do
  225. case "${1}" in
  226. "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
  227. "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
  228. "--use-system-protobuf") USE_SYSTEM_PROTOBUF=1 ;;
  229. "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
  230. "--dont-start-it") DONOTSTART=1 ;;
  231. "--dont-wait") DONOTWAIT=1 ;;
  232. "--auto-update" | "-u") ;;
  233. "--auto-update-type") ;;
  234. "--stable-channel") RELEASE_CHANNEL="stable" ;;
  235. "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
  236. "--force-legacy-cxx") FORCE_LEGACY_CXX=1 ;;
  237. "--enable-plugin-freeipmi") ENABLE_FREEIPMI=1 ;;
  238. "--disable-plugin-freeipmi") ENABLE_FREEIPMI=0 ;;
  239. "--disable-https")
  240. ENABLE_DBENGINE=0
  241. ENABLE_H2O=0
  242. ENABLE_CLOUD=0
  243. ;;
  244. "--disable-dbengine") ENABLE_DBENGINE=0 ;;
  245. "--enable-plugin-go") ENABLE_GO=1 ;;
  246. "--disable-plugin-go") ENABLE_GO=0 ;;
  247. "--disable-go") ENABLE_GO=0 ;;
  248. "--enable-plugin-nfacct") ENABLE_NFACCT=1 ;;
  249. "--disable-plugin-nfacct") ENABLE_NFACCT=0 ;;
  250. "--enable-plugin-xenstat") ENABLE_XENSTAT=1 ;;
  251. "--disable-plugin-xenstat") ENABLE_XENSTAT=0 ;;
  252. "--enable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=1 ;;
  253. "--disable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=0 ;;
  254. "--enable-exporting-kinesis" | "--enable-backend-kinesis")
  255. # TODO: Needs CMake Support
  256. ;;
  257. "--disable-exporting-kinesis" | "--disable-backend-kinesis")
  258. # TODO: Needs CMake Support
  259. ;;
  260. "--enable-exporting-prometheus-remote-write" | "--enable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=1 ;;
  261. "--disable-exporting-prometheus-remote-write" | "--disable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=0 ;;
  262. "--enable-exporting-mongodb" | "--enable-backend-mongodb") EXPORTER_MONGODB=1 ;;
  263. "--disable-exporting-mongodb" | "--disable-backend-mongodb") EXPORTER_MONGODB=0 ;;
  264. "--enable-exporting-pubsub")
  265. # TODO: Needs CMake support
  266. ;;
  267. "--disable-exporting-pubsub")
  268. # TODO: Needs CMake support
  269. ;;
  270. "--enable-ml") NETDATA_ENABLE_ML=1 ;;
  271. "--disable-ml") NETDATA_ENABLE_ML=0 ;;
  272. "--enable-lto")
  273. # TODO: Needs CMake support
  274. ;;
  275. "--enable-logs-management") ENABLE_LOGS_MANAGEMENT=1 ;;
  276. "--disable-logsmanagement") ENABLE_LOGS_MANAGEMENT=0 ;;
  277. "--enable-logsmanagement-tests") ENABLE_LOGS_MANAGEMENT_TESTS=1 ;;
  278. "--disable-lto")
  279. # TODO: Needs CMake support
  280. ;;
  281. "--disable-x86-sse")
  282. # XXX: No longer supported.
  283. ;;
  284. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
  285. "--enable-ebpf") ENABLE_EBPF=1 ;;
  286. "--disable-ebpf") ENABLE_EBPF=0 ;;
  287. "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
  288. "--one-time-build")
  289. # XXX: No longer supported
  290. ;;
  291. "--disable-cloud")
  292. if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
  293. warning "Cloud explicitly enabled, ignoring --disable-cloud."
  294. else
  295. ENABLE_CLOUD=0
  296. NETDATA_DISABLE_CLOUD=1
  297. fi
  298. ;;
  299. "--require-cloud")
  300. if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
  301. warning "Cloud explicitly disabled, ignoring --require-cloud."
  302. else
  303. ENABLE_CLOUD=1
  304. NETDATA_REQUIRE_CLOUD=1
  305. fi
  306. ;;
  307. "--build-json-c")
  308. NETDATA_BUILD_JSON_C=1
  309. ;;
  310. "--install-prefix")
  311. NETDATA_PREFIX="${2}/netdata"
  312. shift 1
  313. ;;
  314. "--install-no-prefix")
  315. NETDATA_PREFIX="${2}"
  316. shift 1
  317. ;;
  318. "--prepare-only")
  319. NETDATA_DISABLE_TELEMETRY=1
  320. NETDATA_PREPARE_ONLY=1
  321. DONOTWAIT=1
  322. ;;
  323. "--help" | "-h")
  324. usage
  325. exit 1
  326. ;;
  327. *)
  328. echo >&2 "Unrecognized option '${1}'."
  329. exit_reason "Unrecognized option '${1}'." I000E
  330. usage
  331. exit 1
  332. ;;
  333. esac
  334. shift 1
  335. done
  336. if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
  337. [ -n "$DISABLE_TELEMETRY" ] ||
  338. [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
  339. [ -n "$DO_NOT_TRACK" ]; then
  340. NETDATA_DISABLE_TELEMETRY=1
  341. fi
  342. if [ -n "${MAKEOPTS}" ]; then
  343. JOBS="$(echo "${MAKEOPTS}" | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
  344. else
  345. JOBS="$(find_processors)"
  346. fi
  347. if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
  348. mega="$((1024 * 1024))"
  349. base=1024
  350. scale=256
  351. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  352. total_ram="$(grep MemTotal /proc/meminfo | cut -d ':' -f 2 | tr -d ' kB')"
  353. total_ram="$((total_ram * 1024))"
  354. if [ "${total_ram}" -le "$((base * mega))" ] && [ -z "${NETDATA_ENABLE_ML}" ]; then
  355. NETDATA_ENABLE_ML=0
  356. fi
  357. if [ -z "${MAKEOPTS}" ]; then
  358. MAKEOPTS="-j${JOBS}"
  359. while [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ]; do
  360. JOBS="$((JOBS - 1))"
  361. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  362. MAKEOPTS="-j${JOBS}"
  363. done
  364. else
  365. if [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
  366. target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  367. total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  368. 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."
  369. exit_reason "Insufficient RAM to safely install." I000F
  370. exit 2
  371. fi
  372. fi
  373. fi
  374. # set default make options
  375. if [ -z "${MAKEOPTS}" ]; then
  376. MAKEOPTS="-j$(find_processors)"
  377. elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
  378. MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
  379. fi
  380. if [ "$(id -u)" -ne 0 ] && [ -z "${NETDATA_PREPARE_ONLY}" ]; then
  381. if [ -z "${NETDATA_PREFIX}" ]; then
  382. netdata_banner
  383. banner_nonroot_install "${@}"
  384. exit_reason "Attempted install as non-root user to /." I0010
  385. exit 1
  386. else
  387. banner_root_notify "${@}"
  388. fi
  389. fi
  390. netdata_banner
  391. progress "real-time performance monitoring, done right!"
  392. cat << BANNER1
  393. You are about to build and install netdata to your system.
  394. The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
  395. any temporary files. You can override this by setting \$TMPDIR to a
  396. writable directory where you can execute files.
  397. It will be installed at these locations:
  398. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  399. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  400. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  401. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  402. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  403. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  404. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  405. BANNER1
  406. [ "$(id -u)" -eq 0 ] && cat << BANNER2
  407. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  408. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  409. BANNER2
  410. cat << BANNER3
  411. This installer allows you to change the installation path.
  412. Press Control-C and run the same command with --help for help.
  413. BANNER3
  414. if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
  415. cat << BANNER4
  416. ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
  417. Anonymous usage stats will be collected and sent to Netdata.
  418. To opt-out, pass --disable-telemetry option to the installer or export
  419. the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
  420. (e.g: export DISABLE_TELEMETRY=1).
  421. BANNER4
  422. fi
  423. if ! command -v cmake >/dev/null 2>&1; then
  424. fatal "Could not find CMake, which is required to build Netdata." I0012
  425. else
  426. cmake="$(command -v cmake)"
  427. progress "Found CMake at ${cmake}. CMake version: $(${cmake} --version | head -n 1)"
  428. fi
  429. if ! command -v "ninja" >/dev/null 2>&1; then
  430. progress "Could not find Ninja, will use Make instead."
  431. else
  432. ninja="$(command -v ninja)"
  433. progress "Found Ninja at ${ninja}. Ninja version: $(${ninja} --version)"
  434. progress "Will use Ninja for this build instead of Make when possible."
  435. fi
  436. make="$(command -v make 2>/dev/null)"
  437. if [ -z "${make}" ] && [ -z "${ninja}" ]; then
  438. fatal "Could not find a usable underlying build system (we support make and ninja)." I0014
  439. fi
  440. CMAKE_OPTS="${ninja:+-G Ninja}"
  441. BUILD_OPTS="VERBOSE=1"
  442. [ -n "${ninja}" ] && BUILD_OPTS="-v"
  443. if [ ${DONOTWAIT} -eq 0 ]; then
  444. if [ -n "${NETDATA_PREFIX}" ]; then
  445. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  446. else
  447. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  448. fi
  449. read -r REPLY
  450. if [ "$REPLY" != '' ]; then
  451. exit_reason "User did not accept install attempt." I0011
  452. exit 1
  453. fi
  454. fi
  455. cmake_install() {
  456. # run cmake --install ${1}
  457. # The above command should be used to replace the logic below once we no longer support
  458. # versions of CMake less than 3.15.
  459. if [ -n "${ninja}" ]; then
  460. run ${ninja} -C "${1}" install
  461. else
  462. run ${make} -C "${1}" install
  463. fi
  464. }
  465. build_error() {
  466. netdata_banner
  467. trap - EXIT
  468. fatal "Netdata failed to build for an unknown reason." I0002
  469. }
  470. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  471. shift
  472. echo >&2 "ok, assuming libs are really installed."
  473. export ZLIB_CFLAGS=" "
  474. export ZLIB_LIBS="-lz"
  475. export UUID_CFLAGS=" "
  476. export UUID_LIBS="-luuid"
  477. fi
  478. trap build_error EXIT
  479. # -----------------------------------------------------------------------------
  480. build_fluentbit() {
  481. env_cmd="env CFLAGS='-w' CXXFLAGS='-w' LDFLAGS="
  482. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  483. env_cmd="env CFLAGS='-fPIC -pipe -w' CXXFLAGS='-fPIC -pipe -w' LDFLAGS="
  484. fi
  485. mkdir -p src/fluent-bit/build || return 1
  486. cd src/fluent-bit/build > /dev/null || return 1
  487. rm CMakeCache.txt > /dev/null 2>&1
  488. if ! run eval "${env_cmd} $1 -C ../../logsmanagement/fluent_bit_build/config.cmake -B./ -S../"; then
  489. cd - > /dev/null || return 1
  490. rm -rf src/fluent-bit/build > /dev/null 2>&1
  491. return 1
  492. fi
  493. if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
  494. cd - > /dev/null || return 1
  495. rm -rf src/fluent-bit/build > /dev/null 2>&1
  496. return 1
  497. fi
  498. cd - > /dev/null || return 1
  499. }
  500. bundle_fluentbit() {
  501. progress "Prepare Fluent-Bit"
  502. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  503. warning "You have explicitly requested to disable Netdata Logs Management support, Fluent-Bit build is skipped."
  504. return 0
  505. fi
  506. if [ ! -d "src/fluent-bit" ]; then
  507. warning "Missing submodule Fluent-Bit. The install process will continue, but Netdata Logs Management support will be disabled."
  508. ENABLE_LOGS_MANAGEMENT=0
  509. return 0
  510. fi
  511. patch -N -p1 src/fluent-bit/CMakeLists.txt -i src/logsmanagement/fluent_bit_build/CMakeLists.patch
  512. patch -N -p1 src/fluent-bit/src/flb_log.c -i src/logsmanagement/fluent_bit_build/flb-log-fmt.patch
  513. # If musl is used, we need to patch chunkio, providing fts has been previously installed.
  514. libc="$(detect_libc)"
  515. if [ "${libc}" = "musl" ]; then
  516. patch -N -p1 src/fluent-bit/lib/chunkio/src/CMakeLists.txt -i src/logsmanagement/fluent_bit_build/chunkio-static-lib-fts.patch
  517. patch -N -p1 src/fluent-bit/cmake/luajit.cmake -i src/logsmanagement/fluent_bit_build/exclude-luajit.patch
  518. patch -N -p1 src/fluent-bit/src/flb_network.c -i src/logsmanagement/fluent_bit_build/xsi-strerror.patch
  519. fi
  520. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling Fluent-Bit."
  521. if build_fluentbit "$cmake"; then
  522. # If Fluent-Bit built with inotify support, use it.
  523. if [ "$(grep -o '^FLB_HAVE_INOTIFY:INTERNAL=.*' src/fluent-bit/build/CMakeCache.txt | cut -d '=' -f 2)" ]; then
  524. CFLAGS="${CFLAGS} -DFLB_HAVE_INOTIFY"
  525. fi
  526. FLUENT_BIT_BUILD_SUCCESS=1
  527. run_ok "Fluent-Bit built successfully."
  528. else
  529. warning "Failed to build Fluent-Bit, Netdata Logs Management support will be disabled in this build."
  530. ENABLE_LOGS_MANAGEMENT=0
  531. fi
  532. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  533. }
  534. bundle_fluentbit
  535. # -----------------------------------------------------------------------------
  536. # If we’re installing the Go plugin, ensure a working Go toolchain is installed.
  537. if [ "${ENABLE_GO}" -eq 1 ]; then
  538. progress "Checking for a usable Go toolchain and attempting to install one to /usr/local/go if needed."
  539. . "${NETDATA_SOURCE_DIR}/packaging/check-for-go-toolchain.sh"
  540. if ! ensure_go_toolchain; then
  541. warning "Go ${GOLANG_MIN_VERSION} needed to build Go plugin, but could not find or install a usable toolchain: ${GOLANG_FAILURE_REASON}"
  542. ENABLE_GO=0
  543. fi
  544. fi
  545. # -----------------------------------------------------------------------------
  546. # If we have the dashboard switching logic, make sure we're on the classic
  547. # dashboard during the install (updates don't work correctly otherwise).
  548. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
  549. "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
  550. fi
  551. # -----------------------------------------------------------------------------
  552. # By default, `git` does not update local tags based on remotes. Because
  553. # we use the most recent tag as part of our version determination in
  554. # our build, this can lead to strange versions that look ancient but are
  555. # actually really recent. To avoid this, try and fetch tags if we're
  556. # working in a git checkout.
  557. if [ -d ./.git ] ; then
  558. echo >&2
  559. progress "Updating tags in git to ensure a consistent version number"
  560. run git fetch -t || true
  561. fi
  562. # -----------------------------------------------------------------------------
  563. echo >&2
  564. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
  565. NETDATA_BUILD_DIR="${NETDATA_BUILD_DIR:-./build/}"
  566. rm -rf "${NETDATA_BUILD_DIR}"
  567. # function to extract values from the config file
  568. config_option() {
  569. section="${1}"
  570. key="${2}"
  571. value="${3}"
  572. if [ -x "${NETDATA_PREFIX}/usr/sbin/netdata" ] && [ -r "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  573. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  574. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  575. -W get "${section}" "${key}" "${value}" ||
  576. echo "${value}"
  577. else
  578. echo "${value}"
  579. fi
  580. }
  581. # the user netdata will run as
  582. if [ "$(id -u)" = "0" ]; then
  583. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  584. ROOT_USER="root"
  585. else
  586. NETDATA_USER="${USER}"
  587. ROOT_USER="${USER}"
  588. fi
  589. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}" 2> /dev/null)"
  590. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  591. echo >&2 "Netdata user and group set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  592. prepare_cmake_options
  593. if [ -n "${NETDATA_PREPARE_ONLY}" ]; then
  594. progress "Exiting before building Netdata as requested."
  595. printf "Would have used the following CMake command line for configuration: %s\n" "${cmake} ${NETDATA_CMAKE_OPTIONS}"
  596. trap - EXIT
  597. exit 0
  598. fi
  599. # Let cmake know we don't want to link shared libs
  600. if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
  601. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DBUILD_SHARED_LIBS=Off"
  602. fi
  603. # shellcheck disable=SC2086
  604. if ! run ${cmake} ${NETDATA_CMAKE_OPTIONS}; then
  605. fatal "Failed to configure Netdata sources." I000A
  606. fi
  607. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  608. # remove the build_error hook
  609. trap - EXIT
  610. # -----------------------------------------------------------------------------
  611. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
  612. # -----------------------------------------------------------------------------
  613. progress "Compile netdata"
  614. # shellcheck disable=SC2086
  615. if ! run ${cmake} --build "${NETDATA_BUILD_DIR}" --parallel ${JOBS} -- ${BUILD_OPTS}; then
  616. fatal "Failed to build Netdata." I000B
  617. fi
  618. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  619. # -----------------------------------------------------------------------------
  620. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
  621. # -----------------------------------------------------------------------------
  622. progress "Install netdata"
  623. if ! cmake_install "${NETDATA_BUILD_DIR}"; then
  624. fatal "Failed to install Netdata." I000C
  625. fi
  626. # -----------------------------------------------------------------------------
  627. progress "Creating standard user and groups for netdata"
  628. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  629. NETDATA_ADDED_TO_GROUPS=""
  630. if [ "$(id -u)" -eq 0 ]; then
  631. progress "Adding group 'netdata'"
  632. portable_add_group netdata || :
  633. progress "Adding user 'netdata'"
  634. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  635. progress "Assign user 'netdata' to required groups"
  636. for g in ${NETDATA_WANTED_GROUPS}; do
  637. # shellcheck disable=SC2086
  638. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  639. done
  640. # Netdata must be able to read /etc/pve/qemu-server/* and /etc/pve/lxc/*
  641. # for reading VMs/containers names, CPU and memory limits on Proxmox.
  642. if [ -d "/etc/pve" ]; then
  643. portable_add_user_to_group "www-data" netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} www-data"
  644. fi
  645. else
  646. run_failed "The installer does not run as root. Nothing to do for user and groups"
  647. fi
  648. # -----------------------------------------------------------------------------
  649. progress "Install logrotate configuration for netdata"
  650. install_netdata_logrotate
  651. # -----------------------------------------------------------------------------
  652. progress "Read installation options from netdata.conf"
  653. # create an empty config if it does not exist
  654. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  655. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  656. # port
  657. defport=19999
  658. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  659. # directories
  660. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  661. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  662. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  663. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  664. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  665. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  666. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  667. NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
  668. cat << OPTIONSEOF
  669. Permissions
  670. - netdata user : ${NETDATA_USER}
  671. - netdata group : ${NETDATA_GROUP}
  672. - root user : ${ROOT_USER}
  673. Directories
  674. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  675. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  676. - netdata log dir : ${NETDATA_LOG_DIR}
  677. - netdata run dir : ${NETDATA_RUN_DIR}
  678. - netdata lib dir : ${NETDATA_LIB_DIR}
  679. - netdata web dir : ${NETDATA_WEB_DIR}
  680. - netdata cache dir : ${NETDATA_CACHE_DIR}
  681. Other
  682. - netdata port : ${NETDATA_PORT}
  683. OPTIONSEOF
  684. # -----------------------------------------------------------------------------
  685. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  686. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  687. # this is needed if NETDATA_PREFIX is not empty
  688. if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
  689. warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
  690. fi
  691. fi
  692. # --- stock conf dir ----
  693. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  694. [ -L "${NETDATA_USER_CONFIG_DIR}/orig" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/orig"
  695. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/orig"
  696. # --- web dir ----
  697. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  698. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  699. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  700. fi
  701. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  702. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  703. # --- data dirs ----
  704. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  705. if [ ! -d "${x}" ]; then
  706. echo >&2 "Creating directory '${x}'"
  707. if ! run mkdir -p "${x}"; then
  708. warning "Failed to create ${x}, it must be created by hand or the Netdata Agent will not be able to be started."
  709. fi
  710. fi
  711. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  712. #run find "${x}" -type f -exec chmod 0660 {} \;
  713. #run find "${x}" -type d -exec chmod 0770 {} \;
  714. done
  715. run chmod 755 "${NETDATA_LOG_DIR}"
  716. # --- claiming dir ----
  717. if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
  718. echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
  719. if ! run mkdir -p "${NETDATA_CLAIMING_DIR}"; then
  720. warning "failed to create ${NETDATA_CLAIMING_DIR}, it will need to be created manually."
  721. fi
  722. fi
  723. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
  724. run chmod 770 "${NETDATA_CLAIMING_DIR}"
  725. # --- plugins ----
  726. if [ "$(id -u)" -eq 0 ]; then
  727. # find the admin group
  728. admin_group=
  729. test -z "${admin_group}" && get_group root > /dev/null 2>&1 && admin_group="root"
  730. test -z "${admin_group}" && get_group daemon > /dev/null 2>&1 && admin_group="daemon"
  731. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  732. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  733. run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  734. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  735. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  736. # shellcheck disable=SC2086
  737. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
  738. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  739. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  740. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  741. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  742. capabilities=0
  743. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  744. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  745. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  746. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  747. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  748. fi
  749. fi
  750. if [ $capabilities -eq 0 ]; then
  751. # fix apps.plugin to be setuid to root
  752. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  753. fi
  754. fi
  755. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" ]; then
  756. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  757. capabilities=0
  758. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  759. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  760. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"; then
  761. # if we managed to setcap, but we fail to execute debugfs.plugin setuid to root
  762. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  763. fi
  764. fi
  765. if [ $capabilities -eq 0 ]; then
  766. # fix debugfs.plugin to be setuid to root
  767. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  768. fi
  769. fi
  770. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin" ]; then
  771. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  772. capabilities=0
  773. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  774. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  775. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"; then
  776. capabilities=1
  777. fi
  778. fi
  779. if [ $capabilities -eq 0 ]; then
  780. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  781. fi
  782. fi
  783. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin" ]; then
  784. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  785. capabilities=0
  786. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  787. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  788. if run setcap cap_dac_read_search,cap_syslog+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"; then
  789. capabilities=1
  790. fi
  791. fi
  792. if [ $capabilities -eq 0 ]; then
  793. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/logs-management.plugin"
  794. fi
  795. fi
  796. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  797. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  798. capabilities=0
  799. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  800. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  801. 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
  802. capabilities=1
  803. fi
  804. fi
  805. if [ $capabilities -eq 0 ]; then
  806. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  807. fi
  808. fi
  809. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
  810. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  811. capabilities=0
  812. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  813. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  814. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"; then
  815. capabilities=1
  816. fi
  817. fi
  818. if [ $capabilities -eq 0 ]; then
  819. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  820. fi
  821. fi
  822. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  823. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  824. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  825. fi
  826. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  827. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  828. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  829. fi
  830. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  831. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  832. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  833. fi
  834. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  835. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  836. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  837. fi
  838. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
  839. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  840. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  841. fi
  842. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  843. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  844. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  845. fi
  846. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  847. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  848. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  849. fi
  850. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners" ]; then
  851. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  852. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  853. fi
  854. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin" ]; then
  855. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
  856. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
  857. fi
  858. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo" ]; then
  859. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  860. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  861. fi
  862. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin" ]; then
  863. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  864. capabilities=1
  865. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  866. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  867. 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
  868. capabilities=0
  869. fi
  870. fi
  871. if [ $capabilities -eq 0 ]; then
  872. # fix go.d.plugin to be setuid to root
  873. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  874. fi
  875. fi
  876. else
  877. # non-privileged user installation
  878. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  879. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  880. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  881. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  882. fi
  883. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  884. detect_libc() {
  885. libc=
  886. if ldd --version 2>&1 | grep -q -i glibc; then
  887. echo >&2 " Detected GLIBC"
  888. libc="glibc"
  889. elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
  890. echo >&2 " Detected GLIBC"
  891. libc="glibc"
  892. elif ldd --version 2>&1 | grep -q -i musl; then
  893. echo >&2 " Detected musl"
  894. libc="musl"
  895. else
  896. cmd=$(ldd /bin/sh | grep -w libc | cut -d" " -f 3)
  897. if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
  898. echo >&2 " Detected GLIBC"
  899. libc="glibc"
  900. fi
  901. fi
  902. if [ -z "$libc" ]; then
  903. warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
  904. return 1
  905. fi
  906. echo "${libc}"
  907. }
  908. should_install_fluentbit() {
  909. if [ "$(uname -s)" = "Darwin" ]; then
  910. return 1
  911. fi
  912. if [ "${ENABLE_LOGS_MANAGEMENT}" = 0 ]; then
  913. warning "netdata-installer.sh run with --disable-logsmanagement, Fluent-Bit installation is skipped."
  914. return 1
  915. elif [ "${FLUENT_BIT_BUILD_SUCCESS:=0}" -eq 0 ]; then
  916. run_failed "Fluent-Bit was not built successfully, Netdata Logs Management support will be disabled in this build."
  917. return 1
  918. elif [ ! -f src/fluent-bit/build/lib/libfluent-bit.so ]; then
  919. run_failed "libfluent-bit.so is missing, Netdata Logs Management support will be disabled in this build."
  920. return 1
  921. fi
  922. return 0
  923. }
  924. install_fluentbit() {
  925. if ! should_install_fluentbit; then
  926. enable_feature PLUGIN_LOGS_MANAGEMENT 0
  927. return 0
  928. fi
  929. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Fluent-Bit."
  930. run chown "root:${NETDATA_GROUP}" src/fluent-bit/build/lib
  931. run chmod 0644 src/fluent-bit/build/lib/libfluent-bit.so
  932. run cp -a -v src/fluent-bit/build/lib/libfluent-bit.so "${NETDATA_PREFIX}"/usr/lib/netdata
  933. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  934. }
  935. progress "Installing Fluent-Bit plugin"
  936. install_fluentbit
  937. # -----------------------------------------------------------------------------
  938. progress "Telemetry configuration"
  939. # Opt-out from telemetry program
  940. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  941. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  942. else
  943. 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"
  944. fi
  945. # -----------------------------------------------------------------------------
  946. progress "Install netdata at system init"
  947. # By default we assume the shutdown/startup of the Netdata Agent are effectively
  948. # without any system supervisor/init like SystemD or SysV. So we assume the most
  949. # basic startup/shutdown commands...
  950. NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
  951. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  952. if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
  953. # If docker runs systemd for some weird reason, let the install proceed
  954. is_systemd_running="NO"
  955. if command -v pidof > /dev/null 2>&1; then
  956. is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
  957. else
  958. is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
  959. fi
  960. if [ "${is_systemd_running}" = "1" ]; then
  961. echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
  962. install_netdata_service || run_failed "Cannot install netdata init service."
  963. else
  964. echo >&2 "We are running within a docker container, will not be installing netdata service"
  965. fi
  966. echo >&2
  967. else
  968. install_netdata_service || run_failed "Cannot install netdata init service."
  969. fi
  970. # -----------------------------------------------------------------------------
  971. # check if we can re-start netdata
  972. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  973. started=0
  974. if [ ${DONOTSTART} -eq 1 ]; then
  975. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  976. else
  977. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  978. fatal "Cannot start netdata!" I000D
  979. fi
  980. started=1
  981. run_ok "netdata started!"
  982. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  983. fi
  984. run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  985. if [ "$(uname)" = "Linux" ]; then
  986. # -------------------------------------------------------------------------
  987. progress "Check KSM (kernel memory deduper)"
  988. ksm_is_available_but_disabled() {
  989. cat << KSM1
  990. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  991. You have kernel memory de-duper (called Kernel Same-page Merging,
  992. or KSM) available, but it is not currently enabled.
  993. To enable it run:
  994. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  995. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  996. If you enable it, you will save 40-60% of netdata memory.
  997. KSM1
  998. }
  999. ksm_is_not_available() {
  1000. cat << KSM2
  1001. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  1002. It seems you do not have kernel memory de-duper (called Kernel Same-page
  1003. Merging, or KSM) available.
  1004. To enable it, you need a kernel built with CONFIG_KSM=y
  1005. If you can have it, you will save 40-60% of netdata memory.
  1006. KSM2
  1007. }
  1008. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  1009. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  1010. ksm_is_available_but_disabled
  1011. fi
  1012. else
  1013. ksm_is_not_available
  1014. fi
  1015. fi
  1016. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1017. # -----------------------------------------------------------------------------
  1018. progress "Check apps.plugin"
  1019. if [ "$(id -u)" -ne 0 ]; then
  1020. cat << SETUID_WARNING
  1021. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  1022. Since you have installed netdata as a normal user, to have apps.plugin collect
  1023. all the needed data, you have to give it the access rights it needs, by running
  1024. either of the following sets of commands:
  1025. To run apps.plugin with escalated capabilities:
  1026. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1027. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1028. ${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}
  1029. or, to run apps.plugin as root:
  1030. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1031. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1032. apps.plugin is performing a hard-coded function of data collection for all
  1033. running processes. It cannot be instructed from the netdata daemon to perform
  1034. any task, so it is pretty safe to do this.
  1035. SETUID_WARNING
  1036. fi
  1037. fi
  1038. # -----------------------------------------------------------------------------
  1039. progress "Copy uninstaller"
  1040. if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
  1041. echo >&2 "Removing uninstaller from old location"
  1042. rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
  1043. fi
  1044. 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"
  1045. chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  1046. # -----------------------------------------------------------------------------
  1047. progress "Basic netdata instructions"
  1048. cat << END
  1049. netdata by default listens on all IPs on port ${NETDATA_PORT},
  1050. so you can access it with:
  1051. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  1052. To stop netdata run:
  1053. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  1054. To start netdata run:
  1055. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  1056. END
  1057. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
  1058. echo >&2
  1059. # -----------------------------------------------------------------------------
  1060. progress "Installing (but not enabling) the netdata updater tool"
  1061. install_netdata_updater || run_failed "Cannot install netdata updater tool."
  1062. # -----------------------------------------------------------------------------
  1063. progress "Wrap up environment set up"
  1064. # Save environment variables
  1065. echo >&2 "Preparing .environment file"
  1066. cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  1067. # Created by installer
  1068. PATH="${PATH}"
  1069. CFLAGS="${CFLAGS}"
  1070. LDFLAGS="${LDFLAGS}"
  1071. MAKEOPTS="${MAKEOPTS}"
  1072. NETDATA_TMPDIR="${TMPDIR}"
  1073. NETDATA_PREFIX="${NETDATA_PREFIX}"
  1074. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS}"
  1075. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  1076. INSTALL_UID="$(id -u)"
  1077. NETDATA_GROUP="${NETDATA_GROUP}"
  1078. REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
  1079. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  1080. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
  1081. NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
  1082. EOF
  1083. run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
  1084. echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
  1085. cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  1086. new_installation
  1087. EOF
  1088. print_deferred_errors
  1089. # -----------------------------------------------------------------------------
  1090. echo >&2
  1091. progress "We are done!"
  1092. if [ ${started} -eq 1 ]; then
  1093. netdata_banner
  1094. progress "is installed and running now!"
  1095. else
  1096. netdata_banner
  1097. progress "is installed now!"
  1098. fi
  1099. echo >&2 " enjoy real-time performance and health monitoring..."
  1100. echo >&2
  1101. exit 0