]> arthur.barton.de Git - netdata.git/blob - netdata.start
added mmap() support for all data, so that netdata can be restarted and continue...
[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=3600
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 # our web files
28 NETDATA_CONFIG_WEB_DIR=web
29
30 if [ ! -d log ]
31 then
32         mkdir log || exit 1
33 fi
34
35 if [ ! -d conf.d ]
36 then
37         mkdir conf.d || exit 1
38 fi
39
40 if [ ! -d cache ]
41 then
42         mkdir cache || exit 1
43 fi
44
45 if [ -f conf.d/netdata.conf ]
46 then
47         # find if debug is enabled in the config
48         df=`grep "debug flags = " conf.d/netdata.conf | tail -n 1 | cut -d '=' -f 2 | sed s"/ //g"`
49         if [ -z "$df" -o "$df" = "0x00000000" -o $((df + 1 - 1)) -eq 0 ]
50         then
51                 NETDATA_CONFIG_DEBUG=0
52         else
53                 NETDATA_CONFIG_DEBUG=1
54         fi
55
56         # find the user to run as
57         NETDATA_CONFIG_USER="`grep 'run as user = ' conf.d/netdata.conf | head -n 1 | cut -d '=' -f 2 | sed s"/ //g"`"
58         NETDATA_CONFIG_WEB_DIR="`grep 'web files directory = ' conf.d/netdata.conf | head -n 1 | cut -d '=' -f 2 | sed -e s"/^ \+//g" -e s"/ \+$//g"`"
59 fi
60
61 echo "Compiling netdata (debug=$NETDATA_CONFIG_DEBUG)"
62 if [ $NETDATA_CONFIG_DEBUG -eq 1 ]
63 then
64         ulimit -c unlimited
65         make debug=1 || exit 1
66         debug_opts="-df 0xfffffadf"
67 else
68         make || exit 1
69         debug_opts="-df 0x00000000"
70 fi
71
72 echo "Stopping a (possibly) running netdata..."
73 killall netdata 2>/dev/null
74 sleep 2
75
76 if [ "$USER" = "root" -a ! -z "$NETDATA_CONFIG_USER" -a -d "$NETDATA_CONFIG_WEB_DIR" ]
77 then
78         echo "Chaning ownership of web files in $NETDATA_CONFIG_WEB_DIR to $NETDATA_CONFIG_USER"
79         chown -R "$NETDATA_CONFIG_USER" "$NETDATA_CONFIG_WEB_DIR" conf.d log || exit 1
80         chmod    0775 "$NETDATA_CONFIG_WEB_DIR" || exit 1
81 fi
82
83 if [ ! "$USER" = "root" ]
84 then
85         echo >&2 "WARNING: NOT RUNNING AS ROOT - CANNOT SWITCH TO USER $NETDATA_CONFIG_USER"
86         echo >&2 "WARNING: MAKE SURE FILES IN web/ ARE OWNED BY $USER - or it will not work"
87 fi
88
89 echo "Starting netdata..."
90 if [ -f conf.d/netdata.conf ]
91 then
92         `pwd`/netdata
93 else
94         touch conf.d/netdata.conf
95
96         if [ "$USER" = "root" ]
97         then
98                 `pwd`/netdata $debug_opts -u $NETDATA_CONFIG_USER -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
99         else
100                 `pwd`/netdata $debug_opts -t $NETDATA_CONFIG_INTERNAL_UPDATE_EVERY -l $NETDATA_CONFIG_INTERNAL_HISTORY_LINES -p $NETDATA_CONFIG_PORT || exit 1
101         fi
102
103         sleep 2
104         wget 2>/dev/null -O conf.d/netdata.conf.new http://localhost:$NETDATA_CONFIG_PORT/netdata.conf
105         mv conf.d/netdata.conf.new conf.d/netdata.conf
106
107         echo "Hit http://127.0.0.1:$NETDATA_CONFIG_PORT/ from your browser."
108         echo "You can edit config options in file conf.d/netdata.conf"
109 fi
110
111 echo
112 echo "All Done."
113 echo