PKG_PROG_PKG_CONFIG
AC_USE_SYSTEM_EXTENSIONS
-AC_ARG_ENABLE(
- [daemon],
- [AS_HELP_STRING([--disable-daemon], [disable daemon])],
- ,
- [enable_daemon="yes"]
-)
AC_ARG_ENABLE(
[plugin-plugin-nfacct],
[AS_HELP_STRING([--enable-plugin-plugin-nfacct], [enable nfacct plugin, requires root])],
#!/bin/bash
+netdata=$(which netdata)
+
+if [ -z "${netdata}" -o ! -f src/netdata ]
+then
+ echo >&2 "Running ./autogen.sh ..."
+ ./autogen.sh || exit 1
+
+ echo >&2 "Running ./configure ..."
+ ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-zlib --with-math --with-user=netdata CFLAGS="-march=native -O3 -Wall -Wextra" || exit 1
+
+ echo >&2 "Compiling netdata ..."
+ make || exit 1
+fi
+
+if [ -z "${netdata}" -o src/netdata -nt "${netdata}" ]
+then
+ echo >&2 "Installing netdata ..."
+ make install
+
+ echo >&2 "Adding netdata group ..."
+ getent group netdata > /dev/null || groupadd -r netdata
+
+ echo >&2 "Adding netdata user ..."
+ getent passwd netdata > /dev/null || useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
+fi
+
+netdata=$(which netdata)
+
base="`dirname "$0"`"
if [ ! -d "${base}" ]
config_option() {
local key="${1}" value="${2}" line=
- if [ -s "conf.d/netdata.conf" ]
+ if [ -s "/etc/netdata/netdata.conf" ]
then
line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "conf.d/netdata.conf" | head -n 1 )"
[ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
}
# user
-defuser="nobody"
+defuser="netdata"
[ ! "${UID}" = "0" ] && defuser="${USER}"
NETDATA_USER="$( config_option "run as user" "${defuser}" )"
NETDATA_PORT="$( config_option "port" ${defport} )"
# directories
-NETDATA_CACHE_DIR="$( config_option "database directory" "cache" )"
-NETDATA_WEB_DIR="$( config_option "web files directory" "web" )"
+NETDATA_CACHE_DIR="$( config_option "database directory" "/var/cache/netdata" )"
+NETDATA_WEB_DIR="$( config_option "web files directory" "/usr/share/netdata/web" )"
NETDATA_LOG_DIR="log"
NETDATA_CONF_DIR="conf.d"
-# -----------------------------------------------------------------------------
-# compile netdata
-
-echo >&2 "Compiling netdata (debug flags = $NETDATA_DEBUG)..."
-if [ $[ NETDATA_DEBUG ] -ne 0 ]
- then
- make install debug=1 || exit 1 # this installs in the current directory
-
- # let netdata core dump if it crashes
- ulimit -c unlimited
-
-else
- make install || exit 1 # this installs in the current directory
-fi
-
-
# -----------------------------------------------------------------------------
# prepare the directories
export TZ=":/etc/localtime"
echo >&2 "Starting netdata..."
-`pwd`/netdata "${@}"
+netdata "${@}"
if [ $? -ne 0 ]
then
# -----------------------------------------------------------------------------
# save a config file, if it is not already there
-if [ ! -s conf.d/netdata.conf ]
+if [ ! -s /etc/netdata/netdata.conf ]
then
echo >&2 "Downloading default configuration from netdata..."
sleep 5
# remove a possibly obsolete download
- [ -f conf.d/netdata.conf.new ] && rm conf.d/netdata.conf.new
+ [ -f /etc/netdata/netdata.conf.new ] && rm /etc/netdata/netdata.conf.new
# try wget
- wget 2>/dev/null -O conf.d/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
+ wget 2>/dev/null -O /etc/netdata/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
ret=$?
# try curl
- if [ $ret -ne 0 -o ! -s conf.d/netdata.conf.net ]
+ if [ $ret -ne 0 -o ! -s /etc/netdata/netdata.conf.net ]
then
- curl -s -o conf.d/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
+ curl -s -o /etc/netdata/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
ret=$?
fi
- if [ $ret -eq 0 -a -s conf.d/netdata.conf.new ]
+ if [ $ret -eq 0 -a -s /etc/netdata/netdata.conf.new ]
then
- mv conf.d/netdata.conf.new conf.d/netdata.conf
- echo >&2 "New configuration saved for you to edit at conf.d/netdata.conf"
+ mv /etc/netdata/netdata.conf.new /etc/netdata/netdata.conf
+ echo >&2 "New configuration saved for you to edit at /etc/netdata/netdata.conf"
- chown -R "${NETDATA_USER}" conf.d/netdata.conf
- chmod 0664 conf.d/netdata.conf
+ chown "${NETDATA_USER}" /etc/netdata/netdata.conf
+ chmod 0664 /etc/netdata/netdata.conf
else
echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
- [ -f conf.d/netdata.conf.new ] && rm conf.d/netdata.conf.new
+ [ -f /etc/netdata/netdata.conf.new ] && rm /etc/netdata/netdata.conf.new
fi
fi
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
-#ifdef NETDATA_DAEMON
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
return(0);
}
-int become_daemon(int dont_fork, int close_all_files, const char *input, const char *output, const char *error, const char *access, int *access_fd, FILE **access_fp)
+int become_daemon(int dont_fork, int close_all_files, const char *user, const char *input, const char *output, const char *error, const char *access, int *access_fd, FILE **access_fp)
{
fflush(NULL);
if(input && *input) {
if((input_fd = open(input, O_RDONLY, 0666)) == -1) {
- fprintf(stderr, "Cannot open input file '%s' (%s).", input, strerror(errno));
+ fprintf(stderr, "Cannot open input file '%s' (%s).\n", input, strerror(errno));
return -1;
}
}
if(output && *output) {
if((output_fd = open(output, O_RDWR | O_APPEND | O_CREAT, 0666)) == -1) {
- fprintf(stderr, "Cannot open output log file '%s' (%s).", output, strerror(errno));
+ fprintf(stderr, "Cannot open output log file '%s' (%s).\n", output, strerror(errno));
if(input_fd != -1) close(input_fd);
return -1;
}
if(error && *error) {
if((error_fd = open(error, O_RDWR | O_APPEND | O_CREAT, 0666)) == -1) {
- fprintf(stderr, "Cannot open error log file '%s' (%s).", error, strerror(errno));
+ fprintf(stderr, "Cannot open error log file '%s' (%s).\n", error, strerror(errno));
if(input_fd != -1) close(input_fd);
if(output_fd != -1) close(output_fd);
return -1;
if(access && *access && access_fd) {
if((*access_fd = open(access, O_RDWR | O_APPEND | O_CREAT, 0666)) == -1) {
- fprintf(stderr, "Cannot open access log file '%s' (%s).", access, strerror(errno));
+ fprintf(stderr, "Cannot open access log file '%s' (%s).\n", access, strerror(errno));
if(input_fd != -1) close(input_fd);
if(output_fd != -1) close(output_fd);
if(error_fd != -1) close(error_fd);
}
}
+ if(user && *user) {
+ if(become_user(user) != 0) {
+ error("Cannot become user '%s'. Continuing as we are.", user);
+ }
+ else debug(D_OPTIONS, "Successfully became user '%s'.", user);
+ }
+
return(0);
}
-#endif
extern int become_user(const char *username);
-extern int become_daemon(int dont_fork, int close_all_files, const char *input, const char *output, const char *error, const char *access, int *access_fd, FILE **access_fp);
+extern int become_daemon(int dont_fork, int close_all_files, const char *user, const char *input, const char *output, const char *error, const char *access, int *access_fd, FILE **access_fp);
#endif /* NETDATA_DAEMON_H */
char *output_log_file = NULL;
char *error_log_file = NULL;
char *access_log_file = NULL;
+ char *user = NULL;
{
char buffer[1024];
// --------------------------------------------------------------------
prepare_rundir();
- char *user = config_get("global", "run as user", (getuid() == 0)?NETDATA_USER:"");
- if(*user) {
- if(become_user(user) != 0) {
- fprintf(stderr, "Cannot become user %s.\n", user);
- exit(1);
- }
- else debug(D_OPTIONS, "Successfully became user %s.", user);
- }
+ user = config_get("global", "run as user", (getuid() == 0)?NETDATA_USER:"");
// --------------------------------------------------------------------
// never become a problem
if(nice(20) == -1) fprintf(stderr, "Cannot lower my CPU priority. Error: %s.\n", strerror(errno));
-#ifdef NETDATA_DAEMON
- if(become_daemon(dont_fork, 0, input_log_file, output_log_file, error_log_file, access_log_file, &access_fd, &stdaccess) == -1) {
- fprintf(stderr, "Cannot demonize myself (%s).", strerror(errno));
+ if(become_daemon(dont_fork, 0, user, input_log_file, output_log_file, error_log_file, access_log_file, &access_fd, &stdaccess) == -1) {
+ fatal("Cannot demonize myself (%s).", strerror(errno));
exit(1);
}
-#endif
if(output_log_syslog || error_log_syslog || access_log_syslog)
openlog("netdata", LOG_PID, LOG_DAEMON);
#endif
#ifdef STORAGE_WITH_MATH
#include <math.h>
+#else
+#warning "You are building without math. math allows accurate calculations. It should be enabled."
#endif
#include "common.h"
#ifdef NETDATA_WITH_ZLIB
if(likely(w->zoutput)) sent = (long)w->zstream.total_out;
+#else
+#warning "You are building without zlib. zlib allows netdata to trasnfer a lot less data with web clients. It should be enabled."
#endif
long size = (w->mode == WEB_CLIENT_MODE_FILECOPY)?w->data->rbytes:w->data->bytes;