Why does using the service command work on a systemd distro

initsystemd

I'm trying to understand the Linux init system.
I don't understand how there are three competing systems, yet the service command seems to work on all of them.

From the service commands man page:

service runs a System V init script or upstart job…

I'm using lubuntu 16.4 I think systemd is the default init system (pstree shows systemd as root process). Systemd is not mentioned in the man page for service. Yet I still start and stop scripts using it.

Can anyone explain why this is?

Best Answer

Some distributions have opted to include compatibility scripts so that old style commands still work. For example, on Debian 8.

root@matrix:~# which service
/usr/sbin/service
root@matrix:~# file /usr/sbin/service
/usr/sbin/service: POSIX shell script, ASCII text executable, with very long lines

root@matrix:~# grep upstart /usr/sbin/service
# Operate against system upstart, not session
   && initctl version 2>/dev/null | grep -q upstart \
   # Upstart configuration exists for this job and we're running on upstart
         # Action is a valid upstart action

root@matrix:~# grep systemd /usr/sbin/service
is_systemd=
if [ -d /run/systemd/system ]; then
   is_systemd=1
          # On systems using systemd, we just perform a normal restart:
          # A restart with systemd is already a full restart.
          if [ -n "$is_systemd" ]; then
# When this machine is running systemd, standard service calls are turned into
if [ -n "$is_systemd" ]
            # the systemd service file does not (yet) support reload for a
Related Question