1

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
4
  • They are the same thing. But your systemd unit file seems to be completely hosed. Try using the original distribution-shipped unit instead of writing your own. Dec 28, 2017 at 21:39
  • I'm not sure what you are talking about. I don't even know what a systemd unit file is. I just installed OpenVPN like sudo apt-get install openvpn Dec 28, 2017 at 22:06
  • That's a little strange. That systemd unit seems to be starting /bin/true instead of OpenVPN. Dec 28, 2017 at 22:13
  • I updated my post with the content of that service file if you would like to take a look at that. I haven't modified any of it obviously. Dec 28, 2017 at 22:45

1 Answer 1

4

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. [email protected]. Once you have created the configuration you need to enable it as a service

systemctl enable [email protected]
Created symlink /etc/systemd/system/multi-user.target.wants/[email protected] → /lib/systemd/system/[email protected].

The /lib/systemd/system/[email protected] 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .