-1

I see from manual of systemctl that's the difference is high- and low- levels. What does that mean? I suppose that active means "started automatically while OS starts" and running means "is active right now".

2 Answers 2

2

From the systemctl manpage:

The "Active:" line shows active state. The value is usually "active" or "inactive". Active could mean started, bound, plugged in, etc depending on the unit type. The unit could also be in process of changing states, reporting a state of "activating" or "deactivating".

The systemctl list-units command output has a column for ACTIVE and another for SUB. The former shows the active state of the unit while the latter shows the sub-state, which depends on the unit. See the example below (output of systemctl list-units --all):

UNIT                                     LOAD   ACTIVE   SUB       DESCRIPTION
proc-sys-fs-binfmt_misc.automount        loaded active   running   Arbitrary Executable File Formats File System Automount Point
sys-module-configfs.device               loaded active   plugged   /sys/module/configfs
var.mount                                loaded active   mounted   /var
dracut-shutdown.service                  loaded active   exited    Restore /run/initramfs on shutdown
systemd-ask-password-plymouth.path       loaded active   waiting   Forward Password Requests to Plymouth Directory Watch
sssd-kcm.service                         loaded inactive dead      SSSD Kerberos Cache Manager
5
  • Ok. What's the difference between active and exited of initramfs? I read it as it's working and it is not working the same time Commented Apr 26, 2024 at 7:40
  • So if I want grep postgresql service only if it's working right now, then grep postgresql.*running would be correct? Commented Apr 26, 2024 at 7:41
  • 1
    "active/exited" typically means a service that is of type oneshot with a setting RemainAfterExit=true. Usually such a service just runs a particular command on service start, and then exits without leaving any process running. Instead of grepping the listing to find out if postgresql.service is running, you could run systemctl is-active postgresql.service and check the result code. Commented Apr 26, 2024 at 8:04
  • How would it work if there would be several similar services? For example there would be two PostgreSQL instances with different versions? Commented Apr 26, 2024 at 8:18
  • 1
    They'd have two different names; literally two separate units, like [email protected], with their own independent active & running states. Commented Apr 26, 2024 at 8:37
1

Just to elaborate on dr_'s answer.

active, inactive, activating and deactivating are unit states. There are 11 different types of units, each with their own useful sub-states.

A service is only one type of unit and has a few substates.

  • "running" means that the service's process (often Type=simple's ExecStart=) is currently running.
  • "exited" means that the service's process has completed, but the unit is still considered to be "active". This is often seen with Type=oneshot combined with RemainAfterExit=true.
  • "dead" means that the service's process ended and so the unit has now become "inactive".

See man systemd.service for info about RemainAfterExit= and man systemd for information about substates.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.