名前は同じですが、内容が異なるシステム化されたターゲットユニット

名前は同じですが、内容が異なるシステム化されたターゲットユニット

私はLinux Mint 20.3 Cinnamonを使用しています。

$ systemctl --user get-default
default.target
$ ls -al /lib/systemd/system/default.target
lrwxrwxrwx 1 root 16 Jan 10 05:56 /lib/systemd/system/default.target -> graphical.target
$ \cat /lib/systemd/system/default.target
#  SPDX-License-Identifier: LGPL-2.1+
#
#  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
  • 私はdefault.target次のように異なるコンテンツを持つ2つの異なる場所にいます。
$ \cat ~/.config/systemd/user/default.target
#  SPDX-License-Identifier: LGPL-2.1+
#
#  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=Main User Target
Documentation=man:systemd.special(7)
Requires=basic.target
After=basic.target
AllowIsolate=yes

質問

  1. /lib/systemd/system/default.targetサービスユニットファイル内でユーザーユニットをどのように指定しますか?
  2. 特定のサービス単位ファイルがどのデフォルトの宛先を使用しているのか、どうすればわかりますか?
  3. systemctl --user get-defaultdefault.targetのいずれに言及していますか?

ベストアンサー1

ターゲットの現在の場所を知るには、次のように状態を照会します。

systemctl --user status default.target

● default.target - Main User Target
     Loaded: loaded (/usr/lib/systemd/user/default.target; static)
[...]


systemctl status default.target
● graphical.target - Graphical Interface
     Loaded: loaded (/lib/systemd/system/graphical.target; indirect; vendor preset: enabled)
[...]

ユニットを検索する順序を提供します。マニュアルに(システム/ユーザーユニット検索パスへ)

つまり、.configlocal-dirにダミーターゲットを作成して起動すると、検索パスが高くなるため、最初にロードされます。

$cat ~/.config/systemd/user/default.target

[Unit]
Description=just exists

$systemctl --user daemon-reload
$systemctl --user start default.target
$systemctl --user status default.target

● default.target - just exists
     Loaded: loaded (/home/felixjn/.config/systemd/user/default.target; static)

つまり、デバイス検索パスは$PATHシェルの変数と同じです。パスに一致する最初のデバイスが選択されます。

ユーザーパスとシステムパスは互いに異なり、重複しないことを知ることが重要です!

おすすめ記事