5 if [ ! -d "$base" -o ! -f "$base/netdata.c" -o ! -d "$base/web" ]
7 echo >&2 "Cannot find my home directory '${base}'."
12 # the detail of the data that will be kept in netdata
13 NETDATA_CONFIG_INTERNAL_UPDATE_EVERY=1
15 # how many entries to keep in memory
16 NETDATA_CONFIG_INTERNAL_HISTORY_LINES=3600
18 # the user to run netdata under
19 NETDATA_CONFIG_USER=nobody
21 # set to 1, to enable debugging
22 NETDATA_CONFIG_DEBUG=0
25 NETDATA_CONFIG_PORT=19999
27 if [ -f netdata.conf ]
29 x="`grep "\[global\]" netdata.conf`"
32 # import the old values
33 cat netdata.conf | grep ^NETDATA_CONFIG_ >netdata.conf.tmp
37 mv netdata.conf netdata.conf.old
38 echo "You are having an old config. Moved to netdata.conf.old"
40 # find if debug is enabled in the config
41 df=`grep -C 3 "\[debug\]" netdata.conf | grep "flags" | tail -n 1 | cut -d '=' -f 2 | sed s"/ //g"`
42 if [ -z "$df" -o "$df" = "0x00000000" -o $((df + 1 - 1)) -eq 0 ]
44 NETDATA_CONFIG_DEBUG=0
46 NETDATA_CONFIG_DEBUG=1
49 # find the user to run as
50 NETDATA_CONFIG_USER="`grep 'run as user = ' netdata.conf | head -n 1 | cut -d '=' -f 2 | sed s"/ //g"`"
54 echo "Compiling netdata (debug=$NETDATA_CONFIG_DEBUG)"
55 if [ $NETDATA_CONFIG_DEBUG -eq 1 ]
58 gcc -Wall -ggdb -o netdata netdata.c -lpthread -lz || exit 1
59 debug_opts="-df 0xfffffadf -dl netdata.log"
61 gcc -Wall -O3 -o netdata netdata.c -lpthread -lz || exit 1
62 debug_opts="-df 0x00000000"
65 echo "Stopping a (possibly) running netdata..."
66 killall netdata 2>/dev/null
67 killall tc-all.sh 2>/dev/null
70 if [ "$USER" = "root" -a ! -z "$NETDATA_CONFIG_USER" ]
72 chown -R "$NETDATA_CONFIG_USER" web || exit 1
73 chmod 0775 web || exit 1
74 chmod -R 0664 web/* || exit 1
77 echo "Starting netdata..."
78 if [ -f netdata.conf ]
84 if [ "$USER" = "root" ]
86 `pwd`/netdata $debug_opts -d -u $NETDATA_CONFIG_USER -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
88 echo >&2 "WARNING: NOT RUNNING AS ROOT - CANNOT SWITCH TO USER $NETDATA_CONFIG_USER"
89 echo >&2 "WARNING: MAKE SURE FILES IN web/ ARE OWNED BY $USER - or it will not work"
90 `pwd`/netdata $debug_opts -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
94 wget 2>/dev/null -O netdata.conf.new http://localhost:$NETDATA_CONFIG_PORT/netdata.conf
95 mv netdata.conf.new netdata.conf
97 echo "Hit http://127.0.0.1:$NETDATA_CONFIG_PORT/ from your browser."
98 echo "You can edit config options in file netdata.conf"