]> arthur.barton.de Git - netdata.git/blobdiff - netdata-installer.sh
preserve configs across installaitons
[netdata.git] / netdata-installer.sh
index b5455776a6f979b90d7d6e60bf74ef4343a0e61b..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
@@ -574,29 +575,58 @@ stop_all_netdata() {
 # -----------------------------------------------------------------------------
 # check netdata for systemd
 
-running=0
-pidof systemd >/dev/null 2>&1
-if [ $? -eq 0 -a "${UID}" -eq 0 ]
-then
-       # systemd is running on this system
+issystemd() {
+       # 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
+}
 
-       if [ ! -f /etc/systemd/system/netdata.service ]
+started=0
+if [ "${UID}" -eq 0 ]
        then
-               echo >&2 "Installing systemd service..."
-               run cp system/netdata.service /etc/systemd/system/netdata.service && \
-                       run systemctl daemon-reload && \
-                       run systemctl enable netdata
-       else
-               run service netdata stop
+
+       if issystemd
+       then
+               # systemd is running on this system
+
+               if [ ! -f /etc/systemd/system/netdata.service ]
+               then
+                       echo >&2 "Installing systemd service..."
+                       run cp system/netdata.service /etc/systemd/system/netdata.service && \
+                               run systemctl daemon-reload && \
+                               run systemctl enable netdata
+               else
+                       run service netdata stop
+               fi
+
+               stop_all_netdata
+               run service netdata restart && started=1
        fi
 
-       stop_all_netdata
-       run service netdata start && running=1
+       if [ ${started} -eq 0 ]
+       then
+               # 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
+                       run service netdata start && started=1
+               fi
+       fi
 fi
 
-if [ ${running} -eq 0 ]
+if [ ${started} -eq 0 ]
 then
-       # no systemd (or not running as root, or systemd failed)
+       # still not started...
 
        stop_all_netdata
 
@@ -872,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.