How to start OH before openvpn?

Running OH on a Raspberri pi 3 that runs as Kodi box, hence I have openvpn starting automatically as a service…problem is that openvpn starts before OH and this creates OH to bind to the wrong IP address, for example:

[WARN ] [g.eclipse.smarthome.core.net.NetUtil] - Found multiple local interfaces - ignoring 172.21.20.xxx
[WARN ] [g.eclipse.smarthome.core.net.NetUtil] - Found multiple local interfaces - ignoring 10.1.10.100
[INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://172.21.20.yyy:8080

And this is creating issues in my OH because the 172.21.20.yyy is the other end of the vpn tunnel hence unreachable from within the house.

How can I change the services startup order so OH starts before openvpn?

Hi s1r,

you can try the following for debian over ssh: (found in another forum)

  1. go to the services folder:
cd /etc/rc2.d/

There are the services with S for start and number between 00 and 99. Bigger number means it starts later. These are symlinks.

  1. delete the symlink of the service you want to start later, for example (S01openvpn)
update-rc.d -f openvpn remove
  1. add a new symlink with higher number (for example 03)
update-rc.d openvpn defaults 03

I don’t know if this will survive a reboot and didn’t try this, but seems to work.

It complains with:

insserv: warning: current start runlevel(s) (3 4 5) of script `openvpn’ overrides LSB defaults (2 3 4 5).

Try to configure OH2’s core.net.NetUtil parameter to bind to a specific IP Subnet:

set in /etc/openhab2/services/runtime.cfg the following:


org.eclipse.smarthome.network:primaryAddress = 10.1.10.100/24
org.eclipse.smarthome.core.net.NetUtil:primaryAddress=10.1.10.0/24

relevant threads:
a) Multiple Network Adapters
b) Parameter setting org.eclipse.smarthome.network

1 Like

What OS are you running? If it’s debian based then it should use systemd as init system. Then its possible to configure your openvpn programs service file to start it only after OH.

PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION=“9 (stretch)”

how about:

rule "startup rule"
when
	System started
then
        executeCommandLine("sudo /etc/init.d/openvpn restart", 5000)
end

make sure to have /etc/init.d/openvpn in your sudo settings (sudo visudo)

So you mean disable openvpn and then have OH start openvpn once is up?
I’m not great in Linux and similar but in Windows you can set service dependencies, I guess that there is something like that in Linux too right?
Ideally I’d set openvpn depending on OH so OH starts first and VPN after

Why are you all giving somekind of workarounds? There’s systemd witch already handles loading all your services at startup. It takes only to add one line to your openvpns service file that tells systemd to start openvpn after OH.

Use google and find out where your unit files are located. Edit the one witch handles openvpn and add this line After=openhab2.service. Then use daemon-reload command to activate the changes.

2 Likes

cause the original request is in the wrong direction.
there is an OH2 parameter (NetUtil) for this purpose and this is the best solution.
if the OH2 service will be restarted, he will face the same issue.

Fair enough :wink:

Of course it’s a workaround.
But because I have this kind of switching enabled in my OH anyway (OpenVPN will only be activated, when I am NOT at home), this suggestion was pretty logical from my point of view.

1 Like

This made it, thx!

As I answered your original question considering startup, @Dim has a valid point that while system is running and you only restart OH you most likely face the same problem. I suggest you to do what dim proposed.

PS. You can test this right away.

I did as @Dim said and it works; n ow next issue is:

[ERROR] [io.openhabcloud.internal.CloudClient] - Connection refused
[WARN ] [io.openhabcloud.internal.CloudClient] - Jetty request 5870052 failed: Connection refused

when opening myopenhab cloud

I think the issue with myopenhab is because now OH binds to 10.1.10.100 but the openhabcloud.internal.CloudClient instead looks for base URL = http://localhost:8080

Any idea where I can force the CludClient to look for another address?