netdata-installer.sh 58 KB

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