]> arthur.barton.de Git - netdata.git/blob - netdata.start
handle non hex debug flags value
[netdata.git] / netdata.start
1 #!/bin/bash
2
3 base="`dirname "$0"`"
4
5 if [ ! -d "$base" -o ! -f "$base/netdata.c" -o ! -d "$base/web" ]
6 then
7         echo >&2 "Cannot find my home directory '${base}'."
8         exit 1
9 fi
10 cd "$base" || exit 1
11
12 # the detail of the data that will be kept in netdata
13 NETDATA_CONFIG_INTERNAL_UPDATE_EVERY=1
14
15 # how many entries to keep in memory
16 NETDATA_CONFIG_INTERNAL_HISTORY_LINES=2400
17
18 # the user to run netdata under
19 NETDATA_CONFIG_USER=nobody
20
21 # set to 1, to enable debugging
22 NETDATA_CONFIG_DEBUG=0
23
24 # our port
25 NETDATA_CONFIG_PORT=19999
26
27 if [ -f netdata.conf ]
28 then
29         x="`grep "\[global\]" netdata.conf`"
30         if [ -z "$x" ]
31         then
32                 # import the old values
33                 cat netdata.conf | grep ^NETDATA_CONFIG_ >netdata.conf.tmp
34                 . netdata.conf.tmp
35                 rm netdata.conf.tmp
36
37                 mv netdata.conf netdata.conf.old
38                 echo "You are having an old config. Moved to netdata.conf.old"
39         else
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 ]
43                 then
44                         NETDATA_CONFIG_DEBUG=0
45                 else
46                         NETDATA_CONFIG_DEBUG=1
47                 fi
48         fi
49 fi
50
51 echo "Compiling netdata (debug=$NETDATA_CONFIG_DEBUG)"
52 if [ $NETDATA_CONFIG_DEBUG -eq 1 ]
53 then
54         ulimit -c unlimited
55         gcc -Wall -ggdb -o netdata netdata.c -lpthread -lz || exit 1
56         debug_opts="-df 0xfffffadf -dl netdata.log"
57 else
58         gcc -Wall -O3 -o netdata netdata.c -lpthread -lz || exit 1
59         debug_opts="-df 0x00000000"
60 fi
61
62 echo "Stopping a (possibly) running netdata..."
63 killall netdata 2>/dev/null
64 killall tc-all.sh 2>/dev/null
65 sleep 2
66
67 echo "Starting netdata..."
68 if [ -f netdata.conf ]
69 then
70         `pwd`/netdata
71 else
72         touch netdata.conf
73
74         if [ "$USER" = "root" ]
75         then
76                 chown -R "$NETDATA_CONFIG_USER" web || exit 1
77                 chmod    0775 web   || exit 1
78                 chmod -R 0664 web/* || exit 1
79                 `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
80         else
81                 echo >&2 "WARNING: NOT RUNNING AS ROOT - CANNOT SWITCH TO USER $NETDATA_CONFIG_USER"
82                 echo >&2 "WARNING: MAKE SURE FILES IN web/ ARE OWNED BY $USER - or it will not work"
83                 `pwd`/netdata $debug_opts -d -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
84         fi
85
86         sleep 2
87         wget 2>/dev/null -O netdata.conf.new http://localhost:$NETDATA_CONFIG_PORT/netdata.conf
88         mv netdata.conf.new netdata.conf
89
90         echo "Hit http://127.0.0.1:$NETDATA_CONFIG_PORT/ from your browser."
91         echo "You can edit config options in file netdata.conf"
92 fi
93
94 echo
95 echo "All Done."
96 echo