@cryptotaxi247 / netdata-1 / commits / 14d5b03eb

installer now generates netdata-updater.sh

Costa Tsaousis (ktsaou) committed Sep 16, 2016 at 18:44 UTC 14d5b03eb0280d39a42b552ddedf319772ee004e
2 files changed +68
.gitignore
+4
@@ -29,6 +29,9 @@ netdata.spec
29
30 *.tar.*
31
32 +cov-int/
33 +netdata-coverity-analysis.tgz
34 +
35 .cproject
36 .idea/
37 .project
@@ -66,6 +69,7 @@ python.d/python-modules-installer.sh
69
70 netdata-installer.log
71 netdata-uninstaller.sh
72 +netdata-updater.sh
73
74 gmon.out
75 gmon.txt
netdata-installer.sh
+64
@@ -25,6 +25,9 @@ printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
25 printf "%q " "$0" "${@}" >>netdata-installer.log
26 printf "\n" >>netdata-installer.log
27
28 +REINSTALL_PWD="${PWD}"
29 +REINSTALL_COMMAND="$(printf "CFLAGS=\"%s\" " "${CFLAGS}"; printf "%q " "$0" "${@}"; printf "\n")"
30 +
31 service="$(which service 2>/dev/null || command -v service 2>/dev/null)"
32 systemctl="$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)"
33 service() {
@@ -1070,3 +1073,64 @@ Enjoy!
1073
1074 END
1075 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"
1076 +
1077 +cat >netdata-updater.sh.new <<REINSTALL
1078 +#!/usr/bin/env bash
1079 +
1080 +# make sure we cd to the working directory
1081 +cd "${REINSTALL_PWD}" || exit 1
1082 +
1083 +# signal netdata to start saving its database
1084 +# this is handy if your database is big
1085 +pids=\$(pidof netdata)
1086 +[ ! -z "\${pids}" ] && kill -USR1 \${pids}
1087 +
1088 +# this is what we will do if it fails (head-less only)
1089 +failed() {
1090 + echo >&2 "\$(date) : FAILED TO UPDATE NETDATA : \${1}"
1091 + cat >&2 "\${tmp}"
1092 + rm "\${tmp}"
1093 + exit 1
1094 +}
1095 +
1096 +update() {
1097 + if [ -t 1 -a -t 2 ]
1098 + then
1099 + # running on a terminal
1100 + echo >&2 "Running on a terminal - (this script also supports running headless from crontab)"
1101 +
1102 + echo >&2
1103 + echo >&2 "Updating source..."
1104 + git pull || exit 1
1105 +
1106 + echo >&2
1107 + echo >&2 "re-installing..."
1108 + ${REINSTALL_COMMAND// --dont-wait/} --dont-wait || exit 1
1109 +
1110 + else
1111 + # running head-less
1112 + # do not generate any output, unless we fail
1113 +
1114 + # create a temporary file for the log
1115 + tmp=\$(mktemp /tmp/netdata-updater-log-XXXXXX.log)
1116 +
1117 + # update source from git
1118 + git pull >>"\${tmp}" 2>&1 || failed "CANNOT FETCH LATEST SOURCE"
1119 +
1120 + # install the latest version
1121 + ${REINSTALL_COMMAND// --dont-wait/} --dont-wait >>"\${tmp}" 2>&1 || failed "CANNOT BUILD AND INSTALL NETDATA"
1122 +
1123 + rm "\${tmp}"
1124 + fi
1125 +
1126 + return 0
1127 +}
1128 +
1129 +# the installer updates this script - so we run and exit in a single line
1130 +update && exit 0
1131 +###############################################################################
1132 +###############################################################################
1133 +REINSTALL
1134 +chmod 755 netdata-updater.sh.new
1135 +mv -f netdata-updater.sh.new netdata-updater.sh
1136 +echo >&2 "Update script generated : ./netdata-updater.sh"