additional checks for the existance of systemd; always attempt to use the service command for managing netdata
Costa Tsaousis (ktsaou) committed
May 30, 2016 at 12:21 UTC
25e5018ae34f7bc1ce4ea1b43aeb424e82f3901e
1 file changed
+18
-15
netdata-installer.sh
+18
-15
@@ -575,12 +575,20 @@ stop_all_netdata() {
575
# check netdata for systemd
576
577
issystemd() {
578
- pidof systemd >/dev/null 2>&1 && return 0
578
+ # if the directory /etc/systemd/system does not exit, it is not systemd
579
+ [ ! -d /etc/systemd/system ] && return 1
580
+
581
+ # if pid 1 is systemd, it is systemd
582
[ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
583
+
584
+ # if systemd is running, it is systemd
585
+ pidof systemd >/dev/null 2>&1 && return 0
586
+
587
+ # else, it is not systemd
588
return 1
589
}
590
583
-running=0
591
+started=0
592
if [ "${UID}" -eq 0 ]
593
then
594
@@ -599,26 +607,21 @@ if [ "${UID}" -eq 0 ]
607
fi
608
609
stop_all_netdata
602
- run service netdata start && running=1
610
+ run service netdata start && started=1
611
fi
612
605
- if [ ${running} -eq 0 ]
613
+ if [ ${started} -eq 0 ]
614
then
607
- service netdata status >/dev/null 2>&1
608
- if [ $? -eq 0 ]
609
- then
610
- # nice guy, he installed netdata to his system
611
- run service netdata stop
612
- stop_all_netdata
613
- run service netdata start && running=1
614
- fi
615
+ # check if we can use the system service
616
+ run service netdata stop
617
+ stop_all_netdata
618
+ run service netdata start && started=1
619
fi
616
-
620
fi
621
619
-if [ ${running} -eq 0 ]
622
+if [ ${started} -eq 0 ]
623
then
621
- # still not running...
624
+ # still not started...
625
626
stop_all_netdata
627