[SOLVED] Install OpenHAB inside a LXC (Linux Container)

Hi folks

I’m trying to get Openhab running inside of a LXC Container on my Intel NUC 64

What I got so far:

  • installed OS Debian 9.9 stretch on the NUC
  • installed and setup LXC on that machine
  • created a Debian 9 container with working apt and network
  • installed latest stable Openhab for linux (2.4) inside the container
  • registered the service in sysctl

when I start the service and watch the status with

 sudo /bin/systemctl status openhab2.service

I get this:

● openhab2.service - openHAB 2 - empowering the smart home
   Loaded: loaded (/usr/lib/systemd/system/openhab2.service; enabled; vendor pre
   Active: activating (auto-restart) (Result: exit-code) since Sun 2019-05-19 14
     Docs: https://www.openhab.org/docs/
  Process: 165 ExecStart=/usr/share/openhab2/runtime/bin/karaf $OPENHAB_STARTMOD
 Main PID: 165 (code=exited, status=1/FAILURE)

I think openhab has exited because the debian9 container from lxc is a real minimal system… I think this happens because there are some dependencies unmet to get openhab running???

Any suggestions which applications are needed to run openhab inside this container?

another guy managed to get this running with openhabian but this is only for ARM processors I guess.

Any help appreciated…

Ok I managed to get this running :wink: java wasn’t installed inside the container…

install with

sudo apt install default-jre

and finally see if it’s installed correctly

java -version

now openhab is running - got to check if its stable now…

btw if I check status I get the following warning:

● openhab2.service - openHAB 2 - empowering the smart home
   Loaded: loaded (/usr/lib/systemd/system/openhab2.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-05-19 15:49:14 UTC; 20s ago
     Docs: https://www.openhab.org/docs/
 Main PID: 92 (java)
    Tasks: 80 (limit: 4915)
   Memory: 280.1M
   CGroup: /system.slice/openhab2.service
           └─92 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdat

Mai 19 15:49:14 openhab2 systemd[1]: Started openHAB 2 - empowering the smart home.
Mai 19 15:49:28 openhab2 karaf[92]: WARNING: An illegal reflective access operation has occurred
Mai 19 15:49:28 openhab2 karaf[92]: WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/var/lib/openhab2/cache/org.eclipse
Mai 19 15:49:28 openhab2 karaf[92]: WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
Mai 19 15:49:28 openhab2 karaf[92]: WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
Mai 19 15:49:28 openhab2 karaf[92]: WARNING: All illegal access operations will be denied in a future release

does anyone know what “com.thoughtworks.xstream.core.util.Fields” is??

Ive been looking at doing this for a while, but am awaiting time to set everything thatll probably break right before i begin to migrate from windows.

I’ll watch with interest. I can say though that the openhabian install script works on x86 installs, not just arm. It might be worth trying…

Ok :slight_smile: my server is split to multiple containers now

  • openhab2
  • mosquitto
  • influxdb
  • squeezeserver

openhab is configured to connect to mosquitto & influxdb over veth (virtual ethernet)
all my sonoffs (mqtt) connect to the mosquitto container. the squeezebox binding connects to the squeezeserver container.

Everything is up and running since 5 days without any errors or system halts. I think I like lxc :wink:

If anyone’s interested in configuration details to do something like this, please feel free to post your questions here…

maybe I’ll write a little tutorial if I find some time for it…

Hi! Did you use iptable for NAT to each container? Do you mind sharing the iptable entries?
I am using lxd.

Yes, it is an old thread…

Hi Marcelo :wink:

First of all I’m not a linux guru…

I installed LXC on Debian Stretch using this guide:

Wiki Debian LXC
I know this will not help because you’re using LXD but that*s the way I set it up.

I never made any changes to iptables configuration.

I set up a network bridge in /etc/default/lxc-net which looks like this:


my container config at /var/lib/lxc/openhab2/config looks like this:

# Template used to create this container: /usr/share/lxc/templates/lxc-debian
# Parameters passed to the template: -r stretch -a amd64 --enable-non-free
# Template script checksum (SHA-1): b290eda01b21f9818fcf1402b2749c4c218500ed
# For additional config options, please look at lxc.container.conf(5)

# Uncomment the following line to support nesting containers:
#lxc.include = /usr/share/lxc/config/nesting.conf
# (Be aware this has security implications)

lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.name = eth0
lxc.network.hwaddr = xx:xx:xx:xx:xx:xx
lxc.network.ipv4 =
lxc.network.ipv4.gateway =
lxc.start.auto = 1
lxc.start.delay = 5
lxc.start.order = 3

lxc.rootfs = /var/lib/lxc/openhab2/rootfs
lxc.rootfs.backend = dir

# Common configuration
lxc.include = /usr/share/lxc/config/debian.common.conf

# Container specific configuration
lxc.tty = 4
lxc.utsname = openhab2
lxc.arch = amd64

and here’s the /etc/network/interfaces from the openhab container:
( path from outside the container: /var/ib/lxc/openhab2/rootfs//etc/network/interfaces )

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static

Hope you can aquire the information you need from this, if not feel free to ask again :wink:

cheers Dan

Thank you Dan! It was very helpful.