@cryptotaxi247 / netdata-1 / commits / 694148943

netdata-installer.sh when run at host, does not stop netdata processes running in containers

Costa Tsaousis (ktsaou) committed Oct 29, 2016 at 18:22 UTC 694148943571bdca72f54b67cd7a63f8f086801a
1 file changed +29 -5
netdata-installer.sh
+29 -5
@@ -752,7 +752,9 @@ stop_netdata_on_pid() {
752 }
753
754 stop_all_netdata() {
755 - local p
755 + local p myns ns
756 +
757 + myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
758
759 echo >&2 "Stopping a (possibly) running netdata..."
760
@@ -761,22 +763,44 @@ stop_all_netdata() {
763 $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
764 $(pidof netdata 2>/dev/null)
765 do
764 - stop_netdata_on_pid ${p}
766 + ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
767 +
768 + if [ -z "${myns}" -o "${myns}" = "${ns}" ]
769 + then
770 + stop_netdata_on_pid ${p}
771 + fi
772 done
773 }
774
775 # -----------------------------------------------------------------------------
769 -# check netdata for systemd
776 +# check for systemd
777
778 issystemd() {
779 + local pids p myns ns systemctl
780 +
781 # if the directory /etc/systemd/system does not exit, it is not systemd
782 [ ! -d /etc/systemd/system ] && return 1
783
784 + # if there is no systemctl command, it is not systemd
785 + systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
786 + [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
787 +
788 # if pid 1 is systemd, it is systemd
789 [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
790
778 - # if systemd is running, it is systemd
779 - pidof systemd >/dev/null 2>&1 && return 0
791 + # if systemd is not running, it is not systemd
792 + pids=$(pidof systemd 2>/dev/null)
793 + [ -z "${pids}" ] && return 1
794 +
795 + # check if the running systemd processes are not in our namespace
796 + myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
797 + for p in ${pids}
798 + do
799 + ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
800 +
801 + # if pid of systemd is in our namespace, it is systemd
802 + [ ! -z "${myns}" && "${myns}" = "${ns}" ] && return 0
803 + done
804
805 # else, it is not systemd
806 return 1