Debian – the difference between OpenVPN service and OpenVPN daemon

debianopenvpn

I'm wanting to run an OpenVPN client on a Debian machine. I can see the service is running:

# 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)

And I can start OpenVPN via the daemon so that it runs in the background

# sudo openvpn --config /etc/openvpn/client.conf --daemon

I can confirm that it's running as expected via it's logging as well as checking my WAN IP.

However, I can stop the OpenVPN service…

# 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)

But the daemon is still running in the background and I'm still connected to the VPN and I'm still getting a public VPN IP address.

So what is the difference between the service and daemon? Are they not dependent on each other?

My goal is to have the OpenVPN running in the background when the computer is booted up and for it to continue running indefinitely. I was just going to set the service to run on boot, but the above actions are now confusing me on how to accomplish that…

Update: Here is this file: /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

Best Answer

A 'service' in this context is an interface for controlling daemons, start, stop, reload etc. An openvpn service is just an instance of openvpn under the control of systemd.


It looks like you have not enabled an openvpn service configuration for client.conf. Systemd can control multiple instances of openvpn independently. These are named individually openvpn@<config>.service where <config> is the name of the .conf file e.g. openvpn@client.service. Once you have created the configuration you need to enable it as a service

systemctl enable openvpn@client.service
Created symlink /etc/systemd/system/multi-user.target.wants/openvpn@client.service → /lib/systemd/system/openvpn@.service.

The /lib/systemd/system/openvpn@.service is a template file that uses passed arguments to run a specified instance.

To control a particular instance you issue systemctl commands as normal

systemctl status openvpn@client
systemctl start openvpn@client
systemctl stop openvpn@client

etc.