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

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.

Thanks!


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, default.target 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.target
zfs.target
● ├─zfs-mount.service
● ├─zfs-share.service
● ├─zfs-zed.service
● └─zfs-import.target
●   └─zfs-import-cache.service