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

相關內容