netdata-installer.sh 43 KB

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