Changing port number on openHAB 2.0

In openHAB 1.7 the start scripts could be modified to change the port number for the service, however in 2.0 this is not true. Jetty runs only on 8080 and/or 8443. Should this be filed as a bug?

hmm … as far as i can see the start.sh and start.bat both contain the according variables to configure another port.

Hello Teichsta,
Thanks for your response. Yes they do but changing them does not effect anything. The jetty server still runs on port 8080.

that has been a problem (see https://github.com/openhab/openhab2/issues/84) but should be fixed long ago. Are you sure you are running the latest oh2 version?

Hello again, Yes I believe I do have the updated version. I picked it up from the cloundbees site on August 14th and your commit was from Feb 13th

since the demo-server is running on 9080 i am quite sure that changing the port worked (at least for oh2a2 release). Which OS are you running?

@teichsta I am running this on Windows 10 with JAVA 1.8.0_51 and openHAB runtime is v2.0.0, build 201508080141.

I can access openHAB only on port 8080

which doesn’t seem to be the recent version (see https://github.com/openhab/openhab2/blob/master/distribution/openhabhome/start.bat). Frankly i didn’t try the Win version. Can anybody of the Win-Users confirm that this bat file isn’t working properly?

@teichsta Just downloaded the latest snapshot from cloudbees - openHAB runtimev2.0.0, build 201509021732. Still seeing the same behaviour. :frowning:

ports under 1024 are restricted ports, though I am not sure how Windows respects that. Have you tried running OpenHAB with elevated privs under windows (ie as administrator) ?

I’m the author of PR 332 which allows you to set the HTTP and HTTPS ports without needing to change the start.bat scripts.

You should just need to set an environment variable OPENHAB_HTTP_PORT to, say, 4711, to make OH2 run on a port different to the standard 8080.

Having said that, I have tested this change only on my Linux setup. Also, the comment with “ports under 1024” holds true on Windows as well. If you really need OH2 to run on port 80, you should configure a reverse proxy for that.

@xsnrg and @hakan Yes to the fact that ports under 1024 are restricted but I have successfully tested running openHAB on port 80 under version 1.7.0 and 1.7.1 by simply changing the start.bat (and start_debug.bat) files. The environment variable was not set in either case. Here is a break down of the use cases I have tried:

  1. Edit startup.bat to change ports - Works with 1.7.x and NOT with 2.0 (no elevated privileges needed)
  2. Add environment variable OPENHAB_HTTP_PORT and set it to 80 (no changes to startup scripts) - DOES NOT WORK FOR 1.7.x & 2.0
  3. Run as a service - same as 1.

This is true on windows 8.1 and WIndows 10 - both 64 bit versions.

I would guess the solution is very simple. As @teichsta claims, it works with start.sh and @mganapa says that start.bat does not work, I see an important difference in the files:

start.sh:

-Dorg.osgi.service.http.port=$HTTP_PORT \
-Dorg.osgi.service.http.port.secure=$HTTPS_PORT \

start.bat:

-Djetty.port=%HTTP_PORT% ^
-Djetty.port.ssl=%HTTPS_PORT% ^

I would assume this is a bug in the bat file. @mganapa, could you please try if replacing jetty.port by org.osgi.service.http.port solves the problem?

2 Likes

@Kai Thanks! That did the trick. Never thought of comparing the .sh file with the .bat. Works as expected now.

1 Like

Great, thanks for the feedback!
I have fixed this now: https://github.com/openhab/openhab2/commit/849c938d71d9d2726a54b148e12438f5d46417b3

Now that OH2 is using karaf, i think to change the port, you need to change it in
…/runtime/karaf/bin/setenv

or can these still be set in start.sh/cmd

See https://github.com/openhab/openhab-distro/blob/master/docs/sources/getting-started.md#configuring-which-https-ports-to-use

@Kai -Ah cool - i had not seen any of the documentation under here. It answers many many questions i had so thanks for linking to it!

1 Like

Yes, it is important to note that https://github.com/openhab/openhab-distro is the new “entry point” for openHAB 2 - the repo https://github.com/openhab/openhab2-addons now only contains add-ons (as its new name suggests).

@kai I’m using the latest beta snapshot and have set the environment arguments but openhab2 is still starting on port 8080 instead of 80.
I’m using openhab2 on the rpi maybe it’s because of the rpi