3 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
5 netdata_source_dir="$(pwd)"
6 installer_dir="$(dirname "${0}")"
8 if [ "${netdata_source_dir}" != "${installer_dir}" -a "${installer_dir}" != "." ]
10 echo >&2 "Warninng: you are currently in '${netdata_source_dir}' but the installer is in '${installer_dir}'."
14 # -----------------------------------------------------------------------------
15 # reload the user profile
17 [ -f /etc/profile ] && . /etc/profile
19 # make sure /etc/profile does not change our current directory
20 cd "${netdata_source_dir}" || exit 1
23 # -----------------------------------------------------------------------------
24 # load the required functions
26 if [ -f "${installer_dir}/installer/functions.sh" ]
28 source "${installer_dir}/installer/functions.sh" || exit 1
30 source "${netdata_source_dir}/installer/functions.sh" || exit 1
33 # make sure we save all commands we run
34 run_logfile="netdata-installer.log"
37 # -----------------------------------------------------------------------------
38 # fix PKG_CHECK_MODULES error
40 if [ -d /usr/share/aclocal ]
42 ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
49 # Be nice on production environments
50 renice 19 $$ >/dev/null 2>/dev/null
52 processors=$(cat /proc/cpuinfo 2>/dev/null | grep ^processor | wc -l)
53 [ $(( processors )) -lt 1 ] && processors=1
55 # you can set CFLAGS before running installer
56 CFLAGS="${CFLAGS--O2}"
57 [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
59 # keep a log of this command
60 printf "\n# " >>netdata-installer.log
61 date >>netdata-installer.log
62 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
63 printf "%q " "$0" "${@}" >>netdata-installer.log
64 printf "\n" >>netdata-installer.log
66 REINSTALL_PWD="${PWD}"
67 REINSTALL_COMMAND="$(printf "%q " "$0" "${@}"; printf "\n")"
69 setcap="$(which setcap 2>/dev/null || command -v setcap 2>/dev/null)"
76 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
79 netdata_banner "installer command line options"
82 ${ME} <installer options>
84 Valid <installer options> are:
86 --install /PATH/TO/INSTALL
88 If you give: --install /opt
89 netdata will be installed in /opt/netdata
93 Do not (re)start netdata.
98 Do not wait for the user to press ENTER.
99 Start immediately building it.
101 --enable-plugin-freeipmi
102 --disable-plugin-freeipmi
104 Enable/disable the FreeIPMI plugin.
105 Default: enable it when libipmimonitoring is available.
110 Enable/disable Link-Time-Optimization
113 --zlib-is-really-here
114 --libs-are-really-here
116 If you get errors about missing zlib,
117 or libuuid but you know it is available,
118 you have a broken pkg-config.
119 Use this option to allow it continue
120 without checking pkg-config.
122 Netdata will by default be compiled with gcc optimization -O2
123 If you need to pass different CFLAGS, use something like this:
125 CFLAGS="<gcc options>" ${ME} <installer options>
127 For the installer to complete successfully, you will need
128 these packages installed:
130 gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
131 uuid-dev (or libuuid-devel)
133 For the plugins, you will at least need:
140 md5sum="$(which md5sum 2>/dev/null || command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)"
141 get_git_config_signatures() {
144 [ ! -d "conf.d" ] && echo >&2 "Wrong directory." && return 1
145 [ -z "${md5sum}" -o ! -x "${md5sum}" ] && echo >&2 "No md5sum command." && return 1
147 echo >configs.signatures.tmp
149 for x in $(find conf.d -name \*.conf)
153 for c in $(git log --follow "conf.d/${x}" | grep ^commit | cut -d ' ' -f 2)
155 git checkout ${c} "conf.d/${x}" || continue
156 s="$(cat "conf.d/${x}" | ${md5sum} | cut -d ' ' -f 1)"
157 echo >>configs.signatures.tmp "${s}:${x}"
160 git checkout HEAD "conf.d/${x}" || break
163 cat configs.signatures.tmp |\
167 echo "declare -A configs_signatures=("
171 echo " ['${md5}']='${file}'"
174 } >configs.signatures
176 rm configs.signatures.tmp
182 while [ ! -z "${1}" ]
184 if [ "$1" = "--install" ]
186 NETDATA_PREFIX="${2}/netdata"
188 elif [ "$1" = "--zlib-is-really-here" -o "$1" = "--libs-are-really-here" ]
192 elif [ "$1" = "--dont-start-it" ]
196 elif [ "$1" = "--dont-wait" ]
200 elif [ "$1" = "--enable-plugin-freeipmi" ]
202 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-plugin-freeipmi"
204 elif [ "$1" = "--disable-plugin-freeipmi" ]
206 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-plugin-freeipmi"
208 elif [ "$1" = "--enable-lto" ]
210 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-lto"
212 elif [ "$1" = "--disable-lto" ]
214 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-lto"
216 elif [ "$1" = "--help" -o "$1" = "-h" ]
220 elif [ "$1" = "get_git_config_signatures" ]
222 get_git_config_signatures && exit 0
227 echo >&2 "I cannot understand option '$1'."
233 netdata_banner "real-time performance monitoring, done right!"
236 You are about to build and install netdata to your system.
238 It will be installed at these locations:
240 - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
241 - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
242 - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
243 - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
244 - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
245 - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
246 - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
249 [ "${UID}" -eq 0 ] && cat <<BANNER2
250 - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
251 - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
256 This installer allows you to change the installation path.
257 Press Control-C and run the same command with --help for help.
261 if [ "${UID}" -ne 0 ]
263 if [ -z "${NETDATA_PREFIX}" ]
265 netdata_banner "wrong command line options!"
266 cat <<NONROOTNOPREFIX
268 ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
270 You are attempting to install netdata as non-root, but you plan
271 to install it in system paths.
273 Please set an installation prefix, like this:
275 $0 ${@} --install /tmp
277 or, run the installer as root:
281 We suggest to install it as root, or certain data collectors will
282 not be able to work. Netdata drops root privileges when running.
283 So, if you plan to keep it, install it as root to get the full
292 ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
293 You are about to install netdata as a non-root user.
294 Netdata will work, but a few data collection modules that
295 require root access will fail.
297 If you installing netdata permanently on your system, run
298 the installer like this:
300 ${TPUT_YELLOW}${TPUT_BOLD}sudo $0 ${@}${TPUT_RESET}
307 if [ "$(type autoreconf 2> /dev/null)" ]
315 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
316 eval $maj=\$1 $min=\$2
318 autoconf_maj_min AMAJ AMIN
323 elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
327 echo "Found autotools $AMAJ.$AMIN"
330 echo "No autotools found"
333 if [ ! "$have_autotools" ]
337 echo "Will skip autoreconf step"
339 netdata_banner "autotools v2.60 required"
342 -------------------------------------------------------------------------------
343 autotools 2.60 or later is required
345 Sorry, you do not seem to have autotools 2.60 or later, which is
346 required to build from the git sources of netdata.
348 You can either install a suitable version of autotools and automake
349 or download a netdata package which does not have these dependencies.
351 Source packages where autotools have already been run are available
353 https://firehol.org/download/netdata/
355 The unsigned/master folder tracks the head of the git tree and released
356 packages are also available.
362 if [ ${DONOTWAIT} -eq 0 ]
364 if [ ! -z "${NETDATA_PREFIX}" ]
366 eval "read >&2 -ep \$'\001${TPUT_BOLD}${TPUT_GREEN}\002Press ENTER to build and install netdata to \'\001${TPUT_CYAN}\002${NETDATA_PREFIX}\001${TPUT_YELLOW}\002\'\001${TPUT_RESET}\002 > ' -e -r REPLY"
368 eval "read >&2 -ep \$'\001${TPUT_BOLD}${TPUT_GREEN}\002Press ENTER to build and install netdata to your system\001${TPUT_RESET}\002 > ' -e -r REPLY"
373 netdata_banner "sorry, it failed to build..."
376 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
378 Sorry! netdata failed to build...
380 You many need to check these:
382 1. The package uuid-dev (or libuuid-devel) has to be installed.
384 If your system cannot find libuuid, although it is installed
385 run me with the option: --libs-are-really-here
387 2. The package zlib1g-dev (or zlib-devel) has to be installed.
389 If your system cannot find zlib, although it is installed
390 run me with the option: --libs-are-really-here
392 3. You need basic build tools installed, like:
394 gcc make autoconf automake pkg-config
396 Autoconf version 2.60 or higher is required.
398 If you still cannot get it to build, ask for help at github:
400 https://github.com/firehol/netdata/issues
408 if [ ${LIBS_ARE_HERE} -eq 1 ]
411 echo >&2 "ok, assuming libs are really installed."
412 export ZLIB_CFLAGS=" "
413 export ZLIB_LIBS="-lz"
414 export UUID_CFLAGS=" "
415 export UUID_LIBS="-luuid"
418 trap build_error EXIT
421 # -----------------------------------------------------------------------------
423 progress "Run autotools to configure the build environment"
425 if [ "$have_autotools" ]
427 run ./autogen.sh || exit 1
431 --prefix="${NETDATA_PREFIX}/usr" \
432 --sysconfdir="${NETDATA_PREFIX}/etc" \
433 --localstatedir="${NETDATA_PREFIX}/var" \
436 --with-user=netdata \
437 ${NETDATA_CONFIGURE_OPTIONS} \
438 CFLAGS="${CFLAGS}" || exit 1
440 # remove the build_error hook
443 # -----------------------------------------------------------------------------
444 progress "Cleanup compilation directory"
446 [ -f src/netdata ] && run make clean
448 # -----------------------------------------------------------------------------
449 progress "Compile netdata"
451 run make -j${processors} || exit 1
454 # -----------------------------------------------------------------------------
455 progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
457 # migrate existing configuration files
458 # for node.d and charts.d
459 if [ -d "${NETDATA_PREFIX}/etc/netdata" ]
461 # the configuration directory exists
463 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]
465 run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
468 # move the charts.d config files
469 for x in apache ap cpu_apps cpufreq example exim hddtemp load_average mem_apps mysql nginx nut opensips phpfpm postfix sensors squid tomcat
471 for y in "" ".old" ".orig"
473 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]
475 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
480 if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]
482 run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
485 # move the node.d config files
486 for x in named sma_webbox snmp
488 for y in "" ".old" ".orig"
490 if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]
492 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
498 # -----------------------------------------------------------------------------
499 progress "Backup existing netdata configuration before installing it"
501 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
503 declare -A configs_signatures=()
504 if [ -f "configs.signatures" ]
506 source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
510 # backup user configurations
511 installer_backup_suffix="${PID}.${RANDOM}"
512 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
516 # make a backup of the configuration file
517 cp -p "${x}" "${x}.old"
519 if [ -z "${md5sum}" -o ! -x "${md5sum}" ]
521 # we don't have md5sum - keep it
522 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
523 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
525 # find it relative filename
526 f="${x/*\/etc\/netdata\//}"
529 md5="$(cat "${x}" | ${md5sum} | cut -d ' ' -f 1)"
532 if [ -f "conf.d/${f}" ]
534 cp "conf.d/${f}" "${x}.orig"
537 if [ "${BASH_VERSINFO[0]}" -ge "4" ]
539 if [ "${configs_signatures[${md5}]}" = "${f}" ]
541 # it is a stock version - don't keep it
542 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version."
544 # edited by user - keep it
545 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} has been edited by user${TPUT_RESET}. Keeping it."
546 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
549 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}cannot be checked for custom edits${TPUT_RESET}. Keeping it."
550 run cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
554 elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
556 rm -f "${x}.installer_backup.${installer_backup_suffix}"
561 # -----------------------------------------------------------------------------
562 progress "Install netdata"
564 run make install || exit 1
567 # -----------------------------------------------------------------------------
568 progress "Restore user edited netdata configuration files"
570 for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
572 if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
574 run cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}" && \
575 run rm -f "${x}.installer_backup.${installer_backup_suffix}"
580 # -----------------------------------------------------------------------------
581 progress "Fix generated files permissions"
583 run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
586 # -----------------------------------------------------------------------------
587 progress "Add user netdata to required user groups"
589 NETDATA_ADDED_TO_DOCKER=0
590 NETDATA_ADDED_TO_NGINX=0
591 NETDATA_ADDED_TO_VARNISH=0
592 NETDATA_ADDED_TO_HAPROXY=0
593 NETDATA_ADDED_TO_ADM=0
594 NETDATA_ADDED_TO_NSD=0
597 portable_add_group netdata
598 portable_add_user netdata
599 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
600 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
601 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
602 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
603 portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
604 portable_add_user_to_group nsd netdata && NETDATA_ADDED_TO_NSD=1
607 run_failed "The installer does not run as root."
610 # -----------------------------------------------------------------------------
611 progress "Install logrotate configuration for netdata"
615 if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
617 run cp system/netdata.logrotate /etc/logrotate.d/netdata
620 if [ -f /etc/logrotate.d/netdata ]
622 run chmod 644 /etc/logrotate.d/netdata
627 # -----------------------------------------------------------------------------
628 progress "Read installation options from netdata.conf"
630 # create an empty config if it does not exist
631 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && \
632 touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
634 # function to extract values from the config file
636 local key="${1}" value="${2}" line=
638 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
640 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
641 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
647 # the user netdata will run as
648 if [ "${UID}" = "0" ]
650 NETDATA_USER="$( config_option "run as user" "netdata" )"
652 NETDATA_USER="${USER}"
655 # the owners of the web files
656 NETDATA_WEB_USER="$( config_option "web files owner" "${NETDATA_USER}" )"
657 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
660 NETDATA_DEBUG="$( config_option "debug flags" 0 )"
664 NETDATA_PORT="$( config_option "default port" ${defport} )"
665 NETDATA_PORT2="$( config_option "port" ${defport} )"
667 if [ "${NETDATA_PORT}" != "${NETDATA_PORT2}" ]
669 if [ "${NETDATA_PORT2}" != "${defport}" ]
671 NETDATA_PORT="${NETDATA_PORT2}"
676 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
677 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
678 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
679 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
680 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
681 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
684 # -----------------------------------------------------------------------------
685 progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
687 if [ ! -d "${NETDATA_RUN_DIR}" ]
689 # this is needed if NETDATA_PREFIX is not empty
690 run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
695 for x in "python.d" "charts.d" "node.d"
697 if [ ! -d "${NETDATA_CONF_DIR}/${x}" ]
699 echo >&2 "Creating directory '${NETDATA_CONF_DIR}/${x}'"
700 run mkdir -p "${NETDATA_CONF_DIR}/${x}" || exit 1
703 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_CONF_DIR}"
704 run find "${NETDATA_CONF_DIR}" -type f -exec chmod 0660 {} \;
705 run find "${NETDATA_CONF_DIR}" -type d -exec chmod 0775 {} \;
709 if [ ! -d "${NETDATA_WEB_DIR}" ]
711 echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
712 run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
714 run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
715 run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
716 run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
720 for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
724 echo >&2 "Creating directory '${x}'"
725 run mkdir -p "${x}" || exit 1
728 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}"
729 #run find "${x}" -type f -exec chmod 0660 {} \;
730 #run find "${x}" -type d -exec chmod 0770 {} \;
733 run chmod 755 "${NETDATA_LOG_DIR}"
739 # find the admin group
741 test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root"
742 test -z "${admin_group}" && getent group daemon >/dev/null 2>&1 && admin_group="daemon"
743 test -z "${admin_group}" && admin_group="${NETDATA_USER}"
745 run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
746 run chown -R root "${NETDATA_PREFIX}/usr/libexec/netdata"
747 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
748 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
749 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0755 {} \;
750 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
755 if [ ! -z "${setcap}" ]
757 run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
761 if [ ${setcap_ret} -eq 0 ]
763 # if we managed to setcap
764 # but we fail to execute apps.plugin
765 # trigger setuid to root
766 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1
771 if [ ${setcap_ret} -ne 0 ]
773 # fix apps.plugin to be setuid to root
774 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
775 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
778 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]
780 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
781 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
785 run chown "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_LOG_DIR}"
786 run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${NETDATA_PREFIX}/usr/libexec/netdata"
787 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
788 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
791 # --- fix #1292 bug ---
793 [ -d "${NETDATA_PREFIX}/usr/libexec" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/libexec"
794 [ -d "${NETDATA_PREFIX}/usr/share/netdata" ] && run chmod a+rX "${NETDATA_PREFIX}/usr/share/netdata"
798 # -----------------------------------------------------------------------------
799 progress "Install netdata at system init"
802 install_non_systemd_init() {
803 [ "${UID}" != 0 ] && return 1
806 if [ -f /etc/os-release ]
808 source /etc/os-release || return 1
809 key="${ID}-${VERSION_ID}"
811 elif [ -f /etc/centos-release ]
813 key=$(</etc/centos-release)
816 if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
818 if [ "${key}" = "gentoo" ]
820 run cp system/netdata-openrc /etc/init.d/netdata && \
821 run chmod 755 /etc/init.d/netdata && \
822 run rc-update add netdata default && \
825 elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
827 run cp system/netdata-lsb /etc/init.d/netdata && \
828 run chmod 755 /etc/init.d/netdata && \
829 run update-rc.d netdata defaults && \
830 run update-rc.d netdata enable && \
833 elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
835 run cp system/netdata-init-d /etc/init.d/netdata && \
836 run chmod 755 /etc/init.d/netdata && \
837 run chkconfig netdata on && \
845 if [ "${UID}" -eq 0 ]
850 # systemd is running on this system
852 if [ ! -f /etc/systemd/system/netdata.service ]
854 echo >&2 "Installing systemd service..."
855 run cp system/netdata.service /etc/systemd/system/netdata.service && \
856 run systemctl daemon-reload && \
857 run systemctl enable netdata
860 install_non_systemd_init
865 # -----------------------------------------------------------------------------
866 # check if we can re-start netdata
873 [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
874 [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
880 stop_netdata_on_pid() {
881 local pid="${1}" ret=0 count=0
883 isnetdata ${pid} || return 0
885 printf >&2 "Stopping netdata on pid ${pid} ..."
886 while [ ! -z "$pid" -a ${ret} -eq 0 ]
888 if [ ${count} -gt 45 ]
890 echo >&2 "Cannot stop the running netdata on pid ${pid}."
894 count=$(( count + 1 ))
896 run kill ${pid} 2>/dev/null
899 test ${ret} -eq 0 && printf >&2 "." && sleep 2
905 echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
909 echo >&2 "netdata on pid ${pid} stopped."
916 myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
918 # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
920 for p in $(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null) \
921 $(cat /var/run/netdata.pid 2>/dev/null) \
922 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
923 $(pidof netdata 2>/dev/null)
925 ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
927 if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
929 stop_netdata_on_pid ${p}
934 if [ ${DONOTSTART} -eq 1 ]
936 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
938 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
940 if [ "${UID}" -eq 0 ]
942 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
944 chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
949 progress "Start netdata"
951 if [ "${UID}" -eq 0 ]
955 service netdata restart && started=1
956 if [ ${started} -eq 0 ]
958 service netdata start && started=1
962 if [ ${started} -eq 0 ]
964 # still not started...
968 echo >&2 "Starting netdata..."
969 run ${NETDATA_PREFIX}/usr/sbin/netdata -P ${NETDATA_RUN_DIR}/netdata.pid "${@}"
973 echo >&2 "SORRY! FAILED TO START NETDATA!"
976 echo >&2 "OK. NetData Started!"
982 # -----------------------------------------------------------------------------
983 # save a config file, if it is not already there
985 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
988 echo >&2 "-------------------------------------------------------------------------------"
990 echo >&2 "Downloading default configuration from netdata..."
993 # remove a possibly obsolete download
994 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
996 # disable a proxy to get data from the local netdata
1001 wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1005 if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1007 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
1011 if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
1013 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1014 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1016 if [ "${UID}" -eq 0 ]
1018 chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1020 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
1022 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
1023 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
1028 # -----------------------------------------------------------------------------
1029 progress "Check KSM (kernel memory deduper)"
1031 ksm_is_available_but_disabled() {
1034 ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
1036 You have kernel memory de-duper (called Kernel Same-page Merging,
1037 or KSM) available, but it is not currently enabled.
1041 ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
1042 ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
1044 If you enable it, you will save 40-60% of netdata memory.
1049 ksm_is_not_available() {
1052 ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
1054 It seems you do not have kernel memory de-duper (called Kernel Same-page
1055 Merging, or KSM) available.
1057 To enable it, you need a kernel built with CONFIG_KSM=y
1059 If you can have it, you will save 40-60% of netdata memory.
1064 if [ -f "/sys/kernel/mm/ksm/run" ]
1066 if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
1068 ksm_is_available_but_disabled
1071 ksm_is_not_available
1074 # -----------------------------------------------------------------------------
1075 progress "Check version.txt"
1077 if [ ! -s web/version.txt ]
1081 ${TPUT_BOLD}Version update check warning${TPUT_RESET}
1083 The way you downloaded netdata, we cannot find its version. This means the
1084 Update check on the dashboard, will not work.
1086 If you want to have version update check, please re-install it
1087 following the procedure in:
1089 https://github.com/firehol/netdata/wiki/Installation
1094 # -----------------------------------------------------------------------------
1095 progress "Check apps.plugin"
1097 if [ "${UID}" -ne 0 ]
1099 cat <<SETUID_WARNING
1101 ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
1103 Since you have installed netdata as a normal user, to have apps.plugin collect
1104 all the needed data, you have to give it the access rights it needs, by running
1105 either of the following sets of commands:
1107 To run apps.plugin with escalated capabilities:
1109 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_USER} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1110 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1111 ${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}
1113 or, to run apps.plugin as root:
1115 ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1116 ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4755 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
1118 apps.plugin is performing a hard-coded function of data collection for all
1119 running processes. It cannot be instructed from the netdata daemon to perform
1120 any task, so it is pretty safe to do this.
1125 # -----------------------------------------------------------------------------
1126 progress "Generate netdata-uninstaller.sh"
1128 cat >netdata-uninstaller.sh <<UNINSTALL
1131 # this script will uninstall netdata
1133 if [ "\$1" != "--force" ]
1135 echo >&2 "This script will REMOVE netdata from your system."
1136 echo >&2 "Run it again with --force to do it."
1140 echo >&2 "Stopping a possibly running netdata..."
1141 for p in \$(pidof netdata); do kill \$p; done
1145 if [ ! -z "\$1" -a -d "\$1" ]
1148 echo "Deleting directory '\$1' ..."
1153 if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
1155 # installation prefix was given
1157 deletedir "${NETDATA_PREFIX}"
1160 # installation prefix was NOT given
1162 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
1164 echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
1165 rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
1168 deletedir "${NETDATA_PREFIX}/etc/netdata"
1169 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
1170 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
1171 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
1172 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
1173 deletedir "${NETDATA_PREFIX}/var/log/netdata"
1176 if [ -f /etc/logrotate.d/netdata ]
1178 echo "Deleting /etc/logrotate.d/netdata ..."
1179 rm -i /etc/logrotate.d/netdata
1182 if [ -f /etc/systemd/system/netdata.service ]
1184 echo "Deleting /etc/systemd/system/netdata.service ..."
1185 rm -i /etc/systemd/system/netdata.service
1188 if [ -f /etc/init.d/netdata ]
1190 echo "Deleting /etc/init.d/netdata ..."
1191 rm -i /etc/init.d/netdata
1194 getent passwd netdata > /dev/null
1198 echo "You may also want to remove the user netdata"
1200 echo " userdel netdata"
1203 getent group netdata > /dev/null
1207 echo "You may also want to remove the group netdata"
1209 echo " groupdel netdata"
1212 getent group docker > /dev/null
1213 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
1216 echo "You may also want to remove the netdata user from the docker group"
1218 echo " gpasswd -d netdata docker"
1221 getent group nginx > /dev/null
1222 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NGINX}" = "1" ]
1225 echo "You may also want to remove the netdata user from the nginx group"
1227 echo " gpasswd -d netdata nginx"
1230 getent group varnish > /dev/null
1231 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_VARNISH}" = "1" ]
1234 echo "You may also want to remove the netdata user from the varnish group"
1236 echo " gpasswd -d netdata varnish"
1239 getent group haproxy > /dev/null
1240 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_HAPROXY}" = "1" ]
1243 echo "You may also want to remove the netdata user from the haproxy group"
1245 echo " gpasswd -d netdata haproxy"
1248 getent group adm > /dev/null
1249 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_ADM}" = "1" ]
1252 echo "You may also want to remove the netdata user from the adm group"
1254 echo " gpasswd -d netdata adm"
1257 getent group nsd > /dev/null
1258 if [ $? -eq 0 -a "${NETDATA_ADDED_TO_NSD}" = "1" ]
1261 echo "You may also want to remove the netdata user from the nsd group"
1263 echo " gpasswd -d netdata nsd"
1268 chmod 750 netdata-uninstaller.sh
1270 # -----------------------------------------------------------------------------
1271 progress "Basic netdata instructions"
1275 netdata by default listens on all IPs on port ${NETDATA_PORT},
1276 so you can access it with:
1278 ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
1280 To stop netdata, just kill it, with:
1282 ${TPUT_YELLOW}${TPUT_BOLD}killall netdata${TPUT_RESET}
1284 To start it, just run it:
1286 ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
1290 echo >&2 "Uninstall script generated: ${TPUT_RED}${TPUT_BOLD}./netdata-uninstaller.sh${TPUT_RESET}"
1294 cat >netdata-updater.sh.new <<REINSTALL
1298 [ "\${1}" = "-f" ] && force=1
1300 export PATH="\${PATH}:${PATH}"
1301 export CFLAGS="${CFLAGS}"
1302 export NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
1304 INSTALL_UID="${UID}"
1305 if [ "\${INSTALL_UID}" != "\${UID}" ]
1307 echo >&2 "This script should be run as user with uid \${INSTALL_UID} but it now runs with uid \${UID}"
1311 # make sure we cd to the working directory
1312 cd "${REINSTALL_PWD}" || exit 1
1314 # make sure there is .git here
1315 [ \${force} -eq 0 -a ! -d .git ] && echo >&2 "No git structures found at: ${REINSTALL_PWD} (use -f for force re-install)" && exit 1
1317 # signal netdata to start saving its database
1318 # this is handy if your database is big
1319 pids=\$(pidof netdata)
1320 [ ! -z "\${pids}" ] && kill -USR1 \${pids}
1325 # we are running on a terminal
1326 # open fd 3 and send it to stderr
1330 # create a temporary file for the log
1331 tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1332 # open fd 3 and send it to tmp
1337 echo >&3 "\$(date) : INFO: " "\${@}"
1345 echo >&3 "\$(date) : ERROR: " "\${@}"
1348 # this is what we will do if it fails (head-less only)
1350 error "FAILED TO UPDATE NETDATA : \${1}"
1352 if [ ! -z "\${tmp}" ]
1360 get_latest_commit_id() {
1362 grep ^commit 2>&3 |\\
1364 cut -d ' ' -f 2 2>&3
1368 [ -z "\${tmp}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
1374 info "Updating netdata source from github..."
1376 last_commit="\$(get_latest_commit_id)"
1377 [ \${force} -eq 0 -a -z "\${last_commit}" ] && failed "CANNOT GET LAST COMMIT ID (use -f for force re-install)"
1379 git pull >&3 2>&3 || failed "CANNOT FETCH LATEST SOURCE (use -f for force re-install)"
1381 new_commit="\$(get_latest_commit_id)"
1382 if [ \${force} -eq 0 ]
1384 [ -z "\${new_commit}" ] && failed "CANNOT GET NEW LAST COMMIT ID (use -f for force re-install)"
1385 [ "\${new_commit}" = "\${last_commit}" ] && info "Nothing to be done! (use -f to force re-install)" && exit 0
1387 elif [ \${force} -eq 0 ]
1389 failed "CANNOT FIND GIT STRUCTURES IN \$(pwd) (use -f for force re-install)"
1393 info "Re-installing netdata..."
1394 ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >&3 2>&3 || failed "FAILED TO COMPILE/INSTALL NETDATA"
1396 [ ! -z "\${tmp}" ] && rm "\${tmp}" && tmp=
1400 # the installer updates this script - so we run and exit in a single line
1402 ###############################################################################
1403 ###############################################################################
1405 chmod 755 netdata-updater.sh.new
1406 mv -f netdata-updater.sh.new netdata-updater.sh
1407 echo >&2 "Update script generated : ${TPUT_GREEN}${TPUT_BOLD}./netdata-updater.sh${TPUT_RESET}"
1409 echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater.sh${TPUT_RESET}${TPUT_DIM} can work from cron. It will trigger an email from cron"
1410 echo >&2 "only if it fails (it does not print anything if it can update netdata).${TPUT_RESET}"
1411 if [ "${UID}" -eq 0 -a -d "/etc/cron.daily" -a ! -f "/etc/cron.daily/netdata-updater.sh" ]
1413 echo >&2 "${TPUT_DIM}Run this to automatically check and install netdata updates once per day:${TPUT_RESET}"
1415 echo >&2 "${TPUT_YELLOW}${TPUT_BOLD}ln -s ${PWD}/netdata-updater.sh /etc/cron.daily/netdata-updater.sh${TPUT_RESET}"
1417 elif [ -f "netdata-updater.sh" ]
1419 rm "netdata-updater.sh"
1422 # -----------------------------------------------------------------------------
1424 progress "We are done!"
1426 if [ ${started} -eq 1 ]
1428 netdata_banner "is installed and running now!"
1430 netdata_banner "is installed now!"
1433 echo >&2 " enjoy real-time performance and health monitoring..."