systemd 单元间接状态

systemd 单元间接状态

我想知道如何检查哪个单元以间接状态激活另一个单元?

我使用 Gnome 和 Debian 服务器运行 Arch。在我的 Debian 机器上,我可以看到显示的输出systemctl list-unit-files --type=target --state=enabled,正如预期的那样:

default.target    enabled
multi-user.target enabled

但在 Arch 桌面上,令我惊讶的是,它没有,尽管:multi-user.targetgraphical.target(我在 arch 上的默认设置)都处于活动状态。当我检查这些单位文件的状态时,它们都是:indirect.当我列出它的依赖项时,graphical.target它会显示gdm.servicemulti-user.target。在 gdm 单元文件中我没有看到Also=部分[Install]。那么究竟是什么激活了呢graphical.target

这种“间接”解决方案的原因是什么?

答案1

man systemd.special

图形目标
       A special target unit for setting up a graphical login screen.
       This pulls in multi-user.target.

       Units that are needed for graphical logins shall add Wants= dependencies for their unit to this unit (or multi-user.target) during installation.
       This is best configured via WantedBy=graphical.target in the unit's [Install] section.

所以你的内容gdm.service会解释更多的事情......


以下是我系统上这两个服务的信息,请注意它们是“静态”的......

$ systemctl status multi-user.target graphical.target

● multi-user.target - Multi-User System
     Loaded: loaded (/lib/systemd/system/multi-user.target; static)
     Active: active since Mon 2023-09-04 09:34:27 +03; 11h ago
      Until: Mon 2023-09-04 09:34:27 +03; 11h ago
       Docs: man:systemd.special(7)

Sep 04 09:34:27 kubuntu systemd[1]: Reached target multi-user.target - Multi-User System.

● graphical.target - Graphical Interface
     Loaded: loaded (/lib/systemd/system/graphical.target; static)
     Active: active since Mon 2023-09-04 09:34:27 +03; 11h ago
      Until: Mon 2023-09-04 09:34:27 +03; 11h ago
       Docs: man:systemd.special(7)

Sep 04 09:34:27 kubuntu systemd[1]: Reached target graphical.target - Graphical Interface.
$ systemctl cat multi-user.target graphical.target

# /lib/systemd/system/multi-user.target
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes

# /lib/systemd/system/graphical.target
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Graphical Interface
Documentation=man:systemd.special(7)
Requires=multi-user.target
Wants=display-manager.service
Conflicts=rescue.service rescue.target
After=multi-user.target rescue.service rescue.target display-manager.service
AllowIsolate=yes
$ ls -la /lib/systemd/system/{multi-user,graphical}.target
-rw-r--r-- 1 root root 606 Jan 26  2023 /lib/systemd/system/graphical.target
-rw-r--r-- 1 root root 540 Jan 26  2023 /lib/systemd/system/multi-user.target

相关内容