netdata-installer.sh 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # shellcheck disable=SC2046,SC2086,SC2166
  4. export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
  5. uniquepath() {
  6. local path=""
  7. while read -r; do
  8. if [[ ! ${path} =~ (^|:)"${REPLY}"(:|$) ]]; then
  9. [ -n "${path}" ] && path="${path}:"
  10. path="${path}${REPLY}"
  11. fi
  12. done < <(echo "${PATH}" | tr ":" "\\n")
  13. [ -n "${path}" ] && [[ ${PATH} =~ /bin ]] && [[ ${PATH} =~ /sbin ]] && export PATH="${path}"
  14. }
  15. uniquepath
  16. PROGRAM="$0"
  17. NETDATA_SOURCE_DIR="$(pwd)"
  18. INSTALLER_DIR="$(dirname "${PROGRAM}")"
  19. if [ "${NETDATA_SOURCE_DIR}" != "${INSTALLER_DIR}" ] && [ "${INSTALLER_DIR}" != "." ]; then
  20. echo >&2 "Warning: you are currently in '${NETDATA_SOURCE_DIR}' but the installer is in '${INSTALLER_DIR}'."
  21. fi
  22. # -----------------------------------------------------------------------------
  23. # reload the user profile
  24. # shellcheck source=/dev/null
  25. [ -f /etc/profile ] && . /etc/profile
  26. # make sure /etc/profile does not change our current directory
  27. cd "${NETDATA_SOURCE_DIR}" || exit 1
  28. # -----------------------------------------------------------------------------
  29. # load the required functions
  30. if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
  31. # shellcheck source=packaging/installer/functions.sh
  32. source "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
  33. else
  34. # shellcheck source=packaging/installer/functions.sh
  35. source "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
  36. fi
  37. download_go() {
  38. url="${1}"
  39. dest="${2}"
  40. if command -v curl >/dev/null 2>&1; then
  41. run curl -sSL --connect-timeout 10 --retry 3 "${url}" > "${dest}"
  42. elif command -v wget >/dev/null 2>&1; then
  43. run wget -T 15 -O - "${url}" > "${dest}"
  44. else
  45. echo >&2
  46. echo >&2 "Downloading go.d plugin from '${url}' failed because of missing mandatory packages."
  47. echo >&2 "Either add packages or disable it by issuing '--disable-go' in the installer"
  48. echo >&2
  49. run_failed "I need curl or wget to proceed, but neither is available on this system."
  50. fi
  51. }
  52. # make sure we save all commands we run
  53. run_logfile="netdata-installer.log"
  54. # -----------------------------------------------------------------------------
  55. # fix PKG_CHECK_MODULES error
  56. if [ -d /usr/share/aclocal ]; then
  57. ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
  58. export ACLOCAL_PATH
  59. fi
  60. export LC_ALL=C
  61. umask 002
  62. # Be nice on production environments
  63. renice 19 $$ >/dev/null 2>/dev/null
  64. # you can set CFLAGS before running installer
  65. CFLAGS="${CFLAGS--O2}"
  66. [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
  67. # keep a log of this command
  68. # shellcheck disable=SC2129
  69. printf "\\n# " >>netdata-installer.log
  70. date >>netdata-installer.log
  71. printf 'CFLAGS="%s" ' "${CFLAGS}" >>netdata-installer.log
  72. printf "%q " "${PROGRAM}" "${@}" >>netdata-installer.log
  73. printf "\\n" >>netdata-installer.log
  74. REINSTALL_COMMAND="$(
  75. printf "%q " "${PROGRAM}" "${@}"
  76. printf "\\n"
  77. )"
  78. # remove options that shown not be inherited by netdata-updater.sh
  79. REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-wait/}"
  80. REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-start-it/}"
  81. if [ "${REINSTALL_COMMAND:0:1}" != "." ] && [ "${REINSTALL_COMMAND:0:1}" != "/" ] && [ -f "./${PROGRAM}" ]; then
  82. REINSTALL_COMMAND="./${REINSTALL_COMMAND}"
  83. fi
  84. banner_nonroot_install() {
  85. cat <<NONROOTNOPREFIX
  86. ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
  87. You are attempting to install netdata as non-root, but you plan
  88. to install it in system paths.
  89. Please set an installation prefix, like this:
  90. $PROGRAM ${@} --install /tmp
  91. or, run the installer as root:
  92. sudo $PROGRAM ${@}
  93. We suggest to install it as root, or certain data collectors will
  94. not be able to work. Netdata drops root privileges when running.
  95. So, if you plan to keep it, install it as root to get the full
  96. functionality.
  97. NONROOTNOPREFIX
  98. }
  99. banner_root_notify() {
  100. cat <<NONROOT
  101. ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
  102. You are about to install netdata as a non-root user.
  103. Netdata will work, but a few data collection modules that
  104. require root access will fail.
  105. If you installing netdata permanently on your system, run
  106. the installer like this:
  107. ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
  108. NONROOT
  109. }
  110. usage() {
  111. netdata_banner "installer command line options"
  112. cat <<HEREDOC
  113. USAGE: ${PROGRAM} [options]
  114. where options include:
  115. --install <path> Install netdata in <path>. Ex. --install /opt will put netdata in /opt/netdata
  116. --dont-start-it Do not (re)start netdata after installation
  117. --dont-wait Run installation in non-interactive mode
  118. --auto-update or -u Install netdata-updater in cron to update netdata automatically once per day
  119. --stable-channel Use packages from GitHub release pages instead of GCS (nightly updates).
  120. This results in less frequent updates.
  121. --disable-go Disable installation of go.d.plugin.
  122. --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
  123. --disable-plugin-freeipmi
  124. --enable-plugin-nfacct Enable nfacct plugin. Default: enable it when libmnl and libnetfilter_acct are available.
  125. --disable-plugin-nfacct
  126. --enable-plugin-xenstat Enable the xenstat plugin. Default: enable it when libxenstat and libyajl are available
  127. --disable-plugin-xenstat Disable the xenstat plugin.
  128. --enable-backend-kinesis Enable AWS Kinesis backend. Default: enable it when libaws_cpp_sdk_kinesis and libraries
  129. it depends on are available.
  130. --disable-backend-kinesis
  131. --enable-backend-prometheus-remote-write Enable Prometheus remote write backend. Default: enable it when libprotobuf and
  132. libsnappy are available.
  133. --disable-backend-prometheus-remote-write
  134. --enable-lto Enable Link-Time-Optimization. Default: enabled
  135. --disable-lto
  136. --disable-x86-sse Disable SSE instructions. By default SSE optimizations are enabled.
  137. --zlib-is-really-here or
  138. --libs-are-really-here If you get errors about missing zlib or libuuid but you know it is available, you might
  139. have a broken pkg-config. Use this option to proceed without checking pkg-config.
  140. --disable-telemetry Use this flag to opt-out from our anonymous telemetry progam.
  141. Netdata will by default be compiled with gcc optimization -O2
  142. If you need to pass different CFLAGS, use something like this:
  143. CFLAGS="<gcc options>" ${PROGRAM} [options]
  144. For the installer to complete successfully, you will need these packages installed:
  145. gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel) uuid-dev (or libuuid-devel)
  146. For the plugins, you will at least need:
  147. curl, bash v4+, python v2 or v3, node.js
  148. HEREDOC
  149. }
  150. DONOTSTART=0
  151. DONOTWAIT=0
  152. AUTOUPDATE=0
  153. NETDATA_PREFIX=
  154. LIBS_ARE_HERE=0
  155. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
  156. RELEASE_CHANNEL="nightly"
  157. while [ -n "${1}" ]; do
  158. case "${1}" in
  159. "--zlib-is-really-here") LIBS_ARE_HERE=1;;
  160. "--libs-are-really-here") LIBS_ARE_HERE=1;;
  161. "--dont-start-it") DONOTSTART=1;;
  162. "--dont-wait") DONOTWAIT=1;;
  163. "--auto-update"|"-u") AUTOUPDATE=1;;
  164. "--stable-channel") RELEASE_CHANNEL="stable";;
  165. "--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-freeipmi/} --enable-plugin-freeipmi";;
  166. "--disable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-freeipmi/} --disable-plugin-freeipmi";;
  167. "--enable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-nfacct/} --enable-plugin-nfacct";;
  168. "--disable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-nfacct/} --disable-plugin-nfacct";;
  169. "--enable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-xenstat/} --enable-plugin-xenstat";;
  170. "--disable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-xenstat/} --disable-plugin-xenstat";;
  171. "--enable-backend-kinesis") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-backend-kinesis/} --enable-backend-kinesis";;
  172. "--disable-backend-kinesis") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-backend-kinesis/} --disable-backend-kinesis";;
  173. "--enable-backend-prometheus-remote-write") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-backend-prometheus-remote-write/} --enable-backend-prometheus-remote-write";;
  174. "--disable-backend-prometheus-remote-write") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-backend-prometheus-remote-write/} --disable-backend-prometheus-remote-write";;
  175. "--enable-lto") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-lto/} --enable-lto";;
  176. "--disable-lto") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-lto/} --disable-lto";;
  177. "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse";;
  178. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1;;
  179. "--disable-go") NETDATA_DISABLE_GO=1;;
  180. "--install")
  181. NETDATA_PREFIX="${2}/netdata"
  182. shift 1
  183. ;;
  184. "--help"|"-h")
  185. usage
  186. exit 1
  187. ;;
  188. *)
  189. run_failed "I cannot understand option '$1'."
  190. usage
  191. exit 1
  192. ;;
  193. esac
  194. shift 1
  195. done
  196. # replace multiple spaces with a single space
  197. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS// / }"
  198. if [ "${UID}" -ne 0 ]; then
  199. if [ -z "${NETDATA_PREFIX}" ]; then
  200. netdata_banner "wrong command line options!"
  201. banner_nonroot_install "${@}"
  202. exit 1
  203. else
  204. banner_root_notify "${@}"
  205. fi
  206. fi
  207. netdata_banner "real-time performance monitoring, done right!"
  208. cat <<BANNER1
  209. You are about to build and install netdata to your system.
  210. It will be installed at these locations:
  211. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  212. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  213. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  214. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  215. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  216. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  217. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  218. BANNER1
  219. [ "${UID}" -eq 0 ] && cat <<BANNER2
  220. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  221. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  222. BANNER2
  223. cat <<BANNER3
  224. This installer allows you to change the installation path.
  225. Press Control-C and run the same command with --help for help.
  226. BANNER3
  227. have_autotools=
  228. if [ "$(type autoreconf 2>/dev/null)" ]; then
  229. autoconf_maj_min() {
  230. local maj min IFS=.-
  231. maj=$1
  232. min=$2
  233. set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
  234. eval $maj=\$1 $min=\$2
  235. }
  236. autoconf_maj_min AMAJ AMIN
  237. if [ "$AMAJ" -gt 2 ]; then
  238. have_autotools=Y
  239. elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]; then
  240. have_autotools=Y
  241. else
  242. echo "Found autotools $AMAJ.$AMIN"
  243. fi
  244. else
  245. echo "No autotools found"
  246. fi
  247. if [ ! "$have_autotools" ]; then
  248. if [ -f configure ]; then
  249. echo "Will skip autoreconf step"
  250. else
  251. netdata_banner "autotools v2.60 required"
  252. cat <<"EOF"
  253. -------------------------------------------------------------------------------
  254. autotools 2.60 or later is required
  255. Sorry, you do not seem to have autotools 2.60 or later, which is
  256. required to build from the git sources of netdata.
  257. EOF
  258. exit 1
  259. fi
  260. fi
  261. if [ ${DONOTWAIT} -eq 0 ]; then
  262. if [ -n "${NETDATA_PREFIX}" ]; then
  263. echo -n "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  264. else
  265. echo -n "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  266. fi
  267. read -ern1
  268. if [ "$REPLY" != '' ]; then
  269. exit 1
  270. fi
  271. fi
  272. build_error() {
  273. netdata_banner "sorry, it failed to build..."
  274. cat <<EOF
  275. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  276. Sorry! netdata failed to build...
  277. You may need to check these:
  278. 1. The package uuid-dev (or libuuid-devel) has to be installed.
  279. If your system cannot find libuuid, although it is installed
  280. run me with the option: --libs-are-really-here
  281. 2. The package zlib1g-dev (or zlib-devel) has to be installed.
  282. If your system cannot find zlib, although it is installed
  283. run me with the option: --libs-are-really-here
  284. 3. You need basic build tools installed, like:
  285. gcc make autoconf automake pkg-config
  286. Autoconf version 2.60 or higher is required.
  287. If you still cannot get it to build, ask for help at github:
  288. https://github.com/netdata/netdata/issues
  289. EOF
  290. trap - EXIT
  291. exit 1
  292. }
  293. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  294. shift
  295. echo >&2 "ok, assuming libs are really installed."
  296. export ZLIB_CFLAGS=" "
  297. export ZLIB_LIBS="-lz"
  298. export UUID_CFLAGS=" "
  299. export UUID_LIBS="-luuid"
  300. fi
  301. trap build_error EXIT
  302. # -----------------------------------------------------------------------------
  303. echo >&2
  304. progress "Run autotools to configure the build environment"
  305. if [ "$have_autotools" ]; then
  306. run autoreconf -ivf || exit 1
  307. fi
  308. run ./configure \
  309. --prefix="${NETDATA_PREFIX}/usr" \
  310. --sysconfdir="${NETDATA_PREFIX}/etc" \
  311. --localstatedir="${NETDATA_PREFIX}/var" \
  312. --libexecdir="${NETDATA_PREFIX}/usr/libexec" \
  313. --with-zlib \
  314. --with-math \
  315. --with-user=netdata \
  316. ${NETDATA_CONFIGURE_OPTIONS} \
  317. CFLAGS="${CFLAGS}" || exit 1
  318. # remove the build_error hook
  319. trap - EXIT
  320. # -----------------------------------------------------------------------------
  321. progress "Cleanup compilation directory"
  322. run make clean
  323. # -----------------------------------------------------------------------------
  324. progress "Compile netdata"
  325. run make -j$(find_processors) || exit 1
  326. # -----------------------------------------------------------------------------
  327. progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
  328. # migrate existing configuration files
  329. # for node.d and charts.d
  330. if [ -d "${NETDATA_PREFIX}/etc/netdata" ]; then
  331. # the configuration directory exists
  332. if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]; then
  333. run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
  334. fi
  335. # move the charts.d config files
  336. for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat; do
  337. for y in "" ".old" ".orig"; do
  338. if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]; then
  339. run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
  340. fi
  341. done
  342. done
  343. if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]; then
  344. run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
  345. fi
  346. # move the node.d config files
  347. for x in named sma_webbox snmp; do
  348. for y in "" ".old" ".orig"; do
  349. if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]; then
  350. run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
  351. fi
  352. done
  353. done
  354. fi
  355. # -----------------------------------------------------------------------------
  356. # shellcheck disable=SC2230
  357. md5sum="$(command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)"
  358. deleted_stock_configs=0
  359. if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" ]; then
  360. progress "Backup existing netdata configuration before installing it"
  361. if [ "${BASH_VERSINFO[0]}" -ge "4" ]; then
  362. declare -A configs_signatures=()
  363. if [ -f "configs.signatures" ]; then
  364. source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
  365. fi
  366. fi
  367. config_signature_matches() {
  368. local md5="${1}" file="${2}"
  369. if [ "${BASH_VERSINFO[0]}" -ge "4" ]; then
  370. [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0
  371. return 1
  372. fi
  373. if [ -f "configs.signatures" ]; then
  374. grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null
  375. return $?
  376. fi
  377. return 1
  378. }
  379. # clean up stock config files from the user configuration directory
  380. for x in $(find -L "${NETDATA_PREFIX}/etc/netdata" -type f -not -path '*/\.*' -not -path "${NETDATA_PREFIX}/etc/netdata/orig/*" \( -name '*.conf.old' -o -name '*.conf' -o -name '*.conf.orig' -o -name '*.conf.installer_backup.*' \)); do
  381. if [ -f "${x}" ]; then
  382. # find it relative filename
  383. f="${x/${NETDATA_PREFIX}\/etc\/netdata\//}"
  384. # find the stock filename
  385. t="${f/.conf.installer_backup.*/.conf}"
  386. t="${t/.conf.old/.conf}"
  387. t="${t/.conf.orig/.conf}"
  388. t="${t/orig\//}"
  389. if [ -z "${md5sum}" -o ! -x "${md5sum}" ]; then
  390. # we don't have md5sum - keep it
  391. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
  392. else
  393. # find its checksum
  394. md5="$(${md5sum} <"${x}" | cut -d ' ' -f 1)"
  395. if config_signature_matches "${md5}" "${t}"; then
  396. # it is a stock version - remove it
  397. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version of '${t}'."
  398. run rm -f "${x}"
  399. deleted_stock_configs=$((deleted_stock_configs + 1))
  400. else
  401. # edited by user - keep it
  402. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} does not match stock of${TPUT_RESET} ${TPUT_CYAN}'${t}'${TPUT_RESET}. Keeping it."
  403. fi
  404. fi
  405. fi
  406. done
  407. fi
  408. touch "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done"
  409. # -----------------------------------------------------------------------------
  410. progress "Install netdata"
  411. run make install || exit 1
  412. # -----------------------------------------------------------------------------
  413. progress "Fix generated files permissions"
  414. run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
  415. # -----------------------------------------------------------------------------
  416. progress "Creating standard user and groups for netdata"
  417. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  418. NETDATA_ADDED_TO_GROUPS=""
  419. if [ "${UID}" -eq 0 ]; then
  420. progress "Adding group 'netdata'"
  421. portable_add_group netdata || :
  422. progress "Adding user 'netdata'"
  423. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  424. progress "Assign user 'netdata' to required groups"
  425. for g in ${NETDATA_WANTED_GROUPS}; do
  426. # shellcheck disable=SC2086
  427. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  428. done
  429. else
  430. run_failed "The installer does not run as root. Nothing to do for user and groups"
  431. fi
  432. # -----------------------------------------------------------------------------
  433. progress "Install logrotate configuration for netdata"
  434. install_netdata_logrotate
  435. # -----------------------------------------------------------------------------
  436. progress "Read installation options from netdata.conf"
  437. # create an empty config if it does not exist
  438. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  439. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  440. # function to extract values from the config file
  441. config_option() {
  442. local section="${1}" key="${2}" value="${3}"
  443. if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  444. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  445. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  446. -W get "${section}" "${key}" "${value}" ||
  447. echo "${value}"
  448. else
  449. echo "${value}"
  450. fi
  451. }
  452. # the user netdata will run as
  453. if [ "${UID}" = "0" ]; then
  454. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  455. ROOT_USER="root"
  456. else
  457. NETDATA_USER="${USER}"
  458. ROOT_USER="${NETDATA_USER}"
  459. fi
  460. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}")"
  461. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  462. echo >&2 "Netdata user and group is finally set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  463. # the owners of the web files
  464. NETDATA_WEB_USER="$(config_option "web" "web files owner" "${NETDATA_USER}")"
  465. NETDATA_WEB_GROUP="${NETDATA_GROUP}"
  466. if [ "${UID}" = "0" ] && [ "${NETDATA_USER}" != "${NETDATA_WEB_USER}" ]; then
  467. NETDATA_WEB_GROUP="$(id -g -n "${NETDATA_WEB_USER}")"
  468. [ -z "${NETDATA_WEB_GROUP}" ] && NETDATA_WEB_GROUP="${NETDATA_WEB_USER}"
  469. fi
  470. NETDATA_WEB_GROUP="$(config_option "web" "web files group" "${NETDATA_WEB_GROUP}")"
  471. # port
  472. defport=19999
  473. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  474. # directories
  475. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  476. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  477. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  478. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  479. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  480. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  481. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  482. cat <<OPTIONSEOF
  483. Permissions
  484. - netdata user : ${NETDATA_USER}
  485. - netdata group : ${NETDATA_GROUP}
  486. - web files user : ${NETDATA_WEB_USER}
  487. - web files group : ${NETDATA_WEB_GROUP}
  488. - root user : ${ROOT_USER}
  489. Directories
  490. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  491. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  492. - netdata log dir : ${NETDATA_LOG_DIR}
  493. - netdata run dir : ${NETDATA_RUN_DIR}
  494. - netdata lib dir : ${NETDATA_LIB_DIR}
  495. - netdata web dir : ${NETDATA_WEB_DIR}
  496. - netdata cache dir : ${NETDATA_CACHE_DIR}
  497. Other
  498. - netdata port : ${NETDATA_PORT}
  499. OPTIONSEOF
  500. # -----------------------------------------------------------------------------
  501. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  502. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  503. # this is needed if NETDATA_PREFIX is not empty
  504. run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
  505. fi
  506. # --- conf dir ----
  507. for x in "python.d" "charts.d" "node.d" "health.d" "statsd.d" "go.d" "custom-plugins.d" "ssl"; do
  508. if [ ! -d "${NETDATA_USER_CONFIG_DIR}/${x}" ]; then
  509. echo >&2 "Creating directory '${NETDATA_USER_CONFIG_DIR}/${x}'"
  510. run mkdir -p "${NETDATA_USER_CONFIG_DIR}/${x}" || exit 1
  511. fi
  512. done
  513. run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_USER_CONFIG_DIR}"
  514. run find "${NETDATA_USER_CONFIG_DIR}" -type f -exec chmod 0640 {} \;
  515. run find "${NETDATA_USER_CONFIG_DIR}" -type d -exec chmod 0755 {} \;
  516. run chmod 755 "${NETDATA_USER_CONFIG_DIR}/edit-config"
  517. # --- stock conf dir ----
  518. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  519. helplink="000.-.USE.THE.orig.LINK.TO.COPY.AND.EDIT.STOCK.CONFIG.FILES"
  520. [ ${deleted_stock_configs} -eq 0 ] && helplink=""
  521. for link in "orig" "${helplink}"; do
  522. if [ ! -z "${link}" ]; then
  523. [ -L "${NETDATA_USER_CONFIG_DIR}/${link}" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/${link}"
  524. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/${link}"
  525. fi
  526. done
  527. run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
  528. run find "${NETDATA_STOCK_CONFIG_DIR}" -type f -exec chmod 0640 {} \;
  529. run find "${NETDATA_STOCK_CONFIG_DIR}" -type d -exec chmod 0755 {} \;
  530. # --- web dir ----
  531. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  532. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  533. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  534. fi
  535. run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
  536. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  537. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  538. # --- data dirs ----
  539. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  540. if [ ! -d "${x}" ]; then
  541. echo >&2 "Creating directory '${x}'"
  542. run mkdir -p "${x}" || exit 1
  543. fi
  544. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  545. #run find "${x}" -type f -exec chmod 0660 {} \;
  546. #run find "${x}" -type d -exec chmod 0770 {} \;
  547. done
  548. run chmod 755 "${NETDATA_LOG_DIR}"
  549. # --- plugins ----
  550. if [ "${UID}" -eq 0 ]; then
  551. # find the admin group
  552. admin_group=
  553. test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root"
  554. test -z "${admin_group}" && getent group daemon >/dev/null 2>&1 && admin_group="daemon"
  555. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  556. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  557. run chown -R "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  558. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  559. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  560. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  561. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  562. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  563. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  564. capabilities=0
  565. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  566. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  567. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  568. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  569. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1 && capabilities=1 || capabilities=0
  570. fi
  571. fi
  572. if [ $capabilities -eq 0 ]; then
  573. # fix apps.plugin to be setuid to root
  574. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  575. fi
  576. fi
  577. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  578. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  579. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  580. fi
  581. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  582. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  583. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  584. fi
  585. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  586. run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  587. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  588. fi
  589. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  590. run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  591. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  592. fi
  593. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  594. run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  595. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  596. fi
  597. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  598. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  599. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  600. fi
  601. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  602. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  603. run chmod 0550 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  604. fi
  605. else
  606. # non-privileged user installation
  607. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  608. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  609. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  610. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  611. fi
  612. # -----------------------------------------------------------------------------
  613. install_go() {
  614. # When updating this value, ensure correct checksums in packaging/go.d.checksums
  615. GO_PACKAGE_VERSION="v0.7.0"
  616. ARCH_MAP=(
  617. 'i386::386'
  618. 'i686::386'
  619. 'x86_64::amd64'
  620. 'aarch64::arm64'
  621. 'armv64::arm64'
  622. 'armv6l::arm'
  623. 'armv7l::arm'
  624. 'armv5tel::arm'
  625. )
  626. if [ -z "${NETDATA_DISABLE_GO+x}" ]; then
  627. progress "Install go.d.plugin"
  628. ARCH=$(uname -m)
  629. OS=$(uname -s | tr '[:upper:]' '[:lower:]')
  630. for index in "${ARCH_MAP[@]}" ; do
  631. KEY="${index%%::*}"
  632. VALUE="${index##*::}"
  633. if [ "$KEY" = "$ARCH" ]; then
  634. ARCH="${VALUE}"
  635. break
  636. fi
  637. done
  638. tmp=$(mktemp -d /tmp/netdata-go-XXXXXX)
  639. GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}"
  640. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
  641. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
  642. if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
  643. run_failed "go.d plugin download failed, go.d plugin will not be available"
  644. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  645. echo >&2
  646. return 0
  647. fi
  648. grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2>/dev/null
  649. grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2>/dev/null
  650. # Checksum validation
  651. if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
  652. echo >&2 "go.d plugin checksum validation failure."
  653. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  654. echo >&2
  655. run_failed "go.d.plugin package files checksum validation failed."
  656. return 0
  657. fi
  658. # Install new files
  659. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
  660. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
  661. run tar -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
  662. run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
  663. run mv "${tmp}/$GO_PACKAGE_BASENAME" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  664. if [ "${UID}" -eq 0 ]; then
  665. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  666. fi
  667. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  668. fi
  669. return 0
  670. }
  671. install_go
  672. # -----------------------------------------------------------------------------
  673. progress "Telemetry configuration"
  674. # Opt-out from telemetry program
  675. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  676. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  677. else
  678. printf "You can opt out from anonymous statistics via the --disable-telemetry option, or by creating an empty file ${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics \n\n"
  679. fi
  680. # -----------------------------------------------------------------------------
  681. progress "Install netdata at system init"
  682. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  683. if grep -q docker /proc/1/cgroup >/dev/null 2>&1; then
  684. echo >&2 "We are running within a docker container, will not be installing netdata service"
  685. echo >&2
  686. else
  687. install_netdata_service || run_failed "Cannot install netdata init service."
  688. fi
  689. # -----------------------------------------------------------------------------
  690. # check if we can re-start netdata
  691. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  692. started=0
  693. if [ ${DONOTSTART} -eq 1 ]; then
  694. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  695. else
  696. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  697. fatal "Cannot start netdata!"
  698. fi
  699. started=1
  700. run_ok "netdata started!"
  701. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  702. fi
  703. if [ "${UID}" -eq 0 ]; then
  704. run chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  705. fi
  706. run chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  707. if [ "$(uname)" = "Linux" ]; then
  708. # -------------------------------------------------------------------------
  709. progress "Check KSM (kernel memory deduper)"
  710. ksm_is_available_but_disabled() {
  711. cat <<KSM1
  712. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  713. You have kernel memory de-duper (called Kernel Same-page Merging,
  714. or KSM) available, but it is not currently enabled.
  715. To enable it run:
  716. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  717. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  718. If you enable it, you will save 40-60% of netdata memory.
  719. KSM1
  720. }
  721. ksm_is_not_available() {
  722. cat <<KSM2
  723. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  724. It seems you do not have kernel memory de-duper (called Kernel Same-page
  725. Merging, or KSM) available.
  726. To enable it, you need a kernel built with CONFIG_KSM=y
  727. If you can have it, you will save 40-60% of netdata memory.
  728. KSM2
  729. }
  730. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  731. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  732. ksm_is_available_but_disabled
  733. fi
  734. else
  735. ksm_is_not_available
  736. fi
  737. fi
  738. # -----------------------------------------------------------------------------
  739. progress "Check version.txt"
  740. if [ ! -s web/gui/version.txt ]; then
  741. cat <<VERMSG
  742. ${TPUT_BOLD}Version update check warning${TPUT_RESET}
  743. The way you downloaded netdata, we cannot find its version. This means the
  744. Update check on the dashboard, will not work.
  745. If you want to have version update check, please re-install it
  746. following the procedure in:
  747. https://docs.netdata.cloud/packaging/installer/
  748. VERMSG
  749. fi
  750. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  751. # -----------------------------------------------------------------------------
  752. progress "Check apps.plugin"
  753. if [ "${UID}" -ne 0 ]; then
  754. cat <<SETUID_WARNING
  755. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  756. Since you have installed netdata as a normal user, to have apps.plugin collect
  757. all the needed data, you have to give it the access rights it needs, by running
  758. either of the following sets of commands:
  759. To run apps.plugin with escalated capabilities:
  760. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
  761. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
  762. ${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}
  763. or, to run apps.plugin as root:
  764. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
  765. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
  766. apps.plugin is performing a hard-coded function of data collection for all
  767. running processes. It cannot be instructed from the netdata daemon to perform
  768. any task, so it is pretty safe to do this.
  769. SETUID_WARNING
  770. fi
  771. fi
  772. # -----------------------------------------------------------------------------
  773. progress "Copy uninstaller"
  774. sed "s|ENVIRONMENT_FILE=\"/etc/netdata/.environment\"|ENVIRONMENT_FILE=\"${NETDATA_PREFIX}/etc/netdata/.environment\"|" packaging/installer/netdata-uninstaller.sh > ${NETDATA_PREFIX}/usr/libexec/netdata-uninstaller.sh
  775. chmod 750 ${NETDATA_PREFIX}/usr/libexec/netdata-uninstaller.sh
  776. # -----------------------------------------------------------------------------
  777. progress "Basic netdata instructions"
  778. cat <<END
  779. netdata by default listens on all IPs on port ${NETDATA_PORT},
  780. so you can access it with:
  781. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  782. To stop netdata run:
  783. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  784. To start netdata run:
  785. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  786. END
  787. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata-uninstaller.sh${TPUT_RESET}"
  788. echo >&2
  789. progress "Install netdata updater tool"
  790. if [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
  791. sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" || exit 1
  792. else
  793. sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" || exit 1
  794. fi
  795. chmod 0755 ${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh
  796. echo >&2 "Update script is located at ${TPUT_GREEN}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh${TPUT_RESET}"
  797. echo >&2
  798. # Figure out the cron directory for the distro
  799. crondir=
  800. [ -d "/etc/periodic/daily" ] && crondir="/etc/periodic/daily"
  801. [ -d "/etc/cron.daily" ] && crondir="/etc/cron.daily"
  802. if [ -z "${crondir}" ]; then
  803. echo >&2 "Cannot figure out the cron directory to handle netdata-updater.sh activation/deactivation"
  804. elif [ "${UID}" -ne "0" ]; then
  805. # We cant touch cron if we are not running as root
  806. echo >&2 "You need to run the installer as root for auto-updating via cron."
  807. else
  808. progress "Check if we must enable/disable the netdata updater"
  809. if [ "${AUTOUPDATE}" = "1" ]; then
  810. if [ -f "${crondir}/netdata-updater.sh" ]; then
  811. progress "Removing incorrect netdata-updater filename in cron"
  812. rm -f "${crondir}/netdata-updater.sh"
  813. fi
  814. echo >&2 "Adding to cron"
  815. rm -f "${crondir}/netdata-updater"
  816. ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata-updater.sh" "${crondir}/netdata-updater"
  817. echo >&2 "Auto-updating has been enabled. Updater script linked to: ${TPUT_RED}${TPUT_BOLD}${crondir}/netdata-update${TPUT_RESET}"
  818. echo >&2
  819. echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} works from cron. It will trigger an email from cron"
  820. echo >&2 "only if it fails (it should not print anything when it can update netdata).${TPUT_RESET}"
  821. else
  822. echo >&2 "You chose *NOT* to enable auto-update, removing any links to the updater from cron (it may have happened if you are reinstalling)"
  823. echo >&2
  824. if [ -f "${crondir}/netdata-updater" ]; then
  825. echo >&2 "Removing cron reference: ${crondir}/netdata-updater"
  826. rm -f "${crondir}/netdata-updater"
  827. else
  828. echo >&2 "Did not find any cron entries to remove"
  829. fi
  830. fi
  831. fi
  832. # Save environment variables
  833. cat <<EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  834. # Created by installer
  835. PATH="${PATH}"
  836. CFLAGS="${CFLAGS}"
  837. NETDATA_PREFIX="${NETDATA_PREFIX}"
  838. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
  839. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  840. INSTALL_UID="${UID}"
  841. NETDATA_GROUP="${NETDATA_GROUP}"
  842. REINSTALL_COMMAND="${REINSTALL_COMMAND}"
  843. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  844. # This value is meant to be populated by autoupdater (if enabled)
  845. NETDATA_TARBALL_CHECKSUM="new_installation"
  846. EOF
  847. # -----------------------------------------------------------------------------
  848. echo >&2
  849. progress "We are done!"
  850. if [ ${started} -eq 1 ]; then
  851. netdata_banner "is installed and running now!"
  852. else
  853. netdata_banner "is installed now!"
  854. fi
  855. echo >&2 " enjoy real-time performance and health monitoring..."
  856. echo >&2
  857. exit 0