How to find out which systemd services/units are part of a target unit?

a5le6t891 asked:

So if I run systemctl list-units --type=target I can see all of the target units on my machine.

But if I wanted to find a list of services and other units that are under each of these “umbrella” target units, how could I do that?

In other words, if I see with journalctl that I have a UNIT xyz, how would I know which target that unit belongs to?

I see in the journal messages that say “Reached target <target_name>“, but I’m curious what log messages and units lead up to that target being reached.


My answer:

I think you are looking for list-dependencies.

From the man page:

       list-dependencies [UNIT]
           Shows units required and wanted by the specified unit. This
           recursively lists units following the Requires=, Requisite=,
           ConsistsOf=, Wants=, BindsTo= dependencies. If no unit is
           specified, is implied.

           By default, only target units are recursively expanded. When --all
           is passed, all other units are recursively expanded as well.

           Options --reverse, --after, --before may be used to change what
           types of dependencies are shown.

For example:

# systemctl list-dependencies
● ├─zfs-mount.service
● ├─zfs-share.service
● ├─zfs-zed.service
● └─
●   └─zfs-import-cache.service

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.