Solution
Translated from: https://forum.ubuntuusers.de/topic/laufender-service-ja-oder-nein/
This is a very good example of why you shouldn't use the service
command since systemd
(and thus systemctl
) was introduced.
You can look at the source code of the service
command
(/usr/sbin/service
). With the --status-all
option, this script changes to
/etc/init.d
and executes each executable file located there with a
previously defined environment and the argument status. From this
call, the return value and the output are saved.
A service receives the marker [+]
if the return value of the executed
program is 0
and the length of the recorded output is not zero. Before
that, it is tested whether the output of the executed file contains
the string usage:
(upper and lower case is ignored) in order to use
the marker [?]
to put. For all other cases the result is [-]
.
Now an example:
/etc/init.d$ ls
acpid console-setup.sh grub-common lvm2 mdadm-waitidle plymouth-log ssh
apache2 cron hwclock.sh lvm2-lvmetad networking procps udev
apache-htcacheclean cryptdisks irqbalance lvm2-lvmpolld nfs-common rpcbind ufw
apparmor cryptdisks-early iscsid lxcfs open-iscsi rsync uuidd
apport dbus keyboard-setup.sh lxd open-vm-tools rsyslog
atd ebtables kmod mdadm plymouth screen-cleanup
/etc/init.d$ ./apache-htcacheclean status
* apache-htcacheclean is not running
/etc/init.d$ echo $?
0
If you ask service directly about the status of a service, it will
instead be passed through a systemctl, which can then give a much more
correct answer.