both installers download configuration from netdata.conf and provide a sane default when this is not possible
Costa Tsaousis (ktsaou) committed
Dec 14, 2017 at 01:37 UTC
28b86c731d9ecb6b72238a5367b3f824d51c75a1
6 files changed
+129
-84
installer/functions.sh
+81
-3
@@ -639,6 +639,84 @@ install_netdata_logrotate() {
639
return 1
640
}
641
642
+# -----------------------------------------------------------------------------
643
+# download netdata.conf
644
+
645
+fix_netdata_conf() {
646
+ local owner="${1}"
647
+
648
+ if [ "${UID}" -eq 0 ]
649
+ then
650
+ run chown "${owner}" "${filename}"
651
+ fi
652
+ run chmod 0664 "${filename}"
653
+}
654
+
655
+generate_netdata_conf() {
656
+ local owner="${1}" filename="${2}" url="${3}"
657
+
658
+ if [ ! -s "${filename}" ]
659
+ then
660
+ cat >"${filename}" <<EOFCONF
661
+# netdata can generate its own config.
662
+# Get it with:
663
+#
664
+# wget -O ${filename} "${url}"
665
+#
666
+# or
667
+#
668
+# curl -s -o ${filename} "${url}"
669
+#
670
+EOFCONF
671
+ fix_netdata_conf "${owner}"
672
+ fi
673
+}
674
+
675
+download_netdata_conf() {
676
+ local owner="${1}" filename="${2}" url="${3}"
677
+
678
+ if [ ! -s "${filename}" ]
679
+ then
680
+ echo >&2
681
+ echo >&2 "-------------------------------------------------------------------------------"
682
+ echo >&2
683
+ echo >&2 "Downloading default configuration from netdata..."
684
+ sleep 5
685
+
686
+ # remove a possibly obsolete download
687
+ [ -f "${filename}.new" ] && rm "${filename}.new"
688
+
689
+ # disable a proxy to get data from the local netdata
690
+ export http_proxy=
691
+ export https_proxy=
692
+
693
+ # try curl
694
+ run curl -s -o "${filename}.new" "${url}"
695
+ ret=$?
696
+
697
+ if [ ${ret} -ne 0 -o ! -s "${filename}.new" ]
698
+ then
699
+ # try wget
700
+ run wget -O "${filename}.new" "${url}"
701
+ ret=$?
702
+ fi
703
+
704
+ if [ ${ret} -eq 0 -a -s "${filename}.new" ]
705
+ then
706
+ run mv "${filename}.new" "${filename}"
707
+ run_ok "New configuration saved for you to edit at ${filename}"
708
+ else
709
+ [ -f "${filename}.new" ] && rm "${filename}.new"
710
+ run_failed "Cannnot download configuration from netdata daemon using url '${url}'"
711
+
712
+ generate_netdata_conf "${owner}" "${filename}" "${url}"
713
+ fi
714
+
715
+ fix_netdata_conf "${owner}"
716
+ fi
717
+}
718
+
719
+
720
# -----------------------------------------------------------------------------
721
# add netdata user and group
722
@@ -654,15 +732,15 @@ add_netdata_user_and_group() {
732
if [ ${UID} -eq 0 ]
733
then
734
portable_add_group netdata || return 1
657
- portable_add_user netdata || return 1
735
+ portable_add_user netdata || return 1
736
portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
737
portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
738
portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
739
portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
740
portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
741
portable_add_user_to_group nsd netdata && NETDATA_ADDED_TO_NSD=1
664
- portable_add_user_to_group proxy netdata && NETDATA_ADDED_TO_PROXY=1
665
- portable_add_user_to_group squid netdata && NETDATA_ADDED_TO_SQUID=1
742
+ portable_add_user_to_group proxy netdata && NETDATA_ADDED_TO_PROXY=1
743
+ portable_add_user_to_group squid netdata && NETDATA_ADDED_TO_SQUID=1
744
return 0
745
fi
746
makeself/install-or-update.sh
+2
@@ -162,7 +162,9 @@ progress "starting netdata"
162
restart_netdata "/opt/netdata/bin/netdata"
163
if [ $? -eq 0 ]
164
then
165
+ download_netdata_conf "${NETDATA_USER}:${NETDATA_GROUP}" "/opt/netdata/etc/netdata/netdata.conf" "http://localhost:19999/netdata.conf"
166
netdata_banner "is installed and running now!"
167
else
168
+ generate_netdata_conf "${NETDATA_USER}:${NETDATA_GROUP}" "/opt/netdata/etc/netdata/netdata.conf" "http://localhost:19999/netdata.conf"
169
netdata_banner "is installed now!"
170
fi
makeself/jobs/70-netdata-git.install.sh
+4
@@ -16,8 +16,12 @@ run ./netdata-installer.sh --install "${NETDATA_INSTALL_PARENT}" \
16
--dont-start-it \
17
${NULL}
18
19
+# delete the generated netdata.conf, so that the static installer will generate a new one
20
+rm "${NETDATA_INSTALL_PATH}/etc/netdata/netdata.conf"
21
+
22
if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
23
then
24
run strip ${NETDATA_INSTALL_PATH}/bin/netdata
25
run strip ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/apps.plugin
26
+ run strip ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/cgroup-network
27
fi
makeself/jobs/99-makeself.install.sh
+39
-29
@@ -2,12 +2,44 @@
2
3
. $(dirname "${0}")/../functions.sh "${@}" || exit 1
4
5
+run cd "${NETDATA_SOURCE_PATH}" || exit 1
6
+
7
+# -----------------------------------------------------------------------------
8
+# find the netdata version
9
+
10
+NOWNER="unknown"
11
+ORIGIN="$(git config --get remote.origin.url || echo "unknown")"
12
+if [[ "${ORIGIN}" =~ ^git@github.com:.*/netdata.*$ ]]
13
+ then
14
+ NOWNER="${ORIGIN/git@github.com:/}"
15
+ NOWNER="${NOWNER/\/netdata*/}"
16
+
17
+elif [[ "${ORIGIN}" =~ ^https://github.com/.*/netdata.*$ ]]
18
+ then
19
+ NOWNER="${ORIGIN/https:\/\/github.com\//}"
20
+ NOWNER="${NOWNER/\/netdata*/}"
21
+fi
22
+
23
+# make sure it does not have any slashes in it
24
+NOWNER="${NOWNER//\//_}"
25
+
26
+if [ "${NOWNER}" = "firehol" ]
27
+ then
28
+ NOWNER=
29
+else
30
+ NOWNER="-${NOWNER}"
31
+fi
32
+
33
+VERSION="$(git describe || echo "undefined")"
34
+[ -z "${VERSION}" ] && VERSION="undefined"
35
+
36
+FILE_VERSION="${VERSION}-$(uname -m)-$(date +"%Y%m%d-%H%M%S")${NOWNER}"
37
+
38
39
# -----------------------------------------------------------------------------
40
# copy the files needed by makeself installation
41
42
run mkdir -p "${NETDATA_INSTALL_PATH}/system"
10
-run cd "${NETDATA_SOURCE_PATH}" || exit 1
43
44
cp \
45
makeself/post-installer.sh \
@@ -65,6 +97,9 @@ rm "${NETDATA_INSTALL_PATH}/sbin" \
97
# -----------------------------------------------------------------------------
98
# create the makeself archive
99
100
+cat "${NETDATA_MAKESELF_PATH}/makeself.lsm" |\
101
+ sed "s|NETDATA_VERSION|${FILE_VERSION}|g" >"${NETDATA_MAKESELF_PATH}/makeself.lsm.tmp"
102
+
103
"${NETDATA_MAKESELF_PATH}/makeself.sh" \
104
--gzip \
105
--complevel 9 \
@@ -72,7 +107,7 @@ rm "${NETDATA_INSTALL_PATH}/sbin" \
107
--needroot \
108
--target "${NETDATA_INSTALL_PATH}" \
109
--header "${NETDATA_MAKESELF_PATH}/makeself-header.sh" \
75
- --lsm "${NETDATA_MAKESELF_PATH}/makeself.lsm" \
110
+ --lsm "${NETDATA_MAKESELF_PATH}/makeself.lsm.tmp" \
111
--license "${NETDATA_MAKESELF_PATH}/makeself-license.txt" \
112
--help-header "${NETDATA_MAKESELF_PATH}/makeself-help-header.txt" \
113
"${NETDATA_INSTALL_PATH}" \
@@ -81,37 +116,12 @@ rm "${NETDATA_INSTALL_PATH}/sbin" \
116
./system/post-installer.sh \
117
${NULL}
118
119
+rm "${NETDATA_MAKESELF_PATH}/makeself.lsm.tmp"
120
121
# -----------------------------------------------------------------------------
122
# copy it to the netdata build dir
123
88
-NOWNER="unknown"
89
-ORIGIN="$(git config --get remote.origin.url || echo "unknown")"
90
-if [[ "${ORIGIN}" =~ ^git@github.com:.*/netdata.*$ ]]
91
- then
92
- NOWNER="${ORIGIN/git@github.com:/}"
93
- NOWNER="${NOWNER/\/netdata*/}"
94
-
95
-elif [[ "${ORIGIN}" =~ ^https://github.com/.*/netdata.*$ ]]
96
- then
97
- NOWNER="${ORIGIN/https:\/\/github.com\//}"
98
- NOWNER="${NOWNER/\/netdata*/}"
99
-fi
100
-
101
-# make sure it does not have any slashes in it
102
-NOWNER="${NOWNER//\//_}"
103
-
104
-if [ "${NOWNER}" = "firehol" ]
105
- then
106
- NOWNER=
107
-else
108
- NOWNER="-${NOWNER}"
109
-fi
110
-
111
-VERSION="$(git describe || echo "undefined")"
112
-[ -z "${VERSION}" ] && VERSION="undefined"
113
-
114
-FILE="netdata-${VERSION}-$(uname -m)-$(date +"%Y%m%d-%H%M%S")${NOWNER}.gz.run"
124
+FILE="netdata-${FILE_VERSION}.gz.run"
125
126
cp "${NETDATA_INSTALL_PATH}.gz.run" "${FILE}"
127
echo >&2 "Self-extracting installer copied to '${FILE}'"
makeself/makeself.lsm
+1
-1
@@ -1,6 +1,6 @@
1
Begin3
2
Title: netdata
3
-Version: 1.6.0
3
+Version: NETDATA_VERSION
4
Description: netdata is a system for distributed real-time performance and health monitoring.
5
It provides unparalleled insights, in real-time, of everything happening on the
6
system it runs (including applications such as web and database servers), using
netdata-installer.sh
+2
-51
@@ -817,16 +817,7 @@ install_netdata_service || run_failed "Cannot install netdata init service."
817
started=0
818
if [ ${DONOTSTART} -eq 1 ]
819
then
820
- if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
821
- then
822
- echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
823
-
824
- if [ "${UID}" -eq 0 ]
825
- then
826
- chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
827
- fi
828
- chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
829
- fi
820
+ generate_netdata_conf "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
821
822
else
823
restart_netdata ${NETDATA_PREFIX}/usr/sbin/netdata "${@}"
@@ -845,47 +836,7 @@ else
836
# -----------------------------------------------------------------------------
837
# save a config file, if it is not already there
838
848
- if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
849
- then
850
- echo >&2
851
- echo >&2 "-------------------------------------------------------------------------------"
852
- echo >&2
853
- echo >&2 "Downloading default configuration from netdata..."
854
- sleep 5
855
-
856
- # remove a possibly obsolete download
857
- [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
858
-
859
- # disable a proxy to get data from the local netdata
860
- export http_proxy=
861
- export https_proxy=
862
-
863
- # try wget
864
- wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
865
- ret=$?
866
-
867
- # try curl
868
- if [ ${ret} -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
869
- then
870
- curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
871
- ret=$?
872
- fi
873
-
874
- if [ ${ret} -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
875
- then
876
- mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
877
- echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
878
-
879
- if [ "${UID}" -eq 0 ]
880
- then
881
- chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
882
- fi
883
- chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
884
- else
885
- echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
886
- [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
887
- fi
888
- fi
839
+ download_netdata_conf "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
840
fi
841
842
# -----------------------------------------------------------------------------