大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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?…

问题原文

原帖链接 · a5le6t891 · CC BY-SA 4.0

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!

社区高分解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。