netdata-installer.sh 44 KB

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