There are other ways to handle this with one OH instance. But putting that aside, are the conflicts strictly ports? Or are you seeing errors with accessing hardware (e.g. zwave dongle, GPIO pins, etc)?
If just ports, keep in mind that there are at least three ports and all three must be different. There is the HTTP (defaults to 8080), HTTPS (defaults to 8443) and Console Ports (in OH 1 defaults to 5555, not sure in OH 2). There might be additional ports in OH 2 I’m not aware of.
Only one instance of OH can access the same hardware device at a time. There is no way to share these devices across multiple running programs.
Given this is your goal, I strongly recommend looking into running OH in Docker containers. You can then map the default ports to whatever you want in the startup of the Docker container itself. This will provide an even stronger separation between the multiple instances of OH and it should improve management, maintenance, and upgrade of each instance.
For example, you can download from DockerHub or create your own OH 2 image. Then all you need are some openhab.service scripts (one for each instance) which starts a container with a separate name and different port mappings and volume mappings (if you want to preserve the data generated by the container). With this approach, you can update/upgrade the software on the one OH image then just rebuild the containers and everything is upgraded all at once.
I can elaborate or answer questions if desired. I’m slowly moving most of my services over to this approach more as a means to source control my service’s configuration than separation but so far I’m exceptionally happy with Docker. I’ll post an example Dockerfile and systemd service script for one of my services below.
With this script when I want to upgrade the software or build the initial image I just run
docker build -t rich/mosquitto . which will recreate the image from scratch. Every time the systemd service runs, it creates a new container from this image (i.e. starts fresh). I put the config and logs on my host machine and map those to the container to preserve the data I want to preserve when the container is rebuilt.
If I wanted to run multiple mosquitto brokers, I would just need to create a copy of mosquitto.service, map the ports to a different number and the volumes to a different path and voila I have two independent services running on the same machine without conflicts.
The problem is he can’t control access to the different sitemaps on a per user basis (unless he sets up a reverse proxy which manages the user authentication and authorization).
MAINTAINER Rich Koshak <email@example.com>
LABEL multi.version="1.0" multi.notes="First attempt at building an Image"
RUN useradd --system --uid 1064 -M --shell /usr/sbin/nologin mosquitto \
&& apt-get -q update \
&& apt-get -q -y install mosquitto
EXPOSE 8883 1883
ENTRYPOINT ["/usr/sbin/mosquitto", "-c"]
ExecStart=/usr/bin/docker run --name=%n -p 8883:8883 -p 1883:1883 -v /opt/mosquitto/etc:/etc/mosquitto -v /opt/mosquitto/logs:/var/log -v /opt/mosquitto/lib:/var/lib/mosquitto rich/mosquitto
ExecStop=/usr/bin/docker stop -t 2 %n ; /usr/bin/docker rm -f %n