netdata-installer.sh 44 KB

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