无法在 WSL 上的 Distrod 上的 Archlinux 上覆盖 systemd 单元的 ConditionVirtualization

无法在 WSL 上的 Distrod 上的 Archlinux 上覆盖 systemd 单元的 ConditionVirtualization

我正在尝试在 Archlinux 上启动 systemd-timesyncd,它是通过 Distrod 安装在 WSL 之上的。默认情况下,systemd-timesyncd 的单元文件会阻止它在虚拟化环境中启动,该单元文件有一个ConditionVirtualization=!container标志。我正在尝试使用以下配置来覆盖它:

[root@valentine ~]# systemd-detect-virt
wsl
[root@valentine ~]# cat /etc/systemd/system/systemd-timesyncd.service.d/override.conf
[Unit]
ConditionVirtualization=wsl
[root@valentine ~]# systemctl daemon-reload
[root@valentine ~]# systemctl start systemd-timesyncd.service
[root@valentine ~]# systemctl status systemd-timesyncd.service
○ systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; preset: enabled)
    Drop-In: /etc/systemd/system/systemd-timesyncd.service.d
             └─override.conf
     Active: inactive (dead)
  Condition: start condition failed at Mon 2023-02-27 10:38:46 CET; 6s ago
             └─ ConditionVirtualization=!container was not met
       Docs: man:systemd-timesyncd.service(8)

Feb 27 10:38:46 valentine systemd[1]: Network Time Synchronization was skipped because of an unmet condition check (ConditionVirtualization=!container).

看起来 systemd 正在选择覆盖配置,但是,它似乎没有使用覆盖配置标志。

解决此问题并使 systemd-timesyncd 在虚拟化环境中运行的最佳方法是什么?

答案1

我遇到了完全相同的问题并遇到了这个答案这对我有帮助。事实证明,它ConditionVirtualization需要一个条目列表,并且必须先清除它才能更改。

我曾经sudo systemctl edit systemd-timesyncd使用以下内容创建嵌入式文件:

[Unit]
ConditionVirtualization=
ConditionVirtualization=wsl

现在它按预期工作:

~ >sudo systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/etc/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/systemd-timesyncd.service.d
             └─override.conf
     Active: active (running) since Wed 2023-03-01 14:31:05 EST; 1s ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 8816 (systemd-timesyn)
     Status: "Initial synchronization to time server 137.184.81.69:123 (0.arch.pool.ntp.org)."
      Tasks: 2 (limit: 19001)
     Memory: 1.4M
     CGroup: /system.slice/systemd-timesyncd.service
             └─8816 /lib/systemd/systemd-timesyncd

Mar 01 14:31:05 gnantel systemd[1]: Starting Network Time Synchronization...
Mar 01 14:31:05 gnantel systemd[1]: Started Network Time Synchronization.
Mar 01 14:31:02 gnantel systemd-timesyncd[8816]: Initial synchronization to time server 137.184.81.69:123 (0.arch.pool.ntp.org).

sudo systemctl daemon-reload为了安全起见,我也做了一个,但在编辑时systemctl不需要使用它。

相关内容