netdata-installer.sh 57 KB

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