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
  • 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. – Michael Hampton Dec 28 '17 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 – Jake Wilson Dec 28 '17 at 22:06
  • That's a little strange. That systemd unit seems to be starting /bin/true instead of OpenVPN. – Michael Hampton Dec 28 '17 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. – Jake Wilson Dec 28 '17 at 22:45
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. 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.