我有一个新的脚本,我正在转换为systemd。要启动此服务,需要有特定的网络接口。
这就是我在我的暴发户脚本中使用的内容:
start on (local-filesystems and net-device-added INTERFACE=tun0)
系统等效于什么?
发布于 2019-02-05 23:44:21
您应该可以使用以下内容对新启动脚本中的内容进行稍微破坏的版本:
Wants=sys-devices-virtual-net-tun0.device
After=sys-devices-virtual-net-tun0.device
systemd应该生成tun0
‘设备’文件。唯一的问题是,如果openvpn没有足够快地创建tun0
设备,您的服务启动将尝试“启动”sys-devices-virtual-net-tun0.device
,这将导致超时失败(默认情况下,DefaultTimeoutStartSec
指定为90秒,通常在/etc/systemd/system.conf
中)。因此,最好要依赖openvpn,然后显式检查tun0
设备,如果找不到它就重新启动:
# Wait loosely on openvpn service
Wants=openvpnxxxx.service
After=openvpnxxx.service
# Make sure tun0 is up/active
ExecStartPre=/bin/bash -c "systemctl is-active sys-devices-virtual-net-tun0.device"
# Keep restarting till tun0 is up
Restart=on-failure
https://askubuntu.com/questions/647167
复制相似问题