netdata-installer.sh 44 KB

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