]> arthur.barton.de Git - netdata.git/commitdiff
removed NETDATA_DAEMON - it can be controlled via command line; now it opens log...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 15 Nov 2015 22:49:53 +0000 (00:49 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 15 Nov 2015 22:49:53 +0000 (00:49 +0200)
configure.ac
netdata.start
src/daemon.c
src/daemon.h
src/main.c
src/storage_number.c
src/web_client.c

index fbfbec6e7003d826f6b64b0b4b6f2d23e3e565eb..56279792a65e46d9e050c3802974c4c12e3c005e 100644 (file)
@@ -26,12 +26,6 @@ AC_PROG_INSTALL
 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])],
index b8fa2f9e0f92273524656ad2372c5229336fd914..c12608980a7dda5e58225927331d8c224ce68cc1 100755 (executable)
@@ -1,5 +1,33 @@
 #!/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}" ]
@@ -20,7 +48,7 @@ cd "${base}" || exit 1
 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" )"
@@ -30,7 +58,7 @@ config_option() {
 }
 
 # user
-defuser="nobody"
+defuser="netdata"
 [ ! "${UID}" = "0" ] && defuser="${USER}"
 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
 
@@ -43,28 +71,12 @@ defport=19999
 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
 
@@ -110,7 +122,7 @@ echo >&2
 export TZ=":/etc/localtime"
 
 echo >&2 "Starting netdata..."
-`pwd`/netdata "${@}"
+netdata "${@}"
 
 if [ $? -ne 0 ]
        then
@@ -125,35 +137,35 @@ fi
 # -----------------------------------------------------------------------------
 # 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
 
index 19c7657e912b3c263c82c79c3bfb544b3ff9a1a5..e2315f0b6b9392658d29a604a44bc2cc21473a72 100755 (executable)
@@ -1,7 +1,6 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
-#ifdef NETDATA_DAEMON
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -142,7 +141,7 @@ int become_user(const char *username)
        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);
 
@@ -151,14 +150,14 @@ int become_daemon(int dont_fork, int close_all_files, const char *input, const c
 
        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;
                }
@@ -166,7 +165,7 @@ int become_daemon(int dont_fork, int close_all_files, const char *input, const c
 
        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;
@@ -175,7 +174,7 @@ int become_daemon(int dont_fork, int close_all_files, const char *input, const c
 
        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);
@@ -316,6 +315,12 @@ int become_daemon(int dont_fork, int close_all_files, const char *input, const c
                }
        }
 
+       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
index 5821163c59f1ca3cc05e007ea4cbfb8c7a813d4f..9f8694f9580a44581b5cd5a6afe598e33e276a94 100755 (executable)
@@ -7,6 +7,6 @@ extern void prepare_rundir();
 
 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 */
index 138277df4645654033ef89fca7a0870f5de728be..44dff9d744491e5e4a52935e2aa3bc3d4858fbe0 100755 (executable)
@@ -239,6 +239,7 @@ int main(int argc, char **argv)
        char *output_log_file = NULL;
        char *error_log_file = NULL;
        char *access_log_file = NULL;
+       char *user = NULL;
        {
                char buffer[1024];
 
@@ -343,14 +344,7 @@ int main(int argc, char **argv)
                // --------------------------------------------------------------------
 
                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:"");
 
                // --------------------------------------------------------------------
 
@@ -382,12 +376,10 @@ int main(int argc, char **argv)
        // 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);
index fe8e4f1f70e6be8b6f6922cadf0445e2a712cb6a..823619e61f6dadd9d31f646d8c4b9806eb012123 100755 (executable)
@@ -3,6 +3,8 @@
 #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"
index 48fd47be4bd51cec3ab9edbc6637ec9eb64b64b7..0e18f7ac589d5286c245b67049263d92e0bb19f7 100755 (executable)
@@ -229,6 +229,8 @@ void web_client_reset(struct web_client *w)
 
 #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;