Note: applications are run as the root user when they are called from rc.local. We recommend you use ‘su osmc -c /path/to/your/program’ to run the application as the default OSMC user.
The Openvpn daemon will start automatically but since the systemd change (if you know the old one) you have to enable each VPN profile with systemctl command. So if openvpn is installed and enabled at startup, you have to:
copy the ovpn file to /etc/openvpn with a .conf extension (E.g. : /etc/openvpn/MYVPN.conf)
enable this profile to start automatically with: > sudo systemctl enable openvpn@MYVPN.service
This will create a symlink in /etc/systemd and you VPN profile is now manageable as a service (status, disable/enable, etc.)
PS: this is valid for last compiled Openvpn using systemd
You can enable it that way but it’s not a “must-do”. Using this technique runs the risk that you’ll have more than one openvpn profile enabled at the same time. IMO, it’s better to have the “master switch” in /etc/default/openvpn and only enable openvpn.service to run.
osmc@osmc:~$ sudo systemctl disable openvpn
Synchronizing state for openvpn.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d openvpn defaults
Executing /usr/sbin/update-rc.d openvpn disable
insserv: warning: current start runlevel(s) (empty) of script `openvpn' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `openvpn' overrides LSB defaults (0 1 6).
osmc@osmc:~$ sudo systemctl status openvpn@test
● openvpn@test.service - OpenVPN connection to test
Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled)
Active: inactive (dead)
Apr 18 12:21:47 osmc ovpn-test[1330]: IFCONFIG POOL: base=10.8.0.2 size=252, ipv6=0
Apr 18 12:21:47 osmc ovpn-test[1330]: Initialization Sequence Completed
Apr 18 12:21:47 osmc systemd[1]: Started OpenVPN connection to test.
Apr 18 12:23:17 osmc systemd[1]: Stopping OpenVPN connection to test...
Apr 18 12:23:17 osmc ovpn-test[1330]: event_wait : Interrupted system call (code=4)
Apr 18 12:23:17 osmc ovpn-test[1330]: Closing TUN/TAP interface
Apr 18 12:23:17 osmc ovpn-test[1330]: /sbin/ifconfig tun0 0.0.0.0
Apr 18 12:23:17 osmc ovpn-test[1330]: Linux ip addr del failed: external program exited with error status: 255
Apr 18 12:23:17 osmc ovpn-test[1330]: SIGTERM[hard,] received, process exiting
Apr 18 12:23:17 osmc systemd[1]: Stopped OpenVPN connection to test.
osmc@osmc:~$ sudo systemctl start openvpn@test
osmc@osmc:~$ sudo systemctl status openvpn@test
● openvpn@test.service - OpenVPN connection to test
Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled)
Active: active (running) since Tue 2017-04-18 12:28:49 CEST; 9s ago
Process: 1504 ExecStart=/usr/sbin/openvpn --daemon ovpn-%i --status /run/openvpn/%i.status 10 --cd /etc/openvpn --config /etc/openvpn/%i.conf (code=exited, status=0/SUCCESS)
Main PID: 1506 (openvpn)
CGroup: /system.slice/system-openvpn.slice/openvpn@test.service
└─1506 /usr/sbin/openvpn --daemon ovpn-test --status /run/openvpn/test.status 10 --cd /etc/openvpn --config /etc/openvpn/test.conf
Apr 18 12:28:49 osmc ovpn-test[1506]: /sbin/ifconfig tun0 10.8.0.1 netmask 255.255.255.0 mtu 1500 broadcast 10.8.0.255
Apr 18 12:28:49 osmc ovpn-test[1506]: Socket Buffers: R=[163840->327680] S=[163840->327680]
Apr 18 12:28:49 osmc ovpn-test[1506]: UDPv4 link local (bound): [AF_INET]192.168.11.51:8689
Apr 18 12:28:49 osmc ovpn-test[1506]: UDPv4 link remote: [AF_UNSPEC]
Apr 18 12:28:49 osmc ovpn-test[1506]: GID set to nogroup
Apr 18 12:28:49 osmc ovpn-test[1506]: UID set to nobody
Apr 18 12:28:49 osmc ovpn-test[1506]: MULTI: multi_init called, r=256 v=256
Apr 18 12:28:49 osmc ovpn-test[1506]: IFCONFIG POOL: base=10.8.0.2 size=252, ipv6=0
Apr 18 12:28:49 osmc ovpn-test[1506]: Initialization Sequence Completed
Apr 18 12:28:49 osmc systemd[1]: Started OpenVPN connection to test.
osmc@osmc:~$ sudo systemctl status openvpn
● openvpn.service - OpenVPN service
Loaded: loaded (/lib/systemd/system/openvpn.service; disabled)
Active: inactive (dead)
Apr 15 22:08:24 osmc systemd[1]: Starting OpenVPN service...
Apr 15 22:08:24 osmc systemd[1]: Started OpenVPN service.
Apr 18 12:18:43 osmc systemd[1]: Stopping OpenVPN service...
As you can see, I disabled openvpn.service, then started openvpn@test.service. The status of openvpn@test once running was:
osmc@osmc:~$ sudo systemctl status openvpn@test
● openvpn@test.service - OpenVPN connection to test
Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled)
Active: active (running) since Tue 2017-04-18 12:28:49 CEST; 9s ago
but openvpn.service and openvpn@.service are both still disabled. So while you can enable openvpn@test.service, AFAIK it’s not a necessary requirement for running the service.
It’s not mandatory you’re right. Since the usage of systemd all .conf file are no more processed and have to be manually enabled so having multiple profiles running at the same time is possible but have to be done by enabling each profile individually. It may be intended too for the usage of namespace of to ease the usage of multiple VPN profile. Both will work and depending of the audience one may be more advisable than the other
I’ve previously been using the OpenVPN kodi plugin by Brian Hornsby. This is great because it allows me to choose a VPN location through the Kodi GUI. However using the systemd method creates a new instance. So any VPNs I select in the Kodi Plugin wont affect the openvpn config being run by systemd. Is there any way of making the systemd openvpn instance and the openvpn instance from the Kodi plugin, work together?