Starting up automatically (re-)starting the VPN

#1

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

#2

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.

OVPN script not working
#3

You could try zombeided VPN manager. Works great.

#4

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

#5

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"
#6

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

#7

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
#8
  1. Correct.

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

#9

Perfecto !! :smiley: Thank you.

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

#11

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

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.