netdata-installer.sh 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # Next unused error code: I0012
  4. export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
  5. uniquepath() {
  6. path=""
  7. tmp="$(mktemp)"
  8. (echo "${PATH}" | tr ":" "\n") > "$tmp"
  9. while read -r REPLY;
  10. do
  11. if echo "${path}" | grep -v "(^|:)${REPLY}(:|$)"; then
  12. [ -n "${path}" ] && path="${path}:"
  13. path="${path}${REPLY}"
  14. fi
  15. done < "$tmp"
  16. rm "$tmp"
  17. [ -n "${path}" ]
  18. export PATH="${path%:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin}"
  19. } > /dev/null
  20. uniquepath
  21. PROGRAM="$0"
  22. NETDATA_SOURCE_DIR="$(pwd)"
  23. INSTALLER_DIR="$(dirname "${PROGRAM}")"
  24. if [ "${NETDATA_SOURCE_DIR}" != "${INSTALLER_DIR}" ] && [ "${INSTALLER_DIR}" != "." ]; then
  25. echo >&2 "Warning: you are currently in '${NETDATA_SOURCE_DIR}' but the installer is in '${INSTALLER_DIR}'."
  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. # load the required functions
  35. if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
  36. # shellcheck source=packaging/installer/functions.sh
  37. . "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
  38. else
  39. # shellcheck source=packaging/installer/functions.sh
  40. . "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
  41. fi
  42. # Used to enable saved warnings support in functions.sh
  43. # shellcheck disable=SC2034
  44. NETDATA_SAVE_WARNINGS=1
  45. # -----------------------------------------------------------------------------
  46. # figure out an appropriate temporary directory
  47. _cannot_use_tmpdir() {
  48. testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
  49. ret=0
  50. if [ -z "${testfile}" ]; then
  51. return "${ret}"
  52. fi
  53. if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then
  54. if chmod +x "${testfile}"; then
  55. if [ "$("${testfile}")" = "SUCCESS" ]; then
  56. ret=1
  57. fi
  58. fi
  59. fi
  60. rm -f "${testfile}"
  61. return "${ret}"
  62. }
  63. if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
  64. if _cannot_use_tmpdir /tmp; then
  65. if _cannot_use_tmpdir "${PWD}"; then
  66. fatal "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." I0000
  67. else
  68. TMPDIR="${PWD}"
  69. fi
  70. else
  71. TMPDIR="/tmp"
  72. fi
  73. fi
  74. # -----------------------------------------------------------------------------
  75. # set up handling for deferred error messages
  76. #
  77. # This leverages the saved warnings functionality shared with some functions from functions.sh
  78. print_deferred_errors() {
  79. if [ -n "${SAVED_WARNINGS}" ]; then
  80. printf >&2 "\n"
  81. printf >&2 "%b\n" "The following warnings and non-fatal errors were encountered during the installation process:"
  82. printf >&2 "%b\n" "${SAVED_WARNINGS}"
  83. printf >&2 "\n"
  84. fi
  85. }
  86. # make sure we save all commands we run
  87. # Variable is used by code in the packaging/installer/functions.sh
  88. # shellcheck disable=SC2034
  89. run_logfile="netdata-installer.log"
  90. # -----------------------------------------------------------------------------
  91. # fix PKG_CHECK_MODULES error
  92. if [ -d /usr/share/aclocal ]; then
  93. ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
  94. export ACLOCAL_PATH
  95. fi
  96. export LC_ALL=C
  97. umask 002
  98. # Be nice on production environments
  99. renice 19 $$ > /dev/null 2> /dev/null
  100. # you can set CFLAGS before running installer
  101. # shellcheck disable=SC2269
  102. LDFLAGS="${LDFLAGS}"
  103. CFLAGS="${CFLAGS-"-O2 -pipe"}"
  104. [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
  105. # shellcheck disable=SC2269
  106. ACLK="${ACLK}"
  107. # keep a log of this command
  108. {
  109. printf "\n# "
  110. date
  111. printf 'CFLAGS="%s" ' "${CFLAGS}"
  112. printf 'LDFLAGS="%s" ' "${LDFLAGS}"
  113. printf "%s" "${PROGRAM}" "${@}"
  114. printf "\n"
  115. } >> netdata-installer.log
  116. REINSTALL_OPTIONS="$(
  117. printf "%s" "${*}"
  118. printf "\n"
  119. )"
  120. # remove options that shown not be inherited by netdata-updater.sh
  121. REINSTALL_OPTIONS="$(echo "${REINSTALL_OPTIONS}" | sed 's/--dont-wait//g' | sed 's/--dont-start-it//g')"
  122. banner_nonroot_install() {
  123. cat << NONROOTNOPREFIX
  124. ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
  125. You are attempting to install netdata as a non-root user, but you plan
  126. to install it in system paths.
  127. Please set an installation prefix, like this:
  128. $PROGRAM ${@} --install-prefix /tmp
  129. or, run the installer as root:
  130. sudo $PROGRAM ${@}
  131. We suggest to install it as root, or certain data collectors will
  132. not be able to work. Netdata drops root privileges when running.
  133. So, if you plan to keep it, install it as root to get the full
  134. functionality.
  135. NONROOTNOPREFIX
  136. }
  137. banner_root_notify() {
  138. cat << NONROOT
  139. ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
  140. You are about to install netdata as a non-root user.
  141. Netdata will work, but a few data collection modules that
  142. require root access will fail.
  143. If you are installing netdata permanently on your system, run
  144. the installer like this:
  145. ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
  146. NONROOT
  147. }
  148. usage() {
  149. netdata_banner
  150. progress "installer command line options"
  151. cat << HEREDOC
  152. USAGE: ${PROGRAM} [options]
  153. where options include:
  154. --install-prefix <path> Install netdata in <path>. Ex. --install-prefix /opt will put netdata in /opt/netdata.
  155. --dont-start-it Do not (re)start netdata after installation.
  156. --dont-wait Run installation in non-interactive mode.
  157. --stable-channel Use packages from GitHub release pages instead of nightly updates.
  158. This results in less frequent updates.
  159. --nightly-channel Use most recent nightly updates instead of GitHub releases.
  160. This results in more frequent updates.
  161. --disable-ebpf Disable eBPF Kernel plugin. Default: enabled.
  162. --force-legacy-cxx Force usage of an older C++ standard to allow building on older systems. This will usually be autodetected.
  163. --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
  164. --disable-plugin-freeipmi Explicitly disable the FreeIPMI plugin.
  165. --disable-dbengine Explicitly disable DB engine support.
  166. --enable-plugin-go Enable the Go plugin. Default: Enabled when possible.
  167. --disable-plugin-go Disable the Go plugin.
  168. --disable-go Disable all Go components.
  169. --enable-plugin-nfacct Enable nfacct plugin. Default: enable it when libmnl and libnetfilter_acct are available.
  170. --disable-plugin-nfacct Explicitly disable the nfacct plugin.
  171. --enable-plugin-xenstat Enable the xenstat plugin. Default: enable it when libxenstat and libyajl are available.
  172. --disable-plugin-xenstat Explicitly disable the xenstat plugin.
  173. --enable-plugin-systemd-journal Enable the systemd journal plugin. Default: enable it when libsystemd is available.
  174. --disable-plugin-systemd-journal Explicitly disable the systemd journal plugin.
  175. --enable-exporting-kinesis Enable AWS Kinesis exporting connector. Default: enable it when libaws_cpp_sdk_kinesis
  176. and its dependencies are available.
  177. --disable-exporting-kinesis Explicitly disable AWS Kinesis exporting connector.
  178. --enable-exporting-prometheus-remote-write Enable Prometheus remote write exporting connector. Default: enable it
  179. when libprotobuf and libsnappy are available.
  180. --disable-exporting-prometheus-remote-write Explicitly disable Prometheus remote write exporting connector.
  181. --enable-exporting-mongodb Enable MongoDB exporting connector. Default: enable it when libmongoc is available.
  182. --disable-exporting-mongodb Explicitly disable MongoDB exporting connector.
  183. --enable-exporting-pubsub Enable Google Cloud PubSub exporting connector. Default: enable it when
  184. libgoogle_cloud_cpp_pubsub_protos and its dependencies are available.
  185. --disable-exporting-pubsub Explicitly disable Google Cloud PubSub exporting connector.
  186. --enable-lto Enable link-time optimization. Default: disabled.
  187. --disable-lto Explicitly disable link-time optimization.
  188. --enable-ml Enable anomaly detection with machine learning. Default: autodetect.
  189. --disable-ml Explicitly disable anomaly detection with machine learning.
  190. --disable-x86-sse Disable SSE instructions & optimizations. Default: enabled.
  191. --use-system-protobuf Use a system copy of libprotobuf instead of bundled copy. Default: bundled.
  192. --zlib-is-really-here
  193. --libs-are-really-here If you see errors about missing zlib or libuuid but you know it is available, you might
  194. have a broken pkg-config. Use this option to proceed without checking pkg-config.
  195. --disable-telemetry Opt-out from our anonymous telemetry program. (DISABLE_TELEMETRY=1)
  196. --skip-available-ram-check Skip checking the amount of RAM the system has and pretend it has enough to build safely.
  197. HEREDOC
  198. }
  199. if [ "$(uname -s)" = "Linux" ]; then
  200. case "$(uname -m)" in
  201. x86_64|i?86) ENABLE_EBPF=1 ;;
  202. esac
  203. fi
  204. DONOTSTART=0
  205. DONOTWAIT=0
  206. NETDATA_PREFIX=
  207. LIBS_ARE_HERE=0
  208. NETDATA_ENABLE_ML=""
  209. ENABLE_DBENGINE=1
  210. ENABLE_GO=1
  211. ENABLE_H2O=1
  212. FORCE_LEGACY_CXX=0
  213. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS-}"
  214. RELEASE_CHANNEL="nightly" # valid values are 'nightly' and 'stable'
  215. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY:-"no"}"
  216. while [ -n "${1}" ]; do
  217. case "${1}" in
  218. "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
  219. "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
  220. "--use-system-protobuf") USE_SYSTEM_PROTOBUF=1 ;;
  221. "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
  222. "--dont-start-it") DONOTSTART=1 ;;
  223. "--dont-wait") DONOTWAIT=1 ;;
  224. "--auto-update" | "-u") ;;
  225. "--auto-update-type") ;;
  226. "--stable-channel") RELEASE_CHANNEL="stable" ;;
  227. "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
  228. "--force-legacy-cxx") FORCE_LEGACY_CXX=1 ;;
  229. "--enable-plugin-freeipmi") ENABLE_FREEIPMI=1 ;;
  230. "--disable-plugin-freeipmi") ENABLE_FREEIPMI=0 ;;
  231. "--disable-https")
  232. warning "HTTPS cannot be disabled."
  233. ;;
  234. "--disable-dbengine") ENABLE_DBENGINE=0 ;;
  235. "--enable-plugin-go") ENABLE_GO=1 ;;
  236. "--disable-plugin-go") ENABLE_GO=0 ;;
  237. "--disable-go") ENABLE_GO=0 ;;
  238. "--enable-plugin-nfacct") ENABLE_NFACCT=1 ;;
  239. "--disable-plugin-nfacct") ENABLE_NFACCT=0 ;;
  240. "--enable-plugin-xenstat") ENABLE_XENSTAT=1 ;;
  241. "--disable-plugin-xenstat") ENABLE_XENSTAT=0 ;;
  242. "--enable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=1 ;;
  243. "--disable-plugin-systemd-journal") ENABLE_SYSTEMD_JOURNAL=0 ;;
  244. "--enable-exporting-kinesis" | "--enable-backend-kinesis")
  245. # TODO: Needs CMake Support
  246. ;;
  247. "--disable-exporting-kinesis" | "--disable-backend-kinesis")
  248. # TODO: Needs CMake Support
  249. ;;
  250. "--enable-exporting-prometheus-remote-write" | "--enable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=1 ;;
  251. "--disable-exporting-prometheus-remote-write" | "--disable-backend-prometheus-remote-write") EXPORTER_PROMETHEUS=0 ;;
  252. "--enable-exporting-mongodb" | "--enable-backend-mongodb") EXPORTER_MONGODB=1 ;;
  253. "--disable-exporting-mongodb" | "--disable-backend-mongodb") EXPORTER_MONGODB=0 ;;
  254. "--enable-exporting-pubsub")
  255. # TODO: Needs CMake support
  256. ;;
  257. "--disable-exporting-pubsub")
  258. # TODO: Needs CMake support
  259. ;;
  260. "--enable-ml") NETDATA_ENABLE_ML=1 ;;
  261. "--disable-ml") NETDATA_ENABLE_ML=0 ;;
  262. "--enable-lto")
  263. # TODO: Needs CMake support
  264. ;;
  265. "--disable-lto")
  266. # TODO: Needs CMake support
  267. ;;
  268. "--disable-x86-sse")
  269. # XXX: No longer supported.
  270. ;;
  271. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
  272. "--enable-ebpf") ENABLE_EBPF=1 ;;
  273. "--disable-ebpf") ENABLE_EBPF=0 ;;
  274. "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
  275. "--one-time-build")
  276. # XXX: No longer supported
  277. ;;
  278. "--disable-cloud")
  279. warning "Cloud cannot be disabled."
  280. ;;
  281. "--require-cloud") ;;
  282. "--build-json-c")
  283. NETDATA_BUILD_JSON_C=1
  284. ;;
  285. "--install-prefix")
  286. NETDATA_PREFIX="${2}/netdata"
  287. shift 1
  288. ;;
  289. "--install-no-prefix")
  290. NETDATA_PREFIX="${2}"
  291. shift 1
  292. ;;
  293. "--prepare-only")
  294. NETDATA_DISABLE_TELEMETRY=1
  295. NETDATA_PREPARE_ONLY=1
  296. DONOTWAIT=1
  297. ;;
  298. "--help" | "-h")
  299. usage
  300. exit 1
  301. ;;
  302. *)
  303. echo >&2 "Unrecognized option '${1}'."
  304. exit_reason "Unrecognized option '${1}'." I000E
  305. usage
  306. exit 1
  307. ;;
  308. esac
  309. shift 1
  310. done
  311. if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
  312. [ -n "$DISABLE_TELEMETRY" ] ||
  313. [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
  314. [ -n "$DO_NOT_TRACK" ]; then
  315. NETDATA_DISABLE_TELEMETRY=1
  316. fi
  317. if [ -n "${MAKEOPTS}" ]; then
  318. JOBS="$(echo "${MAKEOPTS}" | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
  319. else
  320. JOBS="$(find_processors)"
  321. fi
  322. if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
  323. mega="$((1024 * 1024))"
  324. base=1024
  325. scale=256
  326. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  327. total_ram="$(grep MemTotal /proc/meminfo | cut -d ':' -f 2 | tr -d ' kB')"
  328. total_ram="$((total_ram * 1024))"
  329. if [ "${total_ram}" -le "$((base * mega))" ] && [ -z "${NETDATA_ENABLE_ML}" ]; then
  330. NETDATA_ENABLE_ML=0
  331. fi
  332. if [ -z "${MAKEOPTS}" ]; then
  333. MAKEOPTS="-j${JOBS}"
  334. while [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ]; do
  335. JOBS="$((JOBS - 1))"
  336. target_ram="$((base * mega + (scale * mega * (JOBS - 1))))"
  337. MAKEOPTS="-j${JOBS}"
  338. done
  339. else
  340. if [ "${target_ram}" -gt "${total_ram}" ] && [ "${JOBS}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
  341. target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  342. total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  343. run_failed "Netdata needs ${target_ram} of RAM to safely install, but this system only has ${total_ram}. Try reducing the number of processes used for the install using the \$MAKEOPTS variable."
  344. exit_reason "Insufficient RAM to safely install." I000F
  345. exit 2
  346. fi
  347. fi
  348. fi
  349. # set default make options
  350. if [ -z "${MAKEOPTS}" ]; then
  351. MAKEOPTS="-j$(find_processors)"
  352. elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
  353. MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
  354. fi
  355. if [ "$(id -u)" -ne 0 ] && [ -z "${NETDATA_PREPARE_ONLY}" ]; then
  356. if [ -z "${NETDATA_PREFIX}" ]; then
  357. netdata_banner
  358. banner_nonroot_install "${@}"
  359. exit_reason "Attempted install as non-root user to /." I0010
  360. exit 1
  361. else
  362. banner_root_notify "${@}"
  363. fi
  364. fi
  365. netdata_banner
  366. progress "real-time performance monitoring, done right!"
  367. cat << BANNER1
  368. You are about to build and install netdata to your system.
  369. The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
  370. any temporary files. You can override this by setting \$TMPDIR to a
  371. writable directory where you can execute files.
  372. It will be installed at these locations:
  373. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  374. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  375. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  376. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  377. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  378. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  379. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  380. BANNER1
  381. [ "$(id -u)" -eq 0 ] && cat << BANNER2
  382. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  383. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  384. BANNER2
  385. cat << BANNER3
  386. This installer allows you to change the installation path.
  387. Press Control-C and run the same command with --help for help.
  388. BANNER3
  389. if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
  390. cat << BANNER4
  391. ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
  392. Anonymous usage stats will be collected and sent to Netdata.
  393. To opt-out, pass --disable-telemetry option to the installer or export
  394. the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
  395. (e.g: export DISABLE_TELEMETRY=1).
  396. BANNER4
  397. fi
  398. if ! command -v cmake >/dev/null 2>&1; then
  399. fatal "Could not find CMake, which is required to build Netdata." I0012
  400. else
  401. cmake="$(command -v cmake)"
  402. progress "Found CMake at ${cmake}. CMake version: $(${cmake} --version | head -n 1)"
  403. fi
  404. if ! command -v "ninja" >/dev/null 2>&1; then
  405. progress "Could not find Ninja, will use Make instead."
  406. else
  407. ninja="$(command -v ninja)"
  408. progress "Found Ninja at ${ninja}. Ninja version: $(${ninja} --version)"
  409. progress "Will use Ninja for this build instead of Make when possible."
  410. fi
  411. make="$(command -v make 2>/dev/null)"
  412. if [ -z "${make}" ] && [ -z "${ninja}" ]; then
  413. fatal "Could not find a usable underlying build system (we support make and ninja)." I0014
  414. fi
  415. CMAKE_OPTS="${ninja:+-G Ninja}"
  416. BUILD_OPTS="VERBOSE=1"
  417. [ -n "${ninja}" ] && BUILD_OPTS="-k 1"
  418. if [ ${DONOTWAIT} -eq 0 ]; then
  419. if [ -n "${NETDATA_PREFIX}" ]; then
  420. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  421. else
  422. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  423. fi
  424. read -r REPLY
  425. if [ "$REPLY" != '' ]; then
  426. exit_reason "User did not accept install attempt." I0011
  427. exit 1
  428. fi
  429. fi
  430. cmake_install() {
  431. # run cmake --install ${1}
  432. # The above command should be used to replace the logic below once we no longer support
  433. # versions of CMake less than 3.15.
  434. if [ -n "${ninja}" ]; then
  435. run ${ninja} -C "${1}" install
  436. else
  437. run ${make} -C "${1}" install
  438. fi
  439. }
  440. build_error() {
  441. netdata_banner
  442. trap - EXIT
  443. fatal "Netdata failed to build for an unknown reason." I0002
  444. }
  445. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  446. shift
  447. echo >&2 "ok, assuming libs are really installed."
  448. export ZLIB_CFLAGS=" "
  449. export ZLIB_LIBS="-lz"
  450. export UUID_CFLAGS=" "
  451. export UUID_LIBS="-luuid"
  452. fi
  453. trap build_error EXIT
  454. # -----------------------------------------------------------------------------
  455. # If we’re installing the Go plugin, ensure a working Go toolchain is installed.
  456. if [ "${ENABLE_GO}" -eq 1 ]; then
  457. progress "Checking for a usable Go toolchain and attempting to install one to /usr/local/go if needed."
  458. . "${NETDATA_SOURCE_DIR}/packaging/check-for-go-toolchain.sh"
  459. if ! ensure_go_toolchain; then
  460. warning "Go ${GOLANG_MIN_VERSION} needed to build Go plugin, but could not find or install a usable toolchain: ${GOLANG_FAILURE_REASON}"
  461. ENABLE_GO=0
  462. fi
  463. fi
  464. # -----------------------------------------------------------------------------
  465. # If we have the dashboard switching logic, make sure we're on the classic
  466. # dashboard during the install (updates don't work correctly otherwise).
  467. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
  468. "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
  469. fi
  470. # -----------------------------------------------------------------------------
  471. # By default, `git` does not update local tags based on remotes. Because
  472. # we use the most recent tag as part of our version determination in
  473. # our build, this can lead to strange versions that look ancient but are
  474. # actually really recent. To avoid this, try and fetch tags if we're
  475. # working in a git checkout.
  476. if [ -d ./.git ] ; then
  477. echo >&2
  478. progress "Updating tags in git to ensure a consistent version number"
  479. run git fetch -t || true
  480. fi
  481. # -----------------------------------------------------------------------------
  482. echo >&2
  483. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
  484. NETDATA_BUILD_DIR="${NETDATA_BUILD_DIR:-./build/}"
  485. rm -rf "${NETDATA_BUILD_DIR}"
  486. # function to extract values from the config file
  487. config_option() {
  488. section="${1}"
  489. key="${2}"
  490. value="${3}"
  491. if [ -x "${NETDATA_PREFIX}/usr/sbin/netdata" ] && [ -r "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  492. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  493. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  494. -W get "${section}" "${key}" "${value}" ||
  495. echo "${value}"
  496. else
  497. echo "${value}"
  498. fi
  499. }
  500. # the user netdata will run as
  501. if [ "$(id -u)" = "0" ]; then
  502. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  503. ROOT_USER="root"
  504. else
  505. NETDATA_USER="${USER}"
  506. ROOT_USER="${USER}"
  507. fi
  508. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}" 2> /dev/null)"
  509. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  510. echo >&2 "Netdata user and group set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  511. prepare_cmake_options
  512. if [ -n "${NETDATA_PREPARE_ONLY}" ]; then
  513. progress "Exiting before building Netdata as requested."
  514. printf "Would have used the following CMake command line for configuration: %s\n" "${cmake} ${NETDATA_CMAKE_OPTIONS}"
  515. trap - EXIT
  516. exit 0
  517. fi
  518. # Let cmake know we don't want to link shared libs
  519. if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
  520. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DBUILD_SHARED_LIBS=Off"
  521. fi
  522. # shellcheck disable=SC2086
  523. if ! run ${cmake} ${NETDATA_CMAKE_OPTIONS}; then
  524. fatal "Failed to configure Netdata sources." I000A
  525. fi
  526. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  527. # remove the build_error hook
  528. trap - EXIT
  529. # -----------------------------------------------------------------------------
  530. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
  531. # -----------------------------------------------------------------------------
  532. progress "Compile netdata"
  533. # shellcheck disable=SC2086
  534. if ! run ${cmake} --build "${NETDATA_BUILD_DIR}" --parallel ${JOBS} -- ${BUILD_OPTS}; then
  535. fatal "Failed to build Netdata." I000B
  536. fi
  537. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  538. # -----------------------------------------------------------------------------
  539. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
  540. # -----------------------------------------------------------------------------
  541. progress "Install netdata"
  542. if ! cmake_install "${NETDATA_BUILD_DIR}"; then
  543. fatal "Failed to install Netdata." I000C
  544. fi
  545. # -----------------------------------------------------------------------------
  546. progress "Creating standard user and groups for netdata"
  547. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  548. NETDATA_ADDED_TO_GROUPS=""
  549. if [ "$(id -u)" -eq 0 ]; then
  550. progress "Adding group 'netdata'"
  551. portable_add_group netdata || :
  552. progress "Adding user 'netdata'"
  553. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  554. progress "Assign user 'netdata' to required groups"
  555. for g in ${NETDATA_WANTED_GROUPS}; do
  556. # shellcheck disable=SC2086
  557. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  558. done
  559. # Netdata must be able to read /etc/pve/qemu-server/* and /etc/pve/lxc/*
  560. # for reading VMs/containers names, CPU and memory limits on Proxmox.
  561. if [ -d "/etc/pve" ]; then
  562. portable_add_user_to_group "www-data" netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} www-data"
  563. fi
  564. else
  565. run_failed "The installer does not run as root. Nothing to do for user and groups"
  566. fi
  567. # -----------------------------------------------------------------------------
  568. progress "Install logrotate configuration for netdata"
  569. install_netdata_logrotate
  570. progress "Install journald configuration for netdata"
  571. install_netdata_journald_conf
  572. # -----------------------------------------------------------------------------
  573. progress "Read installation options from netdata.conf"
  574. # create an empty config if it does not exist
  575. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  576. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  577. # port
  578. defport=19999
  579. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  580. # directories
  581. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  582. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  583. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  584. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  585. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  586. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  587. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  588. NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
  589. cat << OPTIONSEOF
  590. Permissions
  591. - netdata user : ${NETDATA_USER}
  592. - netdata group : ${NETDATA_GROUP}
  593. - root user : ${ROOT_USER}
  594. Directories
  595. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  596. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  597. - netdata log dir : ${NETDATA_LOG_DIR}
  598. - netdata run dir : ${NETDATA_RUN_DIR}
  599. - netdata lib dir : ${NETDATA_LIB_DIR}
  600. - netdata web dir : ${NETDATA_WEB_DIR}
  601. - netdata cache dir : ${NETDATA_CACHE_DIR}
  602. Other
  603. - netdata port : ${NETDATA_PORT}
  604. OPTIONSEOF
  605. # -----------------------------------------------------------------------------
  606. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  607. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  608. # this is needed if NETDATA_PREFIX is not empty
  609. if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
  610. warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
  611. fi
  612. fi
  613. # --- stock conf dir ----
  614. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  615. [ -L "${NETDATA_USER_CONFIG_DIR}/orig" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/orig"
  616. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/orig"
  617. # --- web dir ----
  618. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  619. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  620. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  621. fi
  622. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  623. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  624. # --- data dirs ----
  625. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  626. if [ ! -d "${x}" ]; then
  627. echo >&2 "Creating directory '${x}'"
  628. if ! run mkdir -p "${x}"; then
  629. warning "Failed to create ${x}, it must be created by hand or the Netdata Agent will not be able to be started."
  630. fi
  631. fi
  632. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  633. #run find "${x}" -type f -exec chmod 0660 {} \;
  634. #run find "${x}" -type d -exec chmod 0770 {} \;
  635. done
  636. run chmod 755 "${NETDATA_LOG_DIR}"
  637. # --- claiming dir ----
  638. if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
  639. echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
  640. if ! run mkdir -p "${NETDATA_CLAIMING_DIR}"; then
  641. warning "failed to create ${NETDATA_CLAIMING_DIR}, it will need to be created manually."
  642. fi
  643. fi
  644. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
  645. run chmod 770 "${NETDATA_CLAIMING_DIR}"
  646. # --- plugins ----
  647. if [ "$(id -u)" -eq 0 ]; then
  648. # find the admin group
  649. admin_group=
  650. test -z "${admin_group}" && get_group root > /dev/null 2>&1 && admin_group="root"
  651. test -z "${admin_group}" && get_group daemon > /dev/null 2>&1 && admin_group="daemon"
  652. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  653. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  654. run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  655. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  656. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  657. # shellcheck disable=SC2086
  658. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
  659. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  660. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  661. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  662. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  663. capabilities=0
  664. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  665. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  666. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  667. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  668. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  669. fi
  670. fi
  671. if [ $capabilities -eq 0 ]; then
  672. # fix apps.plugin to be setuid to root
  673. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  674. fi
  675. fi
  676. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" ]; then
  677. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  678. capabilities=0
  679. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  680. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  681. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"; then
  682. # if we managed to setcap, but we fail to execute debugfs.plugin setuid to root
  683. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  684. fi
  685. fi
  686. if [ $capabilities -eq 0 ]; then
  687. # fix debugfs.plugin to be setuid to root
  688. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/debugfs.plugin"
  689. fi
  690. fi
  691. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin" ]; then
  692. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  693. capabilities=0
  694. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  695. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  696. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"; then
  697. capabilities=1
  698. fi
  699. fi
  700. if [ $capabilities -eq 0 ]; then
  701. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/systemd-journal.plugin"
  702. fi
  703. fi
  704. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  705. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  706. capabilities=0
  707. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  708. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  709. if 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\""; then
  710. capabilities=1
  711. fi
  712. fi
  713. if [ $capabilities -eq 0 ]; then
  714. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  715. fi
  716. fi
  717. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
  718. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  719. capabilities=0
  720. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  721. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  722. if run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"; then
  723. capabilities=1
  724. fi
  725. fi
  726. if [ $capabilities -eq 0 ]; then
  727. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  728. fi
  729. fi
  730. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  731. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  732. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  733. fi
  734. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  735. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  736. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  737. fi
  738. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  739. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  740. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  741. fi
  742. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  743. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  744. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  745. fi
  746. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
  747. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  748. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  749. fi
  750. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  751. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  752. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  753. fi
  754. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  755. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  756. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  757. fi
  758. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners" ]; then
  759. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  760. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/local-listeners"
  761. fi
  762. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin" ]; then
  763. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
  764. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/network-viewer.plugin"
  765. fi
  766. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo" ]; then
  767. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  768. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ndsudo"
  769. fi
  770. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin" ]; then
  771. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  772. capabilities=1
  773. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  774. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  775. if ! run setcap "cap_dac_read_search+epi cap_net_admin+epi cap_net_raw=eip" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"; then
  776. capabilities=0
  777. fi
  778. fi
  779. if [ $capabilities -eq 0 ]; then
  780. # fix go.d.plugin to be setuid to root
  781. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  782. fi
  783. fi
  784. else
  785. # non-privileged user installation
  786. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  787. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  788. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  789. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  790. fi
  791. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  792. # -----------------------------------------------------------------------------
  793. progress "Telemetry configuration"
  794. # Opt-out from telemetry program
  795. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  796. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  797. else
  798. 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"
  799. fi
  800. # -----------------------------------------------------------------------------
  801. progress "Install netdata at system init"
  802. # By default we assume the shutdown/startup of the Netdata Agent are effectively
  803. # without any system supervisor/init like SystemD or SysV. So we assume the most
  804. # basic startup/shutdown commands...
  805. NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
  806. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  807. if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
  808. # If docker runs systemd for some weird reason, let the install proceed
  809. is_systemd_running="NO"
  810. if command -v pidof > /dev/null 2>&1; then
  811. is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
  812. else
  813. is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
  814. fi
  815. if [ "${is_systemd_running}" = "1" ]; then
  816. echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
  817. install_netdata_service || run_failed "Cannot install netdata init service."
  818. else
  819. echo >&2 "We are running within a docker container, will not be installing netdata service"
  820. fi
  821. echo >&2
  822. else
  823. install_netdata_service || run_failed "Cannot install netdata init service."
  824. fi
  825. # -----------------------------------------------------------------------------
  826. # check if we can re-start netdata
  827. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  828. started=0
  829. if [ ${DONOTSTART} -eq 1 ]; then
  830. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  831. else
  832. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  833. fatal "Cannot start netdata!" I000D
  834. fi
  835. started=1
  836. run_ok "netdata started!"
  837. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  838. fi
  839. run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  840. if [ "$(uname)" = "Linux" ]; then
  841. # -------------------------------------------------------------------------
  842. progress "Check KSM (kernel memory deduper)"
  843. ksm_is_available_but_disabled() {
  844. cat << KSM1
  845. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  846. You have kernel memory de-duper (called Kernel Same-page Merging,
  847. or KSM) available, but it is not currently enabled.
  848. To enable it run:
  849. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  850. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  851. If you enable it, you will save 40-60% of netdata memory.
  852. KSM1
  853. }
  854. ksm_is_not_available() {
  855. cat << KSM2
  856. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  857. It seems you do not have kernel memory de-duper (called Kernel Same-page
  858. Merging, or KSM) available.
  859. To enable it, you need a kernel built with CONFIG_KSM=y
  860. If you can have it, you will save 40-60% of netdata memory.
  861. KSM2
  862. }
  863. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  864. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  865. ksm_is_available_but_disabled
  866. fi
  867. else
  868. ksm_is_not_available
  869. fi
  870. fi
  871. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  872. # -----------------------------------------------------------------------------
  873. progress "Check apps.plugin"
  874. if [ "$(id -u)" -ne 0 ]; then
  875. cat << SETUID_WARNING
  876. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  877. Since you have installed netdata as a normal user, to have apps.plugin collect
  878. all the needed data, you have to give it the access rights it needs, by running
  879. either of the following sets of commands:
  880. To run apps.plugin with escalated capabilities:
  881. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  882. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  883. ${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}
  884. or, to run apps.plugin as root:
  885. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  886. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  887. apps.plugin is performing a hard-coded function of data collection for all
  888. running processes. It cannot be instructed from the netdata daemon to perform
  889. any task, so it is pretty safe to do this.
  890. SETUID_WARNING
  891. fi
  892. fi
  893. # -----------------------------------------------------------------------------
  894. progress "Copy uninstaller"
  895. if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
  896. echo >&2 "Removing uninstaller from old location"
  897. rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
  898. fi
  899. 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"
  900. chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  901. # -----------------------------------------------------------------------------
  902. progress "Basic netdata instructions"
  903. cat << END
  904. netdata by default listens on all IPs on port ${NETDATA_PORT},
  905. so you can access it with:
  906. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  907. To stop netdata run:
  908. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  909. To start netdata run:
  910. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  911. END
  912. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
  913. echo >&2
  914. # -----------------------------------------------------------------------------
  915. progress "Installing (but not enabling) the netdata updater tool"
  916. install_netdata_updater || run_failed "Cannot install netdata updater tool."
  917. # -----------------------------------------------------------------------------
  918. progress "Wrap up environment set up"
  919. # Save environment variables
  920. echo >&2 "Preparing .environment file"
  921. cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  922. # Created by installer
  923. PATH="${PATH}"
  924. CFLAGS="${CFLAGS}"
  925. LDFLAGS="${LDFLAGS}"
  926. MAKEOPTS="${MAKEOPTS}"
  927. NETDATA_TMPDIR="${TMPDIR}"
  928. NETDATA_PREFIX="${NETDATA_PREFIX}"
  929. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS}"
  930. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  931. INSTALL_UID="$(id -u)"
  932. NETDATA_GROUP="${NETDATA_GROUP}"
  933. REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
  934. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  935. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
  936. NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
  937. EOF
  938. run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
  939. echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
  940. cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  941. new_installation
  942. EOF
  943. print_deferred_errors
  944. # -----------------------------------------------------------------------------
  945. echo >&2
  946. progress "We are done!"
  947. if [ ${started} -eq 1 ]; then
  948. netdata_banner
  949. progress "is installed and running now!"
  950. else
  951. netdata_banner
  952. progress "is installed now!"
  953. fi
  954. echo >&2 " enjoy real-time performance and health monitoring..."
  955. echo >&2
  956. exit 0