为什么我的 systemd“Requires=”语句被忽略?

为什么我的 systemd“Requires=”语句被忽略?

尽管有Requires=一个挂载单元(run-netns-vpn.mount),systemd 仍会在该单元处于活动状态之前启动我的服务!?

[Unit]
Description=Sets up networking in VPN namespace
Requires=run-netns-vpn.mount
After=run-netns-vpn.mount

[Service]
Type=oneshot
WorkingDirectory=/usr/namespaces
ExecStart=/usr/namespaces/vpn-network-setup.sh

[Install]
WantedBy=multi-user.target

这是服务的状态,具体取决于run-netns-vpn.mount

vpn-ns-setup.service - Sets up networking in VPN namespace
   Loaded: loaded (/lib/systemd/system/vpn-ns-setup.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2018-10-07 16:36:34 BST; 2min 46s ago
  Process: 762 ExecStart=/usr/namespaces/vpn-network-setup.sh (code=exited, status=1/FAILURE)
 Main PID: 762 (code=exited, status=1/FAILURE)

Oct 07 16:36:34 mediabox vpn-network-setup.sh[762]: + ip netns exec vpn ip rule add from 10.200.1.2 table 200
Oct 07 16:36:34 mediabox vpn-network-setup.sh[762]: Cannot open network namespace "vpn": No such file or directory
Oct 07 16:36:34 mediabox systemd[1]: vpn-ns-setup.service: Main process exited, code=exited, status=1/FAILURE
Oct 07 16:36:34 mediabox systemd[1]: vpn-ns-setup.service: Failed with result 'exit-code'.
Oct 07 16:36:34 mediabox systemd[1]: Failed to start Sets up networking in VPN namespace.

这是状态run-netns-vpn.mount

● run-netns-vpn.mount - /run/netns/vpn
   Loaded: loaded
   Active: active (mounted) since Sun 2018-10-07 16:36:47 BST; 3min 52s ago
    Where: /run/netns/vpn
     What: nsfs

服务于 启动,16:36:34装载装载于16:36:47。我希望 a) 服务等待安装 b) 如果无法启动,则会失败。

以供参考:

Linux mediabox 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

为什么会发生这种情况?

相关内容