netdata-installer.sh 40 KB

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