Starting up automatically (re-)starting the VPN

Hello,

I have an openVPN running, but cannot manager to make it start on boot. (and also would like it to auto-restart if it gets disconnected).

Here is how is was implemented in Xbian (creating a startSB.sh in /etc/init.d/):

sudo touch /etc/init.d/startSB.sh
sudo chmod +x /etc/init.d/startSB.sh
sudo nano /etc/init.d/startSB.sh

and initiating a start command

#!/bin/sh
sudo openvpn --config /etc/openvpn/FIP/NL.ovpn --script-security 2

to be bootable

sudo update-rc.d startSB.sh defaults

I know that systemd does not recommend using /etc/init.d for start on boot, but should I write the “start command” from above directly in /etc/systemd/system then?

Thanks

It’s very easy in OSMC - and we do use systemd.

To enable OpenVPN to run at startup, run:

sudo systemctl enable openvpn

To specify which config file to run, you need to:

1 Place the config file in /etc/openvpn and give it a .conf suffix, not .ovpn.

2 Edit file /etc/default/openvpn and add a line

AUTOSTART=“NL”

so that it will look for file /etc/openvpn/NL.conf.

Then restart and see if it’s working as you expect.

You could try zombeided VPN manager. Works great.

Thanks the_bo, my VPN provider is not supported by Zomboided VPN…

Sorry, I’m not very skilled in programming… Do you mean that I create the etc/openvpn/NL.conf into the etc/openvpn folder, and then put the following commands into it ?

sudo openvpn --config /etc/openvpn/FIP/NL.ovpn --script-security 2
AUTOSTART="NL"

I mean move file NL.conf from directory /etc/openvpn/FIP to /etc/openvpn (ie up one level).

No. Follow the second instruction to the letter. You should not create any openvpn start command because systemd takes care of that

OK. So you want me to rename the NL.ovpn into NL.conf, place it under the directory /etc/openvpn and modify the content of the /etc/default/openvpn to “AUTOSTART the NL.conf”. Correct ?

I get the following data when enabling the openvpn, is that normal ?

Synchronizing state for openvpn.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d openvpn defaults
insserv: warning: script 'K01startSB.sh' missing LSB tags and overrides
insserv: warning: script 'startSB.sh' missing LSB tags and overrides
Executing /usr/sbin/update-rc.d openvpn enable
insserv: warning: script 'K01startSB.sh' missing LSB tags and overrides
insserv: warning: script 'startSB.sh' missing LSB tags and overrides
  1. Correct.

  2. You need to remove all the init.d stuff in post #1. It’s not needed with systemd.

Perfecto !! :smiley: Thank you.

Now, I might need you in another post on a second step :wink: - about transmission

Thank you for the instructions! After using them I was able to start and stop openvpn using systemctl, but after reboot it didn’t automatically start despite I enabled it.
To make this work I added to /lib/systemd/system/openvpn@.service into section [Unit] two lines:
Wants=network-online.target
After=network-online.target
My configuration:

  • Raspberi Pi 3b+
  • osmc: 2018.12-1
  • kodi: 17.6
  • vpn: tweaknews

In my experience those two lines have not been necessary. OpenVPN will keep trying until it gets a connection, even if it starts before the network is up. It already contains the line After=network.target.

You should also remember that the change will probably be overwritten when there is an update to OpenVPN.

Hello,

I am reviving this thread as I have just changed my VPN provider to CyberGhost and installed the ovpn and .conf files as needed. It starts on boot, starts manually, but for whatever reason it drops after some minutes and does not restart on its own.

Any idea what I should check ?

  • I do have the AUTOSTART command in the /etc/default/openvpn file)
  • and I even added Restart=on-failure in the /lib/systemd/system/openvpn@.service file under [Service] section

Thank you

Hi,

This only works if openvpn crashes, not if the vpn tunnel goes down. You could try creating a watchdog timer/server like this:-

Regards Tom.

Hi Tom,

seemed like it was working. Thanks a lot.

EDIT: after a false hope it dropped again. Looks like it is dropping after some random time (and yesterday was rather after a longer time, hence my hope)

I checked the status of this tunnel, after a crash or while running, through systemctl status openvpn@cyber_LT, and here the result https://paste.osmc.tv/tafoxomagu.rb....if that helps.

Thank you

Hi,

You may better contacting CyberGhost support to find out why its dropping.

In the mean time have you tried setting up the watchdog?

Regards Tom.

Hi Tom,

yes, I did setup the watchdog, this is why I was happy it worked, but unfortunately, it might have been only due to the longer period without dropping. I’ll contact them.

Thanks,
Nicolas

1 Like