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
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
-
Ok. What's the difference between
activeandexitedofinitramfs? I read it asit's working and it is not working the same timepalmasd1– palmasd12024-04-26 07:40:20 +00:00Commented Apr 26, 2024 at 7:40 -
So if I want grep
postgresqlservice only if it's working right now, thengrep postgresql.*runningwould be correct?palmasd1– palmasd12024-04-26 07:41:42 +00:00Commented Apr 26, 2024 at 7:41 -
1"active/exited" typically means a service that is of type
oneshotwith a settingRemainAfterExit=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 ifpostgresql.serviceis running, you could runsystemctl is-active postgresql.serviceand check the result code.telcoM– telcoM2024-04-26 08:04:01 +00:00Commented 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?palmasd1– palmasd12024-04-26 08:18:10 +00:00Commented Apr 26, 2024 at 8:18
-
1They'd have two different names; literally two separate units, like
[email protected], with their own independent active & running states.grawity– grawity2024-04-26 08:37:28 +00:00Commented Apr 26, 2024 at 8:37
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'sExecStart=) 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=oneshotcombined withRemainAfterExit=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.