我有一个 systemd 单元(“leafnode.socket”),它依赖于正在启动的网络设备(“rath”)。套接字单元在 /etc 中有一个显式文件,设备单元(我相信)是由 systemd 响应 udev 事件自动创建的:
root@ebox ~# cat /etc/systemd/system/leafnode.socket
[Unit]
Description=NNTP server for small sites (socket)
[Socket]
ListenStream=119
BindToDevice=rath
Accept=yes
[Install]
WantedBy=default.target
在启动时,设备启动正常,但插座却没有:
root@ebox /e/s/system# systemctl status leafnode.socket
○ leafnode.socket - NNTP server for small sites (socket)
Loaded: loaded (/etc/systemd/system/leafnode.socket; enabled; preset: enabled)
Active: inactive (dead)
Listen: [::]:119 (Stream)
Accepted: 0; Connected: 0;
Feb 14 09:09:08 ebox.rath.org systemd[1]: Dependency failed for leafnode.socket - NNTP server for small sites (socket).
Feb 14 09:09:08 ebox.rath.org systemd[1]: leafnode.socket: Job leafnode.socket/start failed with result 'dependency'.
root@ebox /e/s/system# systemctl status sys-subsystem-net-devices-rath.device
● sys-subsystem-net-devices-rath.device - /sys/subsystem/net/devices/rath
Loaded: loaded
Active: active (plugged) since Wed 2024-02-14 09:09:08 UTC; 8min ago
Device: /sys/devices/virtual/net/rath
如果我在此时手动启动套接字,它就会正常启动。
有人能帮我理解这里出了什么问题吗?据我所知,套接字单元对设备单元有隐式依赖,因此应该可以正常工作。实际上,systemd 似乎以某种方式确定依赖关系“失败” - 事实上,.device 有相应的超时消息:
root@ebox /e/s/system# journalctl -u sys-subsystem-net-devices-rath.device
Feb 14 09:09:08 ebox.rath.org systemd[1]: sys-subsystem-net-devices-rath.device: Job sys-subsystem-net-devices-rath.device/start timed out.
Feb 14 09:09:08 ebox.rath.org systemd[1]: Timed out waiting for device sys-subsystem-net-devices-rath.device - /sys/subsystem/net/devices/rath.
Feb 14 09:09:08 ebox.rath.org systemd[1]: sys-subsystem-net-devices-rath.device: Job sys-subsystem-net-devices-rath.device/start failed with result 'timeout'.
但是,由于此单元仅在有 udev 事件时才创建,我不明白它怎么可能“超时”。难道 systemd 收到事件这一事实本身不就意味着它已经存在,无需等待任何事情吗?