diff options
Diffstat (limited to 'installer/functions.sh')
-rw-r--r-- | installer/functions.sh | 102 |
1 files changed, 96 insertions, 6 deletions
diff --git a/installer/functions.sh b/installer/functions.sh index cfc2d7eaa..d403bfe52 100644 --- a/installer/functions.sh +++ b/installer/functions.sh @@ -120,6 +120,7 @@ netdata_banner() { # portable service command service_cmd="$(which_cmd service)" +rcservice_cmd="$(which_cmd rc-service)" systemctl_cmd="$(which_cmd systemctl)" service() { local cmd="${1}" action="${2}" @@ -132,6 +133,10 @@ service() { then run "${service_cmd}" "${cmd}" "${action}" return $? + elif [ ! -z "${rcservice_cmd}" ] + then + run "${rcservice_cmd}" "${cmd}" "${action}" + return $? fi return 1 } @@ -437,7 +442,7 @@ install_non_systemd_init() { run update-rc.d netdata defaults && \ run update-rc.d netdata enable && \ return 0 - elif [[ "${key}" =~ ^(amzn-201[567]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6).* ]] + elif [[ "${key}" =~ ^(amzn-201[567]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6|Scientific Linux CERN SLC release 6|CloudLinux Server release 6).* ]] then echo >&2 "Installing init.d file..." run cp system/netdata-init-d /etc/init.d/netdata && \ @@ -488,8 +493,15 @@ install_netdata_service() { if [ ${ret} -eq 0 ] then - NETDATA_START_CMD="service netdata start" - NETDATA_STOP_CMD="service netdata stop" + if [ ! -z "${service_cmd}" ] + then + NETDATA_START_CMD="service netdata start" + NETDATA_STOP_CMD="service netdata stop" + elif [ ! -z "${rcservice_cmd}" ] + then + NETDATA_START_CMD="rc-service netdata start" + NETDATA_STOP_CMD="rc-service netdata stop" + fi fi return ${ret} @@ -628,6 +640,84 @@ install_netdata_logrotate() { } # ----------------------------------------------------------------------------- +# download netdata.conf + +fix_netdata_conf() { + local owner="${1}" + + if [ "${UID}" -eq 0 ] + then + run chown "${owner}" "${filename}" + fi + run chmod 0664 "${filename}" +} + +generate_netdata_conf() { + local owner="${1}" filename="${2}" url="${3}" + + if [ ! -s "${filename}" ] + then + cat >"${filename}" <<EOFCONF +# netdata can generate its own config. +# Get it with: +# +# wget -O ${filename} "${url}" +# +# or +# +# curl -s -o ${filename} "${url}" +# +EOFCONF + fix_netdata_conf "${owner}" + fi +} + +download_netdata_conf() { + local owner="${1}" filename="${2}" url="${3}" + + if [ ! -s "${filename}" ] + then + echo >&2 + echo >&2 "-------------------------------------------------------------------------------" + echo >&2 + echo >&2 "Downloading default configuration from netdata..." + sleep 5 + + # remove a possibly obsolete download + [ -f "${filename}.new" ] && rm "${filename}.new" + + # disable a proxy to get data from the local netdata + export http_proxy= + export https_proxy= + + # try curl + run curl -s -o "${filename}.new" "${url}" + ret=$? + + if [ ${ret} -ne 0 -o ! -s "${filename}.new" ] + then + # try wget + run wget -O "${filename}.new" "${url}" + ret=$? + fi + + if [ ${ret} -eq 0 -a -s "${filename}.new" ] + then + run mv "${filename}.new" "${filename}" + run_ok "New configuration saved for you to edit at ${filename}" + else + [ -f "${filename}.new" ] && rm "${filename}.new" + run_failed "Cannnot download configuration from netdata daemon using url '${url}'" + + generate_netdata_conf "${owner}" "${filename}" "${url}" + fi + + fix_netdata_conf "${owner}" + fi +} + + +# ----------------------------------------------------------------------------- # add netdata user and group NETDATA_ADDED_TO_DOCKER=0 @@ -642,15 +732,15 @@ add_netdata_user_and_group() { if [ ${UID} -eq 0 ] then portable_add_group netdata || return 1 - portable_add_user netdata || return 1 + portable_add_user netdata || return 1 portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1 portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1 portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1 portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1 portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1 portable_add_user_to_group nsd netdata && NETDATA_ADDED_TO_NSD=1 - portable_add_user_to_group proxy netdata && NETDATA_ADDED_TO_PROXY=1 - portable_add_user_to_group squid netdata && NETDATA_ADDED_TO_SQUID=1 + portable_add_user_to_group proxy netdata && NETDATA_ADDED_TO_PROXY=1 + portable_add_user_to_group squid netdata && NETDATA_ADDED_TO_SQUID=1 return 0 fi |