netdata-installer.sh 59 KB

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