summaryrefslogtreecommitdiffstats
path: root/installer
diff options
context:
space:
mode:
Diffstat (limited to 'installer')
-rw-r--r--installer/.keep0
-rw-r--r--installer/README.md366
-rw-r--r--installer/UNINSTALL.md36
-rw-r--r--installer/UPDATE.md71
-rw-r--r--installer/functions.sh866
5 files changed, 0 insertions, 1339 deletions
diff --git a/installer/.keep b/installer/.keep
deleted file mode 100644
index e69de29b..00000000
--- a/installer/.keep
+++ /dev/null
diff --git a/installer/README.md b/installer/README.md
deleted file mode 100644
index cbcefab0..00000000
--- a/installer/README.md
+++ /dev/null
@@ -1,366 +0,0 @@
-# Installation
-![image10](https://cloud.githubusercontent.com/assets/2662304/14253729/534c6f9c-fa95-11e5-8243-93eb0df719aa.gif)
-
-## Linux package managers
-
-You can install the latest release of netdata, using your package manager in
-
- - Arch Linux (`sudo pacman -S netdata`)
- - Alpine Linux (`sudo apk add netdata`)
- - Debian Linux (`sudo apt install netdata`)
- - Gentoo Linux (`sudo emerge --ask netdata`)
- - OpenSUSE (`sudo zypper install netdata`)
- - Solus Linux (`sudo eopkg install netdata`)
- - Ubuntu Linux >= 18.04 (`sudo apt install netdata`)
-
-Please note that the particular packages are not build by netdata.
-
-## Docker
-
-You can [Install netdata with Docker](../docker/#install-netdata-with-docker)
-
-## Linux one liner
-
-![](https://registry.my-netdata.io/api/v1/badge.svg?chart=web_log_nginx.requests_per_url&options=unaligned&dimensions=kickstart&group=sum&after=-3600&label=last+hour&units=installations&value_color=orange&precision=0) ![](https://registry.my-netdata.io/api/v1/badge.svg?chart=web_log_nginx.requests_per_url&options=unaligned&dimensions=kickstart&group=sum&after=-86400&label=today&units=installations&precision=0)
-
-To install netdata from source to your systems and keep it up to date automatically, run the following:
-
-:hash:**`bash <(curl -Ss https://my-netdata.io/kickstart.sh)`**
-
-(do not `sudo` this command, it will do it by itself as needed)
-
-The command:
-
-1. detects the distro and **installs the required system packages** for building netdata (will ask for confirmation)
-2. downloads the latest netdata source tree to `/usr/src/netdata.git`.
-3. installs netdata by running `./netdata-installer.sh` from the source tree.
-4. installs `netdata-updater.sh` to `cron.daily`, so your netdata installation will be updated daily (you will get a message from cron only if the update fails).
-
-The `kickstart.sh` script passes all its parameters to `netdata-installer.sh`, so you can add more parameters to change the installation directory, enable/disable plugins, etc (check below).
-
-For automated installs, append a space + `--dont-wait` to the command line. You can also append `--dont-start-it` to prevent the installer from starting netdata. Example:
-
-```sh
-bash <(curl -Ss https://my-netdata.io/kickstart.sh) all --dont-wait --dont-start-it
-```
-
-## Linux 64bit pre-built static binary
-
-You can install a pre-compiled static binary of netdata for any Intel/AMD 64bit Linux system (even those that don't have a package manager, like CoreOS, CirrOS, busybox systems, etc). You can also use these packages on systems with broken or unsupported package managers.
-
-<br/>![](https://registry.my-netdata.io/api/v1/badge.svg?chart=web_log_nginx.requests_per_url&options=unaligned&dimensions=kickstart64&group=sum&after=-3600&label=last+hour&units=installations&value_color=orange&precision=0) ![](https://registry.my-netdata.io/api/v1/badge.svg?chart=web_log_nginx.requests_per_url&options=unaligned&dimensions=kickstart64&group=sum&after=-86400&label=today&units=installations&precision=0)
-
-To install netdata with a binary package on any Linux distro, any kernel version - for **Intel/AMD 64bit** hosts, run the following:
-
-:hash:&nbsp; **`bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh)`**
-
-(do not `sudo` this command, it will do it by itself as needed; the target system does not need `bash` installed, check below for instructions to run it without `bash`)
-
-*Note: The static builds install netdata at `/opt/netdata`*
-
-For automated installs, append a space + `--dont-wait` to the command line. You can also append `--dont-start-it` to prevent the installer from starting netdata. Example:
-
-```sh
-bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh) --dont-wait --dont-start-it
-```
-
-If your shell fails to handle the above one liner, do this:
-
-```sh
-# download the script with curl
-curl https://my-netdata.io/kickstart-static64.sh >/tmp/kickstart-static64.sh
-
-# or, download the script with wget
-wget -O /tmp/kickstart-static64.sh https://my-netdata.io/kickstart-static64.sh
-
-# run the downloaded script (any sh is fine, no need for bash)
-sh /tmp/kickstart-static64.sh
-```
-
-The static binary files are kept in repo [binary-packages](https://github.com/netdata/binary-packages). You can download any of the `.run` files, and run it. These files are self-extracting shell scripts built with [makeself](https://github.com/megastep/makeself). The target system does **not** need to have bash installed. The same files can be used for updates too.
-
-## Other installation methods
-
-- **Linux manual installation from source**
-
- Semi-automatic, with more details about the steps involved and actions taken [here](#install-netdata-on-linux-manually)
-
-- **Non-Linux installation**
- - [Install from package or source, on FreeBSD](#freebsd)
- - [Install from package, on pfSense](#pfsense)
- - [Enable netdata on FreeNAS Corral](#freenas)
- - [Install from package or source, on macOS (OS X)](#macos)
-
- See also the list of netdata [package maintainers](../packaging/maintainers) for ASUSTOR NAS, OpenWRT, ReadyNAS, etc.
-
-## Install netdata on Linux manually
-
-To install the latest git version of netdata, please follow these 2 steps:
-
-1. [Prepare your system](#prepare-your-system)
-
- Install the required packages on your system.
-
-2. [Install netdata](#install-netdata)
-
- Download and install netdata. You can also update it the same way.
-
----
-
-### Prepare your system
-
-Try our experimental automatic requirements installer (no need to be root). This will try to find the packages that should be installed on your system to build and run netdata. It supports most major Linux distributions released after 2010:
-
-- **Alpine** Linux and its derivatives (you have to install `bash` yourself, before using the installer)
-- **Arch** Linux and its derivatives
-- **Gentoo** Linux and its derivatives
-- **Debian** Linux and its derivatives (including **Ubuntu**, **Mint**)
-- **Fedora** and its derivatives (including **Red Hat Enterprise Linux**, **CentOS**, **Amazon Machine Image**)
-- **SuSe** Linux and its derivatives (including **openSuSe**)
-- **SLE12** Must have your system registered with Suse Customer Center or have the DVD. See [#1162](https://github.com/netdata/netdata/issues/1162)
-
-Install the packages for having a **basic netdata installation** (system monitoring and many applications, without `mysql` / `mariadb`, `postgres`, `named`, hardware sensors and `SNMP`):
-
-```sh
-curl -Ss 'https://raw.githubusercontent.com/netdata/netdata-demo-site/master/install-required-packages.sh' >/tmp/kickstart.sh && bash /tmp/kickstart.sh -i netdata
-```
-
-Install all the required packages for **monitoring everything netdata can monitor**:
-
-```sh
-curl -Ss 'https://raw.githubusercontent.com/netdata/netdata-demo-site/master/install-required-packages.sh' >/tmp/kickstart.sh && bash /tmp/kickstart.sh -i netdata-all
-```
-
-If the above do not work for you, please [open a github issue](https://github.com/netdata/netdata/issues/new?title=packages%20installer%20failed&labels=installation%20help&body=The%20experimental%20packages%20installer%20failed.%0A%0AThis%20is%20what%20it%20says:%0A%0A%60%60%60txt%0A%0Aplease%20paste%20your%20screen%20here%0A%0A%60%60%60) with a copy of the message you get on screen. We are trying to make it work everywhere (this is also why the script [reports back](https://github.com/netdata/netdata/issues/2054) success or failure for all its runs).
-
----
-
-This is how to do it by hand:
-
-```sh
-# Debian / Ubuntu
-apt-get install zlib1g-dev uuid-dev libmnl-dev gcc make git autoconf autoconf-archive autogen automake pkg-config curl
-
-# Fedora
-dnf install zlib-devel libuuid-devel libmnl-devel gcc make git autoconf autoconf-archive autogen automake pkgconfig curl findutils
-
-# CentOS / Red Hat Enterprise Linux
-yum install autoconf automake curl gcc git libmnl-devel libuuid-devel lm_sensors make MySQL-python nc pkgconfig python python-psycopg2 PyYAML zlib-devel
-
-```
-
-Please note that for RHEL/CentOS you might need [EPEL](http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/).
-
-Once netdata is compiled, to run it the following packages are required (already installed using the above commands):
-
-package|description
-:-----:|-----------
-`libuuid`|part of `util-linux` for GUIDs management
-`zlib`|gzip compression for the internal netdata web server
-
-*netdata will fail to start without the above.*
-
-netdata plugins and various aspects of netdata can be enabled or benefit when these are installed (they are optional):
-
-package|description
-:-----:|-----------
-`bash`|for shell plugins and **alarm notifications**
-`curl`|for shell plugins and **alarm notifications**
-`iproute` or `iproute2`|for monitoring **Linux traffic QoS**<br/>use `iproute2` if `iproute` reports as not available or obsolete
-`python`|for most of the external plugins
-`python-yaml`|used for monitoring **beanstalkd**
-`python-beanstalkc`|used for monitoring **beanstalkd**
-`python-dnspython`|used for monitoring DNS query time
-`python-ipaddress`|used for monitoring **DHCPd**<br/>this package is required only if the system has python v2. python v3 has this functionality embedded
-`python-mysqldb`<br/>or<br/>`python-pymysql`|used for monitoring **mysql** or **mariadb** databases<br/>`python-mysqldb` is a lot faster and thus preferred
-`python-psycopg2`|used for monitoring **postgresql** databases
-`python-pymongo`|used for monitoring **mongodb** databases
-`nodejs`|used for `node.js` plugins for monitoring **named** and **SNMP** devices
-`lm-sensors`|for monitoring **hardware sensors**
-`libmnl`|for collecting netfilter metrics
-`netcat`|for shell plugins to collect metrics from remote systems
-
-*netdata will greatly benefit if you have the above packages installed, but it will still work without them.*
-
----
-
-### Install netdata
-
-Do this to install and run netdata:
-
-```sh
-
-# download it - the directory 'netdata' will be created
-git clone https://github.com/netdata/netdata.git --depth=1
-cd netdata
-
-# run script with root privileges to build, install, start netdata
-./netdata-installer.sh
-
-```
-
-* If you don't want to run it straight-away, add `--dont-start-it` option.
-
-* If you don't want to install it on the default directories, you can run the installer like this: `./netdata-installer.sh --install /opt`. This one will install netdata in `/opt/netdata`.
-
-Once the installer completes, the file `/etc/netdata/netdata.conf` will be created (if you changed the installation directory, the configuration will appear in that directory too).
-
-You can edit this file to set options. One common option to tweak is `history`, which controls the size of the memory database netdata will use. By default is `3600` seconds (an hour of data at the charts) which makes netdata use about 10-15MB of RAM (depending on the number of charts detected on your system). Check **[[Memory Requirements]]**.
-
-To apply the changes you made, you have to restart netdata.
-
----
-
-## Other Systems
-
-
-
-##### FreeBSD
-
-You can install netdata from ports or packages collection.
-
-This is how to install the latest netdata version from sources on FreeBSD:
-
-```sh
-# install required packages
-pkg install bash e2fsprogs-libuuid git curl autoconf automake pkgconf pidof
-
-# download netdata
-git clone https://github.com/netdata/netdata.git --depth=1
-
-# install netdata in /opt/netdata
-cd netdata
-./netdata-installer.sh --install /opt
-```
-
-##### pfSense
-To install netdata on pfSense run the following commands (within a shell or under Diagnostics/Command Prompt within the pfSense web interface).
-
-Change platform (i386/amd64, etc) and FreeBSD versions (10/11, etc) according to your environment and change netdata version (1.10.0 in example) according to latest version present within the FreeSBD repository:-
-
-Note first three packages are downloaded from the pfSense repository for maintaining compatibility with pfSense, netdata is downloaded from the FreeBSD repository.
-```
-pkg install pkgconf
-pkg install bash
-pkg install e2fsprogs-libuuid
-pkg add http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/netdata-1.11.0.txz
-```
-To start netdata manually run `service netdata onestart`
-
-To start netdata automatically at each boot add `service netdata start` as a Shellcmd within the pfSense web interface (under **Services/Shellcmd**, which you need to install beforehand under **System/Package Manager/Available Packages**).
-Shellcmd Type should be set to `Shellcmd`.
-![](https://user-images.githubusercontent.com/36808164/36930790-4db3aa84-1f0d-11e8-8752-cdc08bb7207c.png)
-Alternatively more information can be found in https://doc.pfsense.org/index.php/Installing_FreeBSD_Packages, for achieving the same via the command line and scripts.
-
-If you experience an issue with `/usr/bin/install` absense on pfSense 2.3 or earlier, update pfSense or use workaround from [https://redmine.pfsense.org/issues/6643](https://redmine.pfsense.org/issues/6643)
-
-##### FreeNAS
-On FreeNAS-Corral-RELEASE (>=10.0.3), netdata is pre-installed.
-
-To use netdata, the service will need to be enabled and started from the FreeNAS **[CLI](https://github.com/freenas/cli)**.
-
-To enable the netdata service:
-```
-service netdata config set enable=true
-```
-
-To start the netdata service:
-```
-service netdata start
-```
-
-##### macOS
-
-netdata on macOS still has limited charts, but external plugins do work.
-
-You can either install netdata with [Homebrew](https://brew.sh/)
-
-```sh
-brew install netdata
-```
-
-or from source:
-
-```sh
-# install Xcode Command Line Tools
-xcode-select --install
-```
-click `Install` in the software update popup window, then
-```sh
-# install HomeBrew package manager
-/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-
-# install required packages
-brew install ossp-uuid autoconf automake pkg-config
-
-# download netdata
-git clone https://github.com/netdata/netdata.git --depth=1
-
-# install netdata in /usr/local/netdata
-cd netdata
-sudo ./netdata-installer.sh --install /usr/local
-```
-
-The installer will also install a startup plist to start netdata when your Mac boots.
-
-##### Alpine 3.x
-
-Execute these commands to install netdata in Alpine Linux 3.x:
-
-```
-# install required packages
-apk add alpine-sdk bash curl zlib-dev util-linux-dev libmnl-dev gcc make git autoconf automake pkgconfig python logrotate
-
-# if you plan to run node.js netdata plugins
-apk add nodejs
-
-# download netdata - the directory 'netdata' will be created
-git clone https://github.com/netdata/netdata.git --depth=1
-cd netdata
-
-
-# build it, install it, start it
-./netdata-installer.sh
-
-
-# make netdata start at boot
-echo -e "#!/usr/bin/env bash\n/usr/sbin/netdata" >/etc/local.d/netdata.start
-chmod 755 /etc/local.d/netdata.start
-
-# make netdata stop at shutdown
-echo -e "#!/usr/bin/env bash\nkillall netdata" >/etc/local.d/netdata.stop
-chmod 755 /etc/local.d/netdata.stop
-
-# enable the local service to start automatically
-rc-update add local
-```
-
-##### Synology
-
-The documentation previously recommended installing the Debian Chroot package from the Synology community package sources and then running netdata from within the chroot. This does not work, as the chroot environment does not have access to `/proc`, and therefore exposes very few metrics to netdata. Additionally, [this issue](https://github.com/SynoCommunity/spksrc/issues/2758), still open as of 2018/06/24, indicates that the Debian Chroot package is not suitable for DSM versions greater than version 5 and may corrupt system libraries and render the NAS unable to boot.
-
-The good news is that the 64-bit static installer works fine if your NAS is one that uses the amd64 architecture. It will install the content into `/opt/netdata`, making future removal safe and simple.
-
-###### Additional Work
-
-When netdata is first installed, it will run as _root_. This may or may not be acceptable for you, and since other installations run it as the _netdata_ user, you might wish to do the same. This requires some extra work:
-
-1. Creat a group `netdata` via the Synology group interface. Give it no access to anything.
-2. Create a user `netdata` via the Synology user interface. Give it no access to anything and a random password. Assign the user to the `netdata` group. Netdata will chuid to this user when running.
-3. Change ownership of the following directories, as defined in [Netdata Security](../doc/netdata-security.md#netdata-security):
-
-```
-$ chown -R root:netdata /opt/netdata/usr/share/netdata
-$ chown -R netdata:netdata /opt/netdata/var/lib/netdata /opt/netdata/var/cache/netdata
-$ chown -R netdata:root /opt/netdata/var/log/netdata
-```
-
-Additionally, as of 2018/06/24, the netdata installer doesn't recognize DSM as an operating system, so no init script is installed. You'll have to do this manually:
-
-1. Add [this file](https://gist.github.com/oskapt/055d474d7bfef32c49469c1b53e8225f) as `/etc/rc.netdata`. Make it executable with `chmod 0755 /etc/rc.netdata`.
-2. Edit `/etc/rc.local` and add a line calling `/etc/rc.netdata` to have it start on boot:
-
-```
-# Netdata startup
-[ -x /etc/rc.netdata ] && /etc/rc.netdata start
-```
diff --git a/installer/UNINSTALL.md b/installer/UNINSTALL.md
deleted file mode 100644
index 4f9a84d0..00000000
--- a/installer/UNINSTALL.md
+++ /dev/null
@@ -1,36 +0,0 @@
-# Uninstalling netdata
-
-## netdata was installed from source (or `kickstart.sh`)
-
-The script `netdata-installer.sh` generates another script called `netdata-uninstaller.sh`.
-
-To uninstall netdata, run:
-
-```
-cd /path/to/netdata.git
-./netdata-uninstaller.sh --force
-```
-
-The uninstaller will ask you to confirm all deletions.
-
-## netdata was installed with `kickstart-static64.sh` package
-
-Stop netdata with one of the following:
-
-- `service netdata stop` (non-systemd systems)
-- `systemctl stop netdata` (systemd systems)
-
-Disable running netdata at startup, with one of the following (based on your distro):
-
-- `rc-update del netdata`
-- `update-rc.d netdata disable`
-- `chkconfig netdata off`
-- `systemctl disable netdata`
-
-Delete the netdata files:
-
-1. `rm -rf /opt/netdata`
-2. `groupdel netdata`
-3. `userdel netdata`
-4. `rm /etc/logrotate.d/netdata`
-5. `rm /etc/systemd/system/netdata.service` or `rm /etc/init.d/netdata`, depending on the distro.
diff --git a/installer/UPDATE.md b/installer/UPDATE.md
deleted file mode 100644
index cda21fc0..00000000
--- a/installer/UPDATE.md
+++ /dev/null
@@ -1,71 +0,0 @@
-# Updating netdata after its installation
-
-![image8](https://cloud.githubusercontent.com/assets/2662304/14253735/536f4580-fa95-11e5-9f7b-99112b31a5d7.gif)
-
-
-We suggest to keep your netdata updated. We are actively developing it and you should always update to the latest version.
-
-The update procedure depends on how you installed it:
-
-## You downloaded it from github using git
-
-### Manual update
-
-The installer `netdata-installer.sh` generates a `netdata-updater.sh` script in the directory you downloaded netdata.
-You can use this script to update your netdata installation with the same options you used to install it in the first place.
-Just run it and it will download and install the latest version of netdata. The same script can be put in a cronjob to update your netdata at regular intervals.
-
-```sh
-# go to the git downloaded directory
-cd /path/to/git/downloaded/netdata
-
-# run the updater
-./netdata-updater.sh
-```
-
-_Netdata will be restarted with the new version._
-
-If you don't have this script (e.g. you deleted the directory where you downloaded netdata), just follow the **[[Installation]]** instructions again. The installer preserves your configuration. You can also update netdata to the latest version by hand, using this:
-
-```sh
-# go to the git downloaded directory
-cd /path/to/git/downloaded/netdata
-
-# download the latest version
-git pull
-
-# rebuild it, install it, run it
-./netdata-installer.sh
-```
-
-_Netdata will be restarted with the new version._
-
-Keep in mind, netdata may now have new features, or certain old features may now behave differently. So pay some attention to it after updating.
-
-### Auto-update
-
-_Please, consider the risks of running an auto-update. Something can always go wrong. Keep an eye on your installation, and run a manual update if something ever fails._
-
-You can call `netdata-updater.sh` from a cron-job. A successful update will not trigger an email from cron.
-
-```sh
-# Edit your cron-jobs
-crontab -e
-
-# add a cron-job at the bottom. This one will update netdata every day at 6:00AM:
-# update netdata
-0 6 * * * /path/to/git/downloaded/netdata/netdata-updater.sh
-```
-
-## You downloaded a binary package
-
-If you installed it from a binary package, the best way is to **obtain a newer copy** from the source you got it in the first place.
-
-If a newer version of netdata is not available from the source you got it, we suggest to uninstall the version you have and follow the **[[Installation]]** instructions for installing a fresh version of netdata.
-
-
-
-
-
-
-
diff --git a/installer/functions.sh b/installer/functions.sh
deleted file mode 100644
index 155edd79..00000000
--- a/installer/functions.sh
+++ /dev/null
@@ -1,866 +0,0 @@
-# no shebang necessary - this is a library to be sourced
-# SPDX-License-Identifier: GPL-3.0-or-later
-# shellcheck disable=SC1091,SC1117,SC2002,SC2004,SC2034,SC2046,SC2059,SC2086,SC2129,SC2148,SC2154,SC2155,SC2162,SC2166,SC2181,SC2193
-
-# make sure we have a UID
-[ -z "${UID}" ] && UID="$(id -u)"
-
-
-# -----------------------------------------------------------------------------
-# checking the availability of commands
-
-which_cmd() {
- # shellcheck disable=SC2230
- which "${1}" 2>/dev/null || command -v "${1}" 2>/dev/null
-}
-
-check_cmd() {
- which_cmd "${1}" >/dev/null 2>&1 && return 0
- return 1
-}
-
-
-# -----------------------------------------------------------------------------
-
-setup_terminal() {
- TPUT_RESET=""
- TPUT_BLACK=""
- TPUT_RED=""
- TPUT_GREEN=""
- TPUT_YELLOW=""
- TPUT_BLUE=""
- TPUT_PURPLE=""
- TPUT_CYAN=""
- TPUT_WHITE=""
- TPUT_BGBLACK=""
- TPUT_BGRED=""
- TPUT_BGGREEN=""
- TPUT_BGYELLOW=""
- TPUT_BGBLUE=""
- TPUT_BGPURPLE=""
- TPUT_BGCYAN=""
- TPUT_BGWHITE=""
- TPUT_BOLD=""
- TPUT_DIM=""
- TPUT_UNDERLINED=""
- TPUT_BLINK=""
- TPUT_INVERTED=""
- TPUT_STANDOUT=""
- TPUT_BELL=""
- TPUT_CLEAR=""
-
- # Is stderr on the terminal? If not, then fail
- test -t 2 || return 1
-
- if check_cmd tput
- then
- if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
- then
- # Enable colors
- TPUT_RESET="$(tput sgr 0)"
- TPUT_BLACK="$(tput setaf 0)"
- TPUT_RED="$(tput setaf 1)"
- TPUT_GREEN="$(tput setaf 2)"
- TPUT_YELLOW="$(tput setaf 3)"
- TPUT_BLUE="$(tput setaf 4)"
- TPUT_PURPLE="$(tput setaf 5)"
- TPUT_CYAN="$(tput setaf 6)"
- TPUT_WHITE="$(tput setaf 7)"
- TPUT_BGBLACK="$(tput setab 0)"
- TPUT_BGRED="$(tput setab 1)"
- TPUT_BGGREEN="$(tput setab 2)"
- TPUT_BGYELLOW="$(tput setab 3)"
- TPUT_BGBLUE="$(tput setab 4)"
- TPUT_BGPURPLE="$(tput setab 5)"
- TPUT_BGCYAN="$(tput setab 6)"
- TPUT_BGWHITE="$(tput setab 7)"
- TPUT_BOLD="$(tput bold)"
- TPUT_DIM="$(tput dim)"
- TPUT_UNDERLINED="$(tput smul)"
- TPUT_BLINK="$(tput blink)"
- TPUT_INVERTED="$(tput rev)"
- TPUT_STANDOUT="$(tput smso)"
- TPUT_BELL="$(tput bel)"
- TPUT_CLEAR="$(tput clear)"
- fi
- fi
-
- return 0
-}
-setup_terminal || echo >/dev/null
-
-progress() {
- echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
-}
-
-# -----------------------------------------------------------------------------
-
-netdata_banner() {
- local l1=" ^" \
- l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
- l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
- l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
- sp=" " \
- netdata="netdata" start end msg="${*}" chartcolor="${TPUT_DIM}"
-
- [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$(( ${#netdata} - ${#msg}))}"
- [ ${#msg} -gt $(( ${#l2} - 20 )) ] && msg="${msg:0:$(( ${#l2} - 23 ))}..."
-
- start="$(( ${#l2} / 2 - 4 ))"
- [ $(( start + ${#msg} + 4 )) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
- end=$(( ${start} + ${#msg} + 4 ))
-
- echo >&2
- echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
- echo >&2 "${chartcolor}${l2:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}${TPUT_RESET}"
- echo >&2 "${chartcolor}${l3:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_CYAN}${msg}${TPUT_RESET}${chartcolor}${sp:0:2}${l3:end:$((${#l2} - end))}${TPUT_RESET}"
- echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
- echo >&2
-}
-
-# -----------------------------------------------------------------------------
-# portable service command
-
-service_cmd="$(which_cmd service)"
-rcservice_cmd="$(which_cmd rc-service)"
-systemctl_cmd="$(which_cmd systemctl)"
-service() {
- local cmd="${1}" action="${2}"
-
- if [ ! -z "${systemctl_cmd}" ]
- then
- run "${systemctl_cmd}" "${action}" "${cmd}"
- return $?
- elif [ ! -z "${service_cmd}" ]
- then
- run "${service_cmd}" "${cmd}" "${action}"
- return $?
- elif [ ! -z "${rcservice_cmd}" ]
- then
- run "${rcservice_cmd}" "${cmd}" "${action}"
- return $?
- fi
- return 1
-}
-
-# -----------------------------------------------------------------------------
-# portable pidof
-
-pidof_cmd="$(which_cmd pidof)"
-pidof() {
- if [ ! -z "${pidof_cmd}" ]
- then
- ${pidof_cmd} "${@}"
- return $?
- else
- ps -acxo pid,comm |\
- sed "s/^ *//g" |\
- grep netdata |\
- cut -d ' ' -f 1
- return $?
- fi
-}
-
-# -----------------------------------------------------------------------------
-# portable delete recursively interactively
-
-portable_deletedir_recursively_interactively() {
- if [ ! -z "$1" -a -d "$1" ]
- then
- if [ "$(uname -s)" = "Darwin" ]
- then
- echo >&2
- read >&2 -p "Press ENTER to recursively delete directory '$1' > "
- echo >&2 "Deleting directory '$1' ..."
- run rm -R "$1"
- else
- echo >&2
- echo >&2 "Deleting directory '$1' ..."
- run rm -I -R "$1"
- fi
- else
- echo "Directory '$1' does not exist."
- fi
-}
-
-
-# -----------------------------------------------------------------------------
-
-export SYSTEM_CPUS=1
-portable_find_processors() {
- if [ -f "/proc/cpuinfo" ]
- then
- # linux
- SYSTEM_CPUS=$(grep -c ^processor /proc/cpuinfo)
- else
- # freebsd
- SYSTEM_CPUS=$(sysctl hw.ncpu 2>/dev/null | grep ^hw.ncpu | cut -d ' ' -f 2)
- fi
- [ -z "${SYSTEM_CPUS}" -o $(( SYSTEM_CPUS )) -lt 1 ] && SYSTEM_CPUS=1
-}
-portable_find_processors
-
-# -----------------------------------------------------------------------------
-
-run_ok() {
- printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
-}
-
-run_failed() {
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
-}
-
-ESCAPED_PRINT_METHOD=
-printf "%q " test >/dev/null 2>&1
-[ $? -eq 0 ] && ESCAPED_PRINT_METHOD="printfq"
-escaped_print() {
- if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]
- then
- printf "%q " "${@}"
- else
- printf "%s" "${*}"
- fi
- return 0
-}
-
-run_logfile="/dev/null"
-run() {
- local user="${USER--}" dir="${PWD}" info info_console
-
- if [ "${UID}" = "0" ]
- then
- info="[root ${dir}]# "
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
- else
- info="[${user} ${dir}]$ "
- info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
- fi
-
- printf >> "${run_logfile}" "${info}"
- escaped_print >> "${run_logfile}" "${@}"
- printf >> "${run_logfile}" " ... "
-
- printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
- escaped_print >&2 "${@}"
- printf >&2 "${TPUT_RESET}\n"
-
- "${@}"
-
- local ret=$?
- if [ ${ret} -ne 0 ]
- then
- run_failed
- printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
- else
- run_ok
- printf >> "${run_logfile}" "OK\n"
- fi
-
- return ${ret}
-}
-
-getent_cmd="$(which_cmd getent)"
-portable_check_user_exists() {
- local username="${1}" found=
-
- if [ ! -z "${getent_cmd}" ]
- then
- "${getent_cmd}" passwd "${username}" >/dev/null 2>&1
- return $?
- fi
-
- found="$(cut -d ':' -f 1 </etc/passwd | grep "^${username}$")"
- [ "${found}" = "${username}" ] && return 0
- return 1
-}
-
-portable_check_group_exists() {
- local groupname="${1}" found=
-
- if [ ! -z "${getent_cmd}" ]
- then
- "${getent_cmd}" group "${groupname}" >/dev/null 2>&1
- return $?
- fi
-
- found="$(cut -d ':' -f 1 </etc/group | grep "^${groupname}$")"
- [ "${found}" = "${groupname}" ] && return 0
- return 1
-}
-
-portable_check_user_in_group() {
- local username="${1}" groupname="${2}" users=
-
- if [ ! -z "${getent_cmd}" ]
- then
- users="$(getent group "${groupname}" | cut -d ':' -f 4)"
- else
- users="$(grep "^${groupname}:" </etc/group | cut -d ':' -f 4)"
- fi
-
- [[ ",${users}," =~ ,${username}, ]] && return 0
- return 1
-}
-
-portable_add_user() {
- local username="${1}" homedir="${2}"
-
- [ -z "${homedir}" ] && homedir="/tmp"
-
- portable_check_user_exists "${username}"
- [ $? -eq 0 ] && echo >&2 "User '${username}' already exists." && return 0
-
- echo >&2 "Adding ${username} user account with home ${homedir} ..."
-
- # shellcheck disable=SC2230
- local nologin="$(which nologin 2>/dev/null || command -v nologin 2>/dev/null || echo '/bin/false')"
-
- # Linux
- if check_cmd useradd
- then
- run useradd -r -g "${username}" -c "${username}" -s "${nologin}" --no-create-home -d "${homedir}" "${username}" && return 0
- fi
-
- # FreeBSD
- if check_cmd pw
- then
- run pw useradd "${username}" -d "${homedir}" -g "${username}" -s "${nologin}" && return 0
- fi
-
- # BusyBox
- if check_cmd adduser
- then
- run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0
- fi
-
- echo >&2 "Failed to add ${username} user account !"
-
- return 1
-}
-
-portable_add_group() {
- local groupname="${1}"
-
- portable_check_group_exists "${groupname}"
- [ $? -eq 0 ] && echo >&2 "Group '${groupname}' already exists." && return 0
-
- echo >&2 "Adding ${groupname} user group ..."
-
- # Linux
- if check_cmd groupadd
- then
- run groupadd -r "${groupname}" && return 0
- fi
-
- # FreeBSD
- if check_cmd pw
- then
- run pw groupadd "${groupname}" && return 0
- fi
-
- # BusyBox
- if check_cmd addgroup
- then
- run addgroup "${groupname}" && return 0
- fi
-
- echo >&2 "Failed to add ${groupname} user group !"
- return 1
-}
-
-portable_add_user_to_group() {
- local groupname="${1}" username="${2}"
-
- portable_check_group_exists "${groupname}"
- [ $? -ne 0 ] && echo >&2 "Group '${groupname}' does not exist." && return 1
-
- # find the user is already in the group
- if portable_check_user_in_group "${username}" "${groupname}"
- then
- # username is already there
- echo >&2 "User '${username}' is already in group '${groupname}'."
- return 0
- else
- # username is not in group
- echo >&2 "Adding ${username} user to the ${groupname} group ..."
-
- # Linux
- if check_cmd usermod
- then
- run usermod -a -G "${groupname}" "${username}" && return 0
- fi
-
- # FreeBSD
- if check_cmd pw
- then
- run pw groupmod "${groupname}" -m "${username}" && return 0
- fi
-
- # BusyBox
- if check_cmd addgroup
- then
- run addgroup "${username}" "${groupname}" && return 0
- fi
-
- echo >&2 "Failed to add user ${username} to group ${groupname} !"
- return 1
- fi
-}
-
-iscontainer() {
- # man systemd-detect-virt
- local cmd=$(which_cmd systemd-detect-virt)
- if [ ! -z "${cmd}" -a -x "${cmd}" ]
- then
- "${cmd}" --container >/dev/null 2>&1 && return 0
- fi
-
- # /proc/1/sched exposes the host's pid of our init !
- # http://stackoverflow.com/a/37016302
- local pid=$( cat /proc/1/sched 2>/dev/null | head -n 1 | { IFS='(),#:' read name pid th threads; echo $pid; } )
- pid=$(( pid + 0 ))
- [ ${pid} -ne 1 ] && return 0
-
- # lxc sets environment variable 'container'
- [ ! -z "${container}" ] && return 0
-
- # docker creates /.dockerenv
- # http://stackoverflow.com/a/25518345
- [ -f "/.dockerenv" ] && return 0
-
- # ubuntu and debian supply /bin/running-in-container
- # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
- if [ -x "/bin/running-in-container" ]
- then
- "/bin/running-in-container" >/dev/null 2>&1 && return 0
- fi
-
- return 1
-}
-
-issystemd() {
- local pids p myns ns systemctl
-
- # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
- [ ! -d /lib/systemd/system -a ! -d /usr/lib/systemd/system ] && return 1
-
- # if there is no systemctl command, it is not systemd
- # shellcheck disable=SC2230
- systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
- [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
-
- # if pid 1 is systemd, it is systemd
- [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
-
- # if systemd is not running, it is not systemd
- pids=$(pidof systemd 2>/dev/null)
- [ -z "${pids}" ] && return 1
-
- # check if the running systemd processes are not in our namespace
- myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
- for p in ${pids}
- do
- ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
-
- # if pid of systemd is in our namespace, it is systemd
- [ ! -z "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
- done
-
- # else, it is not systemd
- return 1
-}
-
-install_non_systemd_init() {
- [ "${UID}" != 0 ] && return 1
-
- local key="unknown"
- if [ -f /etc/os-release ]
- then
- source /etc/os-release || return 1
- key="${ID}-${VERSION_ID}"
-
- elif [ -f /etc/redhat-release ]
- then
- key=$(</etc/redhat-release)
- fi
-
- if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
- then
- if [[ "${key}" =~ ^(gentoo|alpine).* ]]
- then
- echo >&2 "Installing OpenRC init file..."
- run cp system/netdata-openrc /etc/init.d/netdata && \
- run chmod 755 /etc/init.d/netdata && \
- run rc-update add netdata default && \
- return 0
-
- elif [ "${key}" = "debian-7" \
- -o "${key}" = "ubuntu-12.04" \
- -o "${key}" = "ubuntu-14.04" \
- ]
- then
- echo >&2 "Installing LSB init file..."
- run cp system/netdata-lsb /etc/init.d/netdata && \
- run chmod 755 /etc/init.d/netdata && \
- run update-rc.d netdata defaults && \
- run update-rc.d netdata enable && \
- return 0
- elif [[ "${key}" =~ ^(amzn-201[5678]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6|Scientific Linux CERN SLC release 6|CloudLinux Server release 6).* ]]
- then
- echo >&2 "Installing init.d file..."
- run cp system/netdata-init-d /etc/init.d/netdata && \
- run chmod 755 /etc/init.d/netdata && \
- run chkconfig netdata on && \
- return 0
- else
- echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
- return 1
- fi
- elif [ -f /etc/init.d/netdata ]
- then
- echo >&2 "file '/etc/init.d/netdata' already exists."
- return 0
- else
- echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
- fi
-
- return 1
-}
-
-NETDATA_START_CMD="netdata"
-NETDATA_STOP_CMD="killall netdata"
-
-install_netdata_service() {
- local uname="$(uname 2>/dev/null)"
-
- if [ "${UID}" -eq 0 ]
- then
- if [ "${uname}" = "Darwin" ]
- then
-
- if [ -f "/Library/LaunchDaemons/com.github.netdata.plist" ]
- then
- echo >&2 "file '/Library/LaunchDaemons/com.github.netdata.plist' already exists."
- return 0
- else
- echo >&2 "Installing MacOS X plist file..."
- run cp system/netdata.plist /Library/LaunchDaemons/com.github.netdata.plist && \
- run launchctl load /Library/LaunchDaemons/com.github.netdata.plist && \
- return 0
- fi
-
- elif [ "${uname}" = "FreeBSD" ]
- then
-
- run cp system/netdata-freebsd /etc/rc.d/netdata && \
- NETDATA_START_CMD="service netdata start" && \
- NETDATA_STOP_CMD="service netdata stop" && \
- return 0
-
- elif issystemd
- then
- # systemd is running on this system
- NETDATA_START_CMD="systemctl start netdata"
- NETDATA_STOP_CMD="systemctl stop netdata"
-
- SYSTEMD_DIRECTORY=""
-
- if [ -d "/lib/systemd/system" ]
- then
- SYSTEMD_DIRECTORY="/lib/systemd/system"
- elif [ -d "/usr/lib/systemd/system" ]
- then
- SYSTEMD_DIRECTORY="/usr/lib/systemd/system"
- fi
-
- if [ "${SYSTEMD_DIRECTORY}x" != "x" ]
- then
- echo >&2 "Installing systemd service..."
- run cp system/netdata.service "${SYSTEMD_DIRECTORY}/netdata.service" && \
- run systemctl daemon-reload && \
- run systemctl enable netdata && \
- return 0
- else
- echo >&2 "no systemd directory; cannot install netdata.service"
- fi
- else
- install_non_systemd_init
- local ret=$?
-
- if [ ${ret} -eq 0 ]
- then
- if [ ! -z "${service_cmd}" ]
- then
- NETDATA_START_CMD="service netdata start"
- NETDATA_STOP_CMD="service netdata stop"
- elif [ ! -z "${rcservice_cmd}" ]
- then
- NETDATA_START_CMD="rc-service netdata start"
- NETDATA_STOP_CMD="rc-service netdata stop"
- fi
- fi
-
- return ${ret}
- fi
- fi
-
- return 1
-}
-
-
-# -----------------------------------------------------------------------------
-# stop netdata
-
-pidisnetdata() {
- if [ -d /proc/self ]
- then
- [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
- [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
- return 1
- fi
- return 0
-}
-
-stop_netdata_on_pid() {
- local pid="${1}" ret=0 count=0
-
- pidisnetdata ${pid} || return 0
-
- printf >&2 "Stopping netdata on pid ${pid} ..."
- while [ ! -z "$pid" -a ${ret} -eq 0 ]
- do
- if [ ${count} -gt 45 ]
- then
- echo >&2 "Cannot stop the running netdata on pid ${pid}."
- return 1
- fi
-
- count=$(( count + 1 ))
-
- run kill ${pid} 2>/dev/null
- ret=$?
-
- test ${ret} -eq 0 && printf >&2 "." && sleep 2
- done
-
- echo >&2
- if [ ${ret} -eq 0 ]
- then
- echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
- return 1
- fi
-
- echo >&2 "netdata on pid ${pid} stopped."
- return 0
-}
-
-netdata_pids() {
- local p myns ns
-
- myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
-
- # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
-
- for p in \
- $(cat /var/run/netdata.pid 2>/dev/null) \
- $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
- $(pidof netdata 2>/dev/null)
- do
- ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
-
- if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
- then
- pidisnetdata ${p} && echo "${p}"
- fi
- done
-}
-
-stop_all_netdata() {
- local p
- for p in $(netdata_pids)
- do
- stop_netdata_on_pid ${p}
- done
-}
-
-# -----------------------------------------------------------------------------
-# restart netdata
-
-restart_netdata() {
- local netdata="${1}"
- shift
-
- local started=0
-
- progress "Start netdata"
-
- if [ "${UID}" -eq 0 ]
- then
- service netdata stop
- stop_all_netdata
- service netdata restart && started=1
-
- if [ ${started} -eq 1 -a -z "$(netdata_pids)" ]
- then
- echo >&2 "Ooops! it seems netdata is not started."
- started=0
- fi
-
- if [ ${started} -eq 0 ]
- then
- service netdata start && started=1
- fi
- fi
-
- if [ ${started} -eq 1 -a -z "$(netdata_pids)" ]
- then
- echo >&2 "Hm... it seems netdata is still not started."
- started=0
- fi
-
- if [ ${started} -eq 0 ]
- then
- # still not started...
-
- run stop_all_netdata
- run "${netdata}" "${@}"
- return $?
- fi
-
- return 0
-}
-
-# -----------------------------------------------------------------------------
-# install netdata logrotate
-
-install_netdata_logrotate() {
- if [ ${UID} -eq 0 ]
- then
- if [ -d /etc/logrotate.d ]
- then
- if [ ! -f /etc/logrotate.d/netdata ]
- then
- run cp system/netdata.logrotate /etc/logrotate.d/netdata
- fi
-
- if [ -f /etc/logrotate.d/netdata ]
- then
- run chmod 644 /etc/logrotate.d/netdata
- fi
-
- return 0
- fi
- fi
-
- return 1
-}
-
-# -----------------------------------------------------------------------------
-# download netdata.conf
-
-fix_netdata_conf() {
- local owner="${1}"
-
- if [ "${UID}" -eq 0 ]
- then
- run chown "${owner}" "${filename}"
- fi
- run chmod 0664 "${filename}"
-}
-
-generate_netdata_conf() {
- local owner="${1}" filename="${2}" url="${3}"
-
- if [ ! -s "${filename}" ]
- then
- cat >"${filename}" <<EOFCONF
-# netdata can generate its own config.
-# Get it with:
-#
-# wget -O ${filename} "${url}"
-#
-# or
-#
-# curl -s -o ${filename} "${url}"
-#
-EOFCONF
- fix_netdata_conf "${owner}"
- fi
-}
-
-download_netdata_conf() {
- local owner="${1}" filename="${2}" url="${3}"
-
- if [ ! -s "${filename}" ]
- then
- echo >&2
- echo >&2 "-------------------------------------------------------------------------------"
- echo >&2
- echo >&2 "Downloading default configuration from netdata..."
- sleep 5
-
- # remove a possibly obsolete download
- [ -f "${filename}.new" ] && rm "${filename}.new"
-
- # disable a proxy to get data from the local netdata
- export http_proxy=
- export https_proxy=
-
- # try curl
- run curl -s -o "${filename}.new" "${url}"
- ret=$?
-
- if [ ${ret} -ne 0 -o ! -s "${filename}.new" ]
- then
- # try wget
- run wget -O "${filename}.new" "${url}"
- ret=$?
- fi
-
- if [ ${ret} -eq 0 -a -s "${filename}.new" ]
- then
- run mv "${filename}.new" "${filename}"
- run_ok "New configuration saved for you to edit at ${filename}"
- else
- [ -f "${filename}.new" ] && rm "${filename}.new"
- run_failed "Cannnot download configuration from netdata daemon using url '${url}'"
-
- generate_netdata_conf "${owner}" "${filename}" "${url}"
- fi
-
- fix_netdata_conf "${owner}"
- fi
-}
-
-
-# -----------------------------------------------------------------------------
-# add netdata user and group
-
-NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
-NETDATA_ADDED_TO_GROUPS=""
-add_netdata_user_and_group() {
- local homedir="${1}" g
-
- if [ ${UID} -eq 0 ]
- then
- portable_add_group netdata || return 1
- portable_add_user netdata "${homedir}" || return 1
-
- for g in ${NETDATA_WANTED_GROUPS}
- do
- portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
- done
-
- [ ~netdata = / ] && cat <<USERMOD
-
-The netdata user has its home directory set to /
-You may want to change it, using this command:
-
-# usermod -d "${homedir}" netdata
-
-USERMOD
- return 0
- fi
-
- return 1
-}