我想在Debian机器上运行一个OpenVPN客户机。我可以看到服务正在运行:
# sudo service openvpn status
● openvpn.service - OpenVPN service
Loaded: loaded (/lib/systemd/system/openvpn.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2017-12-28 19:01:14 UTC; 1h 8min ago
Process: 19416 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 19416 (code=exited, status=0/SUCCESS)我可以通过守护进程启动OpenVPN,以便它在后台运行。
# sudo openvpn --config /etc/openvpn/client.conf --daemon我可以通过它的日志记录和检查我的广域网IP来确认它正在按预期运行。
但是,我可以停止OpenVPN服务.
# sudo service openvpn stop
# sudo service openvpn status
● openvpn.service - OpenVPN service
Loaded: loaded (/lib/systemd/system/openvpn.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2017-12-28 20:10:00 UTC; 37s ago
Process: 19416 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 19416 (code=exited, status=0/SUCCESS)但是守护进程仍然在后台运行,我仍然连接到VPN,我仍然得到一个公共VPN IP地址。
那么,服务和守护进程之间有什么区别呢?他们不互相依赖吗?
我的目标是在启动计算机时让OpenVPN在后台运行,并使它无限期地继续运行。我本打算将服务设置为在引导时运行,但上述操作现在使我对如何完成该操作感到困惑.
更新:这是一个文件:/lib/systemd/system/openvpn.service
# This service is actually a systemd target,
# but we are using a service since targets cannot be reloaded.
[Unit]
Description=OpenVPN service
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecReload=/bin/true
WorkingDirectory=/etc/openvpn
[Install]
WantedBy=multi-user.target发布于 2017-12-28 21:22:07
此上下文中的“服务”是一个用于控制守护进程、启动、停止、重新加载等的接口。openvpn服务只是systemd控制下openvpn的一个实例。
看起来您还没有为client.conf启用openvpn服务配置。Systemd可以独立地控制openvpn的多个实例。它们分别命名为openvpn@.service,其中是.conf文件的名称,例如openvpn@client.service。一旦创建了配置,就需要将其启用为服务。
systemctl enable openvpn@client.service
Created symlink /etc/systemd/system/multi-user.target.wants/openvpn@client.service → /lib/systemd/system/openvpn@.service./lib/systemd/system/openvpn@.service是一个模板文件,它使用传递的参数运行指定的实例。
要控制特定实例,您可以正常地发出systemctl命令。
systemctl status openvpn@client
systemctl start openvpn@client
systemctl stop openvpn@client等。
https://serverfault.com/questions/889921
复制相似问题