netdata-installer.sh 72 KB

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