summaryrefslogtreecommitdiffstats
path: root/netdata-installer.sh
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2015-11-17 22:06:15 +0200
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2015-11-17 22:06:15 +0200
commit1b68ee4b7b809471f52a63708d4fc020dbc93ee0 (patch)
tree153cc34ab8a733c5800005d8da65086ad0601dc7 /netdata-installer.sh
parent552153eded43a925c20417ae0df5e9fa66f9bc2a (diff)
updated installer
Diffstat (limited to 'netdata-installer.sh')
-rwxr-xr-xnetdata-installer.sh122
1 files changed, 76 insertions, 46 deletions
diff --git a/netdata-installer.sh b/netdata-installer.sh
index 3027b213a8..8dbb488ddc 100755
--- a/netdata-installer.sh
+++ b/netdata-installer.sh
@@ -1,5 +1,23 @@
#!/bin/bash
+cat <<BANNER
+
+
+This script will build and install netdata to your system.
+
+By default netdata will be installed as any other package.
+If you want to install it to another directory, run me
+with the option:
+
+$0 --install /path/to/install
+
+A new directory called netdata will be created as
+
+/path/to/install/netdata
+
+
+BANNER
+
if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
then
echo >&2
@@ -7,13 +25,23 @@ if [ ! "${UID}" = 0 -o "$1" = "-h" -o "$1" = "--help" ]
echo >&2 "The netdata daemon will drop priviliges"
echo >&2 "but you have to start it as root."
echo >&2
- echo >&2 "If netdata is not already installed,"
- echo >&2 "this script will also build and install"
- echo >&2 "netdata to your system."
- echo >&2
exit 1
fi
+NETDATA_PREFIX=
+if [ "$1" = "--install" ]
+ then
+ NETDATA_PREFIX="${2}/netdata"
+ shift 2
+fi
+
+if [ ! -z "${NETDATA_PREFIX}" ]
+ then
+ read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
+else
+ read -p "Press ENTER to build and install netdata to your system > "
+fi
+
# reload the profile
[ -f /etc/profile ] && . /etc/profile
@@ -28,8 +56,9 @@ You many need to check these:
1. The package zlib1g-dev has to be installed.
-2. You need basic build tools installed, like: gcc, autoconf,
- pgk-config, automake, etc.
+2. You need basic build tools installed, like:
+
+ gcc autoconf automake pgk-config
3. If your system cannot find ZLIB, although it is installed
run me with the option: --zlib-is-really-here
@@ -63,33 +92,33 @@ if [ "$1" = "--zlib-is-really-here" ]
export ZLIB_LIBS="-lz"
fi
-if [ ! -f src/Makefile ]
- then
- read -p "Netdata is not configured. Press ENTER to configure it > "
-
- trap build_error EXIT
+trap build_error EXIT
- echo >&2 "Running ./autogen.sh ..."
- run ./autogen.sh || exit 1
+echo >&2 "Running ./autogen.sh ..."
+run ./autogen.sh || exit 1
- echo >&2 "Running ./configure ..."
- run ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-zlib --with-math --with-user=netdata CFLAGS="-march=native -O3" || exit 1
+echo >&2 "Running ./configure ..."
+run ./configure \
+ --prefix="${NETDATA_PREFIX}/usr" \
+ --sysconfdir="${NETDATA_PREFIX}/etc" \
+ --localstatedir="${NETDATA_PREFIX}/var" \
+ --with-zlib --with-math --with-user=netdata \
+ CFLAGS="-march=native -O3" || exit 1
- # remove the build_error hook
- trap - EXIT
+# remove the build_error hook
+trap - EXIT
- if [ -f src/netdata ]
- then
- echo >&2 "Cleaning a possibly old compilation ..."
- make clean
- fi
+if [ -f src/netdata ]
+ then
+ echo >&2 "Cleaning a possibly old compilation ..."
+ run make clean
fi
echo >&2 "Compiling netdata ..."
run make || exit 1
echo >&2 "Installing netdata ..."
-run make install
+run make install || exit 1
echo >&2 "Adding netdata user group ..."
getent group netdata > /dev/null || run groupadd -r netdata
@@ -103,15 +132,15 @@ getent passwd netdata > /dev/null || run useradd -r -g netdata -c netdata -s /sb
# load options from the configuration file
# create an empty config if it does not exist
-[ ! -f /etc/netdata/netdata.conf ] && touch /etc/netdata/netdata.conf
+[ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
# function to extract values from the config file
config_option() {
local key="${1}" value="${2}" line=
- if [ -s "/etc/netdata/netdata.conf" ]
+ if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
then
- line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "/etc/netdata/netdata.conf" | head -n 1 )"
+ line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
[ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
fi
@@ -132,10 +161,10 @@ defport=19999
NETDATA_PORT="$( config_option "port" ${defport} )"
# directories
-NETDATA_CACHE_DIR="$( config_option "cache directory" "/var/cache/netdata" )"
-NETDATA_WEB_DIR="$( config_option "web files directory" "/usr/share/netdata/web" )"
-NETDATA_LOG_DIR="$( config_option "log directory" "/var/log/netdata" )"
-NETDATA_CONF_DIR="$( config_option "config directory" "/etc/netdata" )"
+NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
+NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
+NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
+NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
# -----------------------------------------------------------------------------
@@ -149,12 +178,13 @@ do
echo >&2 "Creating directory '${x}'"
run mkdir -p "${x}" || exit 1
fi
- run chown -R "${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
+ run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
run chmod 0775 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
done
# fix apps.plugin to be setuid to root
-run chown root '/usr/libexec/netdata/plugins.d/apps.plugin' && run chmod 4755 '/usr/libexec/netdata/plugins.d/apps.plugin'
+run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
+run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
# -----------------------------------------------------------------------------
@@ -172,7 +202,7 @@ do
fi
count=$((count + 1))
- killall netdata 2>/dev/null
+ run killall netdata 2>/dev/null
ret=$?
test $ret -eq 0 && printf >&2 "." && sleep 2
done
@@ -183,7 +213,7 @@ echo >&2
# run netdata
echo >&2 "Starting netdata..."
-netdata "${@}"
+run ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
if [ $? -ne 0 ]
then
@@ -198,35 +228,35 @@ fi
# -----------------------------------------------------------------------------
# save a config file, if it is not already there
-if [ ! -s /etc/netdata/netdata.conf ]
+if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
then
echo >&2 "Downloading default configuration from netdata..."
sleep 5
# remove a possibly obsolete download
- [ -f /etc/netdata/netdata.conf.new ] && rm /etc/netdata/netdata.conf.new
+ [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
# try wget
- wget 2>/dev/null -O /etc/netdata/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
+ wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
ret=$?
# try curl
- if [ $ret -ne 0 -o ! -s /etc/netdata/netdata.conf.net ]
+ if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
then
- curl -s -o /etc/netdata/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
+ curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
ret=$?
fi
- if [ $ret -eq 0 -a -s /etc/netdata/netdata.conf.new ]
+ if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
then
- mv /etc/netdata/netdata.conf.new /etc/netdata/netdata.conf
- echo >&2 "New configuration saved for you to edit at /etc/netdata/netdata.conf"
+ mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
+ echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
- chown "${NETDATA_USER}" /etc/netdata/netdata.conf
- chmod 0664 /etc/netdata/netdata.conf
+ chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
+ chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
else
echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
- [ -f /etc/netdata/netdata.conf.new ] && rm /etc/netdata/netdata.conf.new
+ [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
fi
fi
@@ -245,7 +275,7 @@ To stop netdata, just kill it, with:
To start it, just run it:
- netdata
+ ${NETDATA_PREFIX}/usr/sbin/netdata
Enjoy!