systemd 尝试过早挂载 davfs2 - 在收到 DHCP 地址之前

systemd 尝试过早挂载 davfs2 - 在收到 DHCP 地址之前

我正在尝试davfs2在启动时在 debian stretch 上自动挂载 WebDAV 文件夹。

似乎systemd在 DHCP 客户端具有 IP 地址之前尝试使用 挂载文件夹mount.davfs(这当然会失败),即使使用_netdev了 中的挂载选项也是如此/etc/fstab。(如果没有_netdev,挂载也会失败,但整个启动过程也会失败,并且我在启动过程中会进入 root shell。)

我能施展什么魔法davfs,让它只在我们通过 DHCP 获取 IP 地址后才尝试挂载?(为什么这不是默认的……)

从下面的输出可以看出journalctldavfs2在 DHCPACK 和 NFS 挂载成功之前尝试挂载DHCPACK。因此 NFS 可以正常运行,但是davfs2会失败。

> grep davfs /etc/fstab
https://example.com/remote.php/webdav/ /home/peter/pmorch davfs user,rw,auto,_netdev 0 0

> sudo journalctl --since 13:20:48 | grep -P 'davfs|pmorch|DHCP|ISO'
Jan 18 13:20:49 snowden dhclient[669]: Internet Systems Consortium DHCP Client 4.3.5
Jan 18 13:20:49 snowden sh[657]: Internet Systems Consortium DHCP Client 4.3.5
Jan 18 13:20:49 snowden sh[657]: DHCPDISCOVER on ens18 to 255.255.255.255 port 67 interval 3
Jan 18 13:20:49 snowden dhclient[669]: DHCPDISCOVER on ens18 to 255.255.255.255 port 67 interval 3
Jan 18 13:20:49 snowden systemd[1]: Mounting /mnt/ISO-Dev...
Jan 18 13:20:49 snowden systemd[1]: Mounting /home/peter/pmorch...
Jan 18 13:20:49 snowden systemd[1]: Mounting /mnt/ISO...
Jan 18 13:20:49 snowden mount.davfs[751]: davfs2 1.5.4
Jan 18 13:20:49 snowden systemd[1]: home-peter-pmorch.mount: Mount process exited, code=exited status=1
Jan 18 13:20:49 snowden systemd[1]: Failed to mount /home/peter/pmorch.
Jan 18 13:20:49 snowden systemd[1]: home-peter-pmorch.mount: Unit entered failed state.
Jan 18 13:20:50 snowden dhclient[669]: DHCPREQUEST of 172.22.216.172 on ens18 to 255.255.255.255 port 67
Jan 18 13:20:50 snowden sh[657]: DHCPREQUEST of 172.22.216.172 on ens18 to 255.255.255.255 port 67
Jan 18 13:20:50 snowden sh[657]: DHCPOFFER of 172.22.216.172 from 172.22.216.251
Jan 18 13:20:50 snowden dhclient[669]: DHCPOFFER of 172.22.216.172 from 172.22.216.251
Jan 18 13:20:50 snowden dhclient[669]: DHCPACK of 172.22.216.172 from 172.22.216.251
Jan 18 13:20:50 snowden sh[657]: DHCPACK of 172.22.216.172 from 172.22.216.251
Jan 18 13:20:52 snowden systemd[1]: Mounted /mnt/ISO-Dev.
Jan 18 13:20:52 snowden systemd[1]: Mounted /mnt/ISO.

答案1

正如所述systemd:在网络真正启动后在启动时启动服务(用于 WoL 目的)由于一些我无法理解的奇怪原因,systemd 目标network-online(以及其他听起来合理的目标)已经达到我们获得了一个 DHCP IP 地址。(这似乎错误的)。

fstab我猜测这就是s_netdev过早尝试安装它的原因。

相反,我已经完全删除了该行/etc/fstab,现在完成了:

systemctl enable systemd-networkd.service systemd-networkd-wait-online.service

并创建/etc/systemd/system/home-peter-pmorch.mount

[Unit]
Description=Mount pmorch WebDAV Service
After=systemd-networkd-wait-online.service
Wants=systemd-networkd-wait-online.service

[Mount]
What=https://example.com/remote.php/webdav/
Where=/home/peter/pmorch
Options=uid=peter,gid=peter,file_mode=0664,dir_mode=2775,grpid
Type=davfs
TimeoutSec=15

[Install]
WantedBy=multi-user.target

现在它在启动时就被挂载了。在发生网络问题后,我再也无法这样做,mount -a但必须

sudo systemctl start home-peter-pmorch.mount

但现在至少它起作用了。

相关内容