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