Running openHAB 2 in Docker

Ok, I’ll retry it. Just trying to get a dev system running with 2.3…then I’ll attempt and upgrade.

I’ve got a separate post about getting a dev system working (rather than upgrade my main prod system) and dealing with persistence and mqtt clients etc.

  • implement a inotify helper

I found an inotify message forwarder (https://github.com/mhallin/notify-forwarder) which can forward inotify events from a NAS to the openhab container and it works!

I created an Openhab cont-init.d script. That script and a arm32 bit and a arm64 bit binary that i compiled can be downloaded here: https://1drv.ms/u/s!AhWVJSYSapFMgrZhYm7i-CmSHHLeKQ?e=XDFIlC . This is the script:

#!/bin/bash
arch=$(uname -m)
if [[ $arch == 'aarch64' ]]; then
echo running aarch64 version of inotify-forwarder...
    /etc/cont-init.d/notify-forwarder_aarch64 receive &
elif [[ $arch == 'armv7l' ]]; then
    echo running armhf version of inotify-forwarder...
    /etc/cont-init.d/notify-forwarder_armhf receive &
fi
disown

When using the following commandline on the NAS and i change a file via VS Code:

./notify-forwarder_armhf watch -c  10.43.125.124:29324 /k3s_storage/openhab/conf /openhab/conf /k3s_storage/openhab/addons /openhab/addons

I receive attrib events on the Openhab container. I can confirm that Openhab listens to attrib events :slight_smile:

root@openhab-6fbf4d4dcf-qzkfj:/openhab# inotifywait -m -e attrib -r /openhab/conf
Setting up watches.  Beware: since -r was given, this may take a while!
Watches established.
/openhab/conf/.git/ ATTRIB FETCH_HEAD
/openhab/conf/.git/ ATTRIB FETCH_HEAD
/openhab/conf/automation/jsr223/python/personal/ ATTRIB 000_init_rules_on_startup.py

I will complete this post with an systemd script for the NAS later.
-edit-

A very quick and dirty unit file:

[Unit]
Description=Inotify Forwarder for OpenHAB
After=network.target
StartLimitIntervalSec=0
StartLimitBurst=3000
[Service]
Restart=always
RestartSec=3
Type=simple
ExecStart=/k3s_storage/openhab/contrib-init/notify-forwarder_armhf watch -c 10.43.93.81:29324 /k3s_storage/openhab/conf /openhab/conf /k3s_storage/openhab/addons /openhab/addons /k3s_storage/openhab/userdata/etc /openhab/userdata/etc

[Install]
WantedBy=multi-user.target
1 Like

Have you tried setting the yeelight binding log level to trace and see what is (not) going on?

Also you could inspect the network traffic to see if there is specific network traffic blocked.

And I’m not really sure, but when you’re not using host mode, you might need some kind of traffic forwarder/router for the upnp traffic?

I found an issue when trying to call the karaf client in a rule using the `executeCommanLine" command:

rule "Do what I want"

  when
    Item restart_zwave changed to 2

  then

    val String results = executeCommandLine("/openhab/runtime/bin/client 'bundle:restart org.openhab.binding.zwave' ", 8000)

    logInfo("FILE", "***** RESTARTING: >" + results + "< *****")

end

The logs shows:

19:46:07.304 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '/openhab/runtime/bin/client 'bundle:restart org.openhab.binding.zwave' '
19:46:09.160 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - exit code '1', result 'Closed'
19:46:09.161 [INFO ] [g.eclipse.smarthome.model.script.FILE] - ***** RECYCLING: >Closed< *****

It seems that there are some environment variables missing when calling it via rule because when I rund this command from the command line (or putting it into a small script and running the script from the command line inside the container the client bundle:restart works:

root@openhab-2:/openhab/conf/scripts# /openhab/runtime/bin/client bundle:restart 232
Logging in as openhab
root@openhab-2:/openhab/conf/scripts# 

And here the log output:

19:47:38.152 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node2' changed from ONLINE: Node initialising: REQUEST_NIF to UNINITIALIZED
19:47:38.168 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node2' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
19:47:38.169 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node5' changed from ONLINE: Node initialising: REQUEST_NIF to UNINITIALIZED
19:47:38.185 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node5' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
19:47:38.185 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node4' changed from ONLINE: Node initialising: REQUEST_NIF to UNINITIALIZED
19:47:38.232 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node4' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
19:47:38.233 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:serial_zstick:564c8ec1' changed from ONLINE to UNINITIALIZED
19:47:41.450 [INFO ] [ding.zwave.handler.ZWaveSerialHandler] - Stopped ZWave serial handler
19:47:41.479 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:serial_zstick:564c8ec1' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
19:47:47.496 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node2' changed from UNINITIALIZED (HANDLER_MISSING_ERROR) to UNINITIALIZED (BRIDGE_UNINITIALIZED)
19:47:47.499 [INFO ] [.zwave.handler.ZWaveControllerHandler] - Attempting to add listener when controller is null
19:47:47.609 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:serial_zstick:564c8ec1' changed from UNINITIALIZED (HANDLER_MISSING_ERROR) to INITIALIZING
19:47:47.615 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:serial_zstick:564c8ec1' changed from INITIALIZING to OFFLINE (BRIDGE_OFFLINE): Controller is offline
19:47:47.623 [INFO ] [ding.zwave.handler.ZWaveSerialHandler] - Connecting to serial port '/dev/ttyACM0'
19:47:47.631 [INFO ] [ding.zwave.handler.ZWaveSerialHandler] - Serial port is initialized
19:47:47.635 [INFO ] [ave.internal.protocol.ZWaveController] - Starting ZWave controller
19:47:47.635 [INFO ] [ave.internal.protocol.ZWaveController] - ZWave timeout is set to 5000ms. Soft reset is false.
19:47:47.647 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node5' changed from UNINITIALIZED (HANDLER_MISSING_ERROR) to INITIALIZING
19:47:47.649 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node2' changed from UNINITIALIZED (BRIDGE_UNINITIALIZED) to INITIALIZING
19:47:47.652 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node4' changed from UNINITIALIZED (HANDLER_MISSING_ERROR) to INITIALIZING
19:47:47.666 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node2' changed from INITIALIZING to OFFLINE (BRIDGE_OFFLINE): Controller is offline
19:47:47.668 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node4' changed from INITIALIZING to OFFLINE (BRIDGE_OFFLINE): Controller is offline
19:47:47.669 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node5' changed from INITIALIZING to OFFLINE (BRIDGE_OFFLINE): Controller is offline
19:47:50.840 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:serial_zstick:564c8ec1' changed from OFFLINE (BRIDGE_OFFLINE): Controller is offline to ONLINE
19:47:50.845 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node5' changed from OFFLINE (BRIDGE_OFFLINE): Controller is offline to ONLINE
19:47:50.846 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node4' changed from OFFLINE (BRIDGE_OFFLINE): Controller is offline to ONLINE
19:47:50.849 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node2' changed from OFFLINE (BRIDGE_OFFLINE): Controller is offline to ONLINE
19:47:50.849 [INFO ] [smarthome.event.ThingUpdatedEvent    ] - Thing 'zwave:serial_zstick:564c8ec1' has been updated.
19:47:50.857 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node2' changed from ONLINE to ONLINE: Node initialising: REQUEST_NIF
19:47:50.863 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'zwave:device:564c8ec1:node4' changed from ONLINE to ONLINE: Node initialising: REQUEST_NIF

Any idea what is different between normal OpenHAB installation and docker?

This Limitation can be fixed by building a custom Image :slight_smile:

Example to install netcat ping jq bc awk

Dockerfile

FROM openhab/openhab:latest

RUN apt-get update && apt-get install -y netcat inetutils-ping jq bc gawk &&\
  rm -rf /var/lib/apt/lists/*

Command to build the Image

docker build --force-rm --no-cache -t private/openhab:latest

You don’t need to build a custom image anymore with the container init scripts support.

3 Likes

Nice … Thx for the hint :slight_smile:

Hello guys,

I´ve followed the tutorial and got openhab 2.4 up and running in docker. Everything seems to run fine except those warnings/errors on each startup:

2019-10-03 11:26:18.135 [WARN ] [org.apache.felix.fileinstall        ] - /usr/share/openhab2/addons does not exist, please create it.
2019-10-03 11:26:18.163 [ERROR] [org.apache.felix.fileinstall        ] - Cannot create folder /var/lib/openhab2/tmp/bundles. Is the folder write-protected?
2019-10-03 11:26:18.164 [ERROR] [org.apache.felix.configadmin        ] - [org.osgi.service.cm.ManagedServiceFactory, id=38, bundle=10/mvn:org.apache.felix/org.apache.felix.fileinstall/3.6.4]: Unexpected problem updating configuration org.apache.felix.fileinstall.1813a014-eea4-4ad5-aa1f-e70c2be8093f

Permissions should be okay, I did:

sudo find /opt/openhab/ \( -type d -exec chmod 777 {} + \) -o \( -type f -exec chmod 777 {} + \)

to be sure. Any ideas where to start?

Thanks a lot!

Which tutorial did you follow because based on the path names I reckon you’re not using the official openHAB docker image:

Also note that the log is complaining about /var/lib/openhab2/tmp/bundles (this directory does not exist in the official openHAB docker image) while you set the permissions for /opt/openhab/.

I´ve followed the tutorial from this thread and I´m using the offical openHAB docker image.

But now I see: I copied my / userdata and my / conf folder from my Openhabian installation (without Docker). There are probably references there that I still need to change.

Thanks!

Actually, I have the same issue. Did you find the culprit?
This is actually the only item which causes some issue. Not sure though what the impact is.

When I map the folders according best practice, but still using my old conf directory mapped, the system crashes immediately.

ExecStart=/usr/bin/docker run --name=%n --net=host \
  -v /etc/localtime:/etc/localtime:ro \
  -v /etc/timezone:/etc/timezone:ro \
  -v /home/zotac/openhab2:/openhab/conf \
  -v /opt/openhab/userdata:/openhab/userdata \
  -v /opt/openhab/addons:/openhab/addons \
  -v /opt/openhab/.java:/openhab/.java \

result:

2019-11-12 20:04:19.537 [ERROR] [org.apache.felix.scr                ] - bundle org.apache.felix.scr:2.1.2 (39)Circular reference detected trying to get service {org.eclipse.smarthome.core.audio.AudioSink}={service.id=118, service.bundleid=116, service.scope=bundle, component.name=org.eclipse.smarthome.io.javasound.internal.JavaSoundAudioSink, component.id=6}
 stack of references: ServiceReference: {org.eclipse.smarthome.core.audio.AudioSink}={service.id=118, service.bundleid=116, service.scope=bundle, component.name=org.eclipse.smarthome.io.javasound.internal.JavaSoundAudioSink, component.id=6}
ServiceReference: {org.eclipse.smarthome.core.audio.AudioManager, org.eclipse.smarthome.config.core.ConfigOptionProvider}={service.id=120, service.bundleid=103, service.scope=bundle, defaultSink=enhancedjavasound, service.config.label=Audio, component.name=org.eclipse.smarthome.core.audio.internal.AudioManagerImpl, component.id=7, service.config.category=system, felix.fileinstall.filename=file:/openhab/userdata/etc/org.eclipse.smarthome.audio.cfg, service.pid=org.eclipse.smarthome.audio, service.config.description.uri=system:audio}

Having my mapping as follows, and using the old userdata location,

ExecStart=/usr/bin/docker run --name=%n --net=host \
  -v /etc/localtime:/etc/localtime:ro \
  -v /etc/timezone:/etc/timezone:ro \
  -v /home/zotac/openhab2:/openhab/conf \
  -v /var/lib/openhab2:/openhab/userdata \
  -v /opt/openhab/addons:/openhab/addons \
  -v /opt/openhab/.java:/openhab/.java \    

gets the system up and running, and as far as I can see it behaves normal. Only entries in the log files are:

2019-11-12 16:04:24.657 [ERROR] [org.apache.felix.fileinstall        ] - Cannot create folder /var/lib/openhab2/tmp/bundles. Is the folder write-protected?
2019-11-12 16:04:24.666 [ERROR] [org.apache.felix.configadmin        ] - [org.osgi.service.cm.ManagedServiceFactory, id=38, bundle=10/mvn:org.apache.felix/org.apache.felix.fileinstall/3.6.4]: Unexpected problem updating configuration org.apache.felix.fileinstall.098b1b9c-eaed-41c3-8fac-c8c88d5624c5
java.lang.RuntimeException: Cannot create folder: /var/lib/openhab2/tmp/bundles

Anyone, any idea?

Maybe search and replace works. It’s a known issue anyhow:

I have completely saved my configuration in files (things, items etc.). For me it works, if I copy only the

/conf

folder. The

/userdata

folder remains completely empty.

However, I once had to copy the folder

/userdata/etc

, because openhab would not start otherwise.

Except you are missing your imbedded persistence line mapdbb and rrd4j, and any files that individual bindings might create like the secret and uuid the cloud connector creates, zwave xml files, retained messages on the embedded MQTT broker, etc. Some actions you take in the Karaf console get saved to the files in etc as well.

If you want to actually create a full backup and not lose anything, you must include everything in userdata too except for cache and temp.

Thanks for the hint. Right now I have a very simple setup here, without zwave, mqtt and so on. With the upcoming extensions I will consider that.

I want to come back to these issues.

I’m runnung openhab2.5.2 in a docker container. When starting it up I got

[WARN ] [org.apache.felix.fileinstall ] - /usr/share/openhab2/addons does not exist, please create it.
[ERROR] [org.apache.felix.fileinstall ] - Cannot create folder /var/lib/openhab2/tmp/bundles. Is the folder write-protected?

I changed into the running container and defined the missing folders manually. After a container restart all issues have been gone. So I guess there is something missing in the docker images provided. How can this be solved?

The only thing what is still complaining is

[ERROR] [etvisu.internal.util.ClientInstaller] - webfolder /openhab/userdata/…/…/…/CometVisu/src is no directory

This seems not to cause further issues but how can this be resolved as well?

Thanks a lot in advance

Hello all

I would like to install OpenHAB2 on OpenMediaVault server using Docker and Portainer to install it.

How Can I do that?

BR

I think we need a little bit more to start with. For example, where you start. is everything ready? do you have OMV and Portainer already running ?

Hello papaPhil

Yes I have OpenMediaVault already started and Docker/Portainer already installed and functional (I installed Unifi-controller).

Next step is to install OpenHAB on OpenMediaVault but I’m not an expert of Portainer… And as Unifi-COntroller is already installed, I need to have some tweaks (as java is used by OpenHAB and Unifi-COntroller, also change the port access for OpenHAB etc…)

BR

You will get the best support by posting to an OMV or Portainer website. Very few are deploying openHAB on these platforms and pretty much all of the problems and instructions are going to be specific to OMV and Portainer, not openHAB.

Ultimately, you need to learn how to translate the Docker run command arguments to whatever OMV+Portainer require. That is all outside the scope of this forum.