7 echo >&2 "Cannot find my home directory '${base}'."
10 cd "${base}" || exit 1
13 # -----------------------------------------------------------------------------
14 # load options from the configuration file
16 # create an empty config if it does not exist
17 [ ! -f conf.d/netdata.conf ] && touch conf.d/netdata.conf
19 # function to extract values from the config file
21 local key="${1}" value="${2}" line=
23 if [ -s "conf.d/netdata.conf" ]
25 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "conf.d/netdata.conf" | head -n 1 )"
26 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
34 [ ! "${UID}" = "0" ] && defuser="${USER}"
35 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
39 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
43 NETDATA_PORT="$( config_option "port" ${defport} )"
46 NETDATA_CACHE_DIR="$( config_option "database directory" "cache" )"
47 NETDATA_WEB_DIR="$( config_option "web files directory" "web" )"
49 NETDATA_CONF_DIR="conf.d"
52 # -----------------------------------------------------------------------------
55 echo >&2 "Compiling netdata (debug flags = $NETDATA_DEBUG)..."
56 if [ $[ NETDATA_DEBUG ] -ne 0 ]
58 make install debug=1 || exit 1 # this installs in the current directory
60 # let netdata core dump if it crashes
64 make install || exit 1 # this installs in the current directory
68 # -----------------------------------------------------------------------------
69 # prepare the directories
71 echo >&2 "Fixing directory permissions for user ${NETDATA_USER}..."
72 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"
76 mkdir "${x}" || exit 1
78 chown -R "${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
79 chmod 0775 "${x}" "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
83 # -----------------------------------------------------------------------------
84 # stop a running netdata
86 printf >&2 "Stopping a (possibly) running netdata..."
93 echo >&2 "Cannot stop the running netdata."
98 killall netdata 2>/dev/null
100 test $ret -eq 0 && printf >&2 "." && sleep 2
105 # -----------------------------------------------------------------------------
108 # avoid extended stat(/etc/localtime)
109 # http://stackoverflow.com/questions/4554271/how-to-avoid-excessive-stat-etc-localtime-calls-in-strftime-on-linux
110 export TZ=":/etc/localtime"
112 echo >&2 "Starting netdata..."
118 echo >&2 "SORRY! FAILED TO START NETDATA!"
121 echo >&2 "OK. NetData Started!"
125 # -----------------------------------------------------------------------------
126 # save a config file, if it is not already there
128 if [ ! -s conf.d/netdata.conf ]
130 echo >&2 "Downloading default configuration from netdata..."
133 # remove a possibly obsolete download
134 [ -f conf.d/netdata.conf.new ] && rm conf.d/netdata.conf.new
137 wget 2>/dev/null -O conf.d/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
141 if [ $ret -ne 0 -o ! -s conf.d/netdata.conf.net ]
143 curl -s -o conf.d/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
147 if [ $ret -eq 0 -a -s conf.d/netdata.conf.new ]
149 mv conf.d/netdata.conf.new conf.d/netdata.conf
150 echo >&2 "New configuration saved for you to edit at conf.d/netdata.conf"
152 chown -R "${NETDATA_USER}" conf.d/netdata.conf
153 chmod 0664 conf.d/netdata.conf
155 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
156 [ -f conf.d/netdata.conf.new ] && rm conf.d/netdata.conf.new
161 echo >&2 "Hit http://localhost:${NETDATA_PORT}/ from your browser."