]> arthur.barton.de Git - netdata.git/blobdiff - netdata-installer.sh
Merge pull request #574 from paulfantom/master
[netdata.git] / netdata-installer.sh
index 32b6113019d2ae1f4e3e4962dc293af04a35bc0e..da0ec82159338c46f0a027a5163b9eede22addfe 100755 (executable)
@@ -338,15 +338,15 @@ run make || exit 1
 
 # backup user configurations
 installer_backup_suffix="${PID}.${RANDOM}"
-for x in apps_groups.conf charts.d.conf
+for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
 do
-       if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}" ]
+       if [ -f "${x}" ]
                then
-               cp -p "${NETDATA_PREFIX}/etc/netdata/${x}" "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup.${installer_backup_suffix}"
+               cp -p "${x}" "${x}.installer_backup.${installer_backup_suffix}"
 
-       elif [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup.${installer_backup_suffix}" ]
+       elif [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
                then
-               rm -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup.${installer_backup_suffix}"
+               rm -f "${x}.installer_backup.${installer_backup_suffix}"
        fi
 done
 
@@ -354,11 +354,12 @@ echo >&2 "Installing netdata ..."
 run make install || exit 1
 
 # restore user configurations
-for x in apps_groups.conf charts.d.conf
+for x in $(find "${NETDATA_PREFIX}/etc/netdata/" -name '*.conf' -type f)
 do
-       if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup.${installer_backup_suffix}" ]
+       if [ -f "${x}.installer_backup.${installer_backup_suffix}" ]
                then
-               cp -p "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup.${installer_backup_suffix}" "${NETDATA_PREFIX}/etc/netdata/${x}"
+               cp -p "${x}.installer_backup.${installer_backup_suffix}" "${x}"
+               rm -f "${x}.installer_backup.${installer_backup_suffix}"
        fi
 done
 
@@ -376,7 +377,7 @@ if [ ${UID} -eq 0 ]
        if [ $? -ne 0 ]
                then
                echo >&2 "Adding netdata user account ..."
-               run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
+               run useradd -r -g netdata -c netdata -s $(which nologin || echo '/bin/false') -d / netdata
        fi
 
        getent group docker > /dev/null
@@ -575,12 +576,20 @@ stop_all_netdata() {
 # check netdata for systemd
 
 issystemd() {
-       pidof systemd >/dev/null 2>&1 && return 0
+       # if the directory /etc/systemd/system does not exit, it is not systemd
+       [ ! -d /etc/systemd/system ] && return 1
+
+       # if pid 1 is systemd, it is systemd
        [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
+
+       # if systemd is running, it is systemd
+       pidof systemd >/dev/null 2>&1 && return 0
+
+       # else, it is not systemd
        return 1
 }
 
-running=0
+started=0
 if [ "${UID}" -eq 0 ]
        then
 
@@ -599,26 +608,25 @@ if [ "${UID}" -eq 0 ]
                fi
 
                stop_all_netdata
-               run service netdata start && running=1
+               run service netdata restart && started=1
        fi
 
-       if [ ${running} -eq 0 ]
+       if [ ${started} -eq 0 ]
        then
-               service netdata status >/dev/null 2>&1
-               if [ $? -eq 0 ]
+               # check if we can use the system service
+               run service netdata stop
+               stop_all_netdata
+               run service netdata restart && started=1
+               if [ ${started} -eq 0 ]
                then
-                       # nice guy, he installed netdata to his system
-                       run service netdata stop
-                       stop_all_netdata
-                       run service netdata start && running=1
+                       run service netdata start && started=1
                fi
        fi
-       
 fi
 
-if [ ${running} -eq 0 ]
+if [ ${started} -eq 0 ]
 then
-       # still not running...
+       # still not started...
 
        stop_all_netdata
 
@@ -894,7 +902,7 @@ cat <<-END
        -------------------------------------------------------------------------------
 
        INFO: Command line options changed. -pidfile, -nd and -ch are deprecated.
-       If you use custom stratup scripts please run netdata -h to see the 
+       If you use custom startup scripts, please run netdata -h to see the 
        corresponding options and update your scripts.
 
        Hit http://${access}:${NETDATA_PORT}/ from your browser.