当我获得连接到NordVPN后需要在引导时启动的服务时,我创建了一个测试服务器。
无论如何,我发现如果我也断开了连接,则需要在恢复到VPN的连接后重新启动服务。
你能帮我做这个吗?
非常感谢
我创建了一个服务,并延迟了启动的时间。
[Unit]
Description=qBittorrent-nox service
Documentation=man:qbittorrent-nox(1)
Wants=network-online.target
After=network-online.target nss-lookup.target
[Service]
ExecStartPre=/bin/sleep 60
# if you have systemd < 240 (Ubuntu 18.10 and earlier, for example), you probably want to use Type=>
Type=exec
# change user as needed
User=root
# The -d flag should not be used in this setup
ExecStart=/usr/bin/qbittorrent-nox
Restart=on-failure
RestartSec=1s
# uncomment this for versions of qBittorrent < 4.2.0 to set the maximum number of open files to unl>
#LimitNOFILE=infinity
# uncomment this to use "Network interface" and/or "Optional IP address to bind to" options
# without this binding will fail and qBittorrent's traffic will go through the default route
# AmbientCapabilities=CAP_NET_RAW
[Install]
WantedBy=multi-user.target发布于 2022-12-04 02:58:44
Restart指令指定重新启动服务的条件。此指令的默认值为on-failure,这意味着只有当服务以非零退出代码退出时才会重新启动。在这种情况下,您可以修改此指令,以指定无论何时恢复VPN连接都应重新启动服务。
下面是如何在单元文件中修改重新启动指令的示例:
[Service]
...
Restart=on-failure-or-vpn-restored使用此配置,无论何时使用非零退出代码退出服务,或在恢复VPN连接时,服务都将重新启动。
请注意,您需要创建一个独立的单元文件来管理VPN连接,并将此单元文件指定为服务的单元文件的依赖项。这将确保该服务仅在VPN连接建立后才启动。
例如,可以将以下行添加到服务的单元文件中,使其依赖于VPN连接:
[Unit]
...
After=vpn.service
Wants=vpn.service这将确保您的服务只有在vpn.service单元成功启动之后才能启动。您将需要创建vpn.service单元文件,并指定管理VPN连接所需的详细信息。
https://stackoverflow.com/questions/74666970
复制相似问题