netdata-installer.sh 70 KB

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