fix for initial download of the config file #10
Costa Tsaousis (ktsaou) committed
Oct 18, 2015 at 13:16 UTC
69be840e24acc4025eb2fe784e66d03dd4f23d7b
1 file changed
+29
-4
netdata.start
+29
-4
@@ -13,10 +13,14 @@ cd "${base}" || exit 1
13
# -----------------------------------------------------------------------------
14
# load options from the configuration file
15
16
+# create an empty config if it does not exist
17
+[ ! -f conf.d/netdata.conf ] && touch conf.d/netdata.conf
18
+
19
+# function to extract values from the config file
20
config_option() {
21
local key="${1}" value="${2}" line=
22
19
- if [ -f "conf.d/netdata.conf" ]
23
+ if [ -s "conf.d/netdata.conf" ]
24
then
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" )"
@@ -109,27 +113,48 @@ if [ $? -ne 0 ]
113
echo >&2
114
echo >&2 "SORRY! FAILED TO START NETDATA!"
115
exit 1
116
+else
117
+ echo >&2 "OK. NetData Started!"
118
fi
119
120
121
# -----------------------------------------------------------------------------
122
# save a config file, if it is not already there
123
118
-if [ ! -f conf.d/netdata.conf ]
124
+if [ ! -s conf.d/netdata.conf ]
125
then
126
+ echo >&2 "Downloading default configuration from netdata..."
127
sleep 5
128
+
129
+ # remove a possibly obsolete download
130
+ [ -f conf.d/netdata.conf.new ] && rm conf.d/netdata.conf.new
131
+
132
+ # try wget
133
wget 2>/dev/null -O conf.d/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
122
- if [ $? -eq 0 -a -s conf.d/netdata.conf.new ]
134
+ ret=$?
135
+
136
+ # try curl
137
+ if [ $ret -ne 0 -o ! -s conf.d/netdata.conf.net ]
138
+ then
139
+ curl -s -o conf.d/netdata.conf.new "http://localhost:${NETDATA_PORT}/netdata.conf"
140
+ ret=$?
141
+ fi
142
+
143
+ if [ $ret -eq 0 -a -s conf.d/netdata.conf.new ]
144
then
145
mv conf.d/netdata.conf.new conf.d/netdata.conf
146
echo >&2 "New configuration saved for you to edit at conf.d/netdata.conf"
147
+
148
+ chown -R "${NETDATA_USER}" conf.d/netdata.conf
149
+ chmod 0664 conf.d/netdata.conf
150
else
151
+ echo >&2 "Cannnot download configuration from netdata daemon!"
152
rm conf.d/netdata.conf.new
153
fi
154
fi
155
156
echo >&2
132
-echo >&2 "OK. NetData started! Hit http://localhost:${NETDATA_PORT}/ from your browser."
157
+echo >&2 "Hit http://localhost:${NETDATA_PORT}/ from your browser."
158
echo >&2
159
echo >&2 "Enjoy..."
160
echo >&2