[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/
           https://community.openhab.org
  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/
           https://community.openhab.org
 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??

1 Like

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:

USE_LXC_BRIDGE="false"
LXC_ADDR="192.168.1.100"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="192.168.1.0/24"
LXC_DHCP_RANGE="192.168.1.101,192.168.1.109"
LXC_DHCP_MAX="9"
LXC_DHCP_CONFILE=""
LXC_DOMAIN=""

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 = 192.168.1.101/24
lxc.network.ipv4.gateway = 192.168.1.100
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
        address 192.168.1.101/24
        gateway 192.168.1.1

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.

cheers!

Marcelo

Did you find time since then? :wink:

1 Like

Whooo Markus… digging the grave :wink: this post is more then four years old…

and no, haven’t found some time, but all information is available in this thread I think :wink:

but to be honest I moved to openhab3 and proxmox a while ago…
are you really searching for howto get openhab2 running in lxc 1.0?

lxc is version 3 or maybe 4 now on debian when I remember this correctly…

but my answer to Marcelo’s question covers all I’ve done - if I remember that right…

you have to search for howto do things nowadays since the lxc/lxd versions changed.

But these are the steps:

  • install lxc/lxd
  • create the network bridge (like mentioned above)
  • create the container
  • login to the container
  • edit the network config in /etc/network/interfaces (inside the container)
  • install java
  • install openhab

hope that these infos get you started - sorry but I really don’t think I can do more for you :confused:

cheers
Dan

edit: found this tutorial maybe that helps…

Hi Dan, thank you! No, I’m not looking for openHAB 2 on LXC 1, I’m more interested in your container-splitting as you mentioned:

  • openhab2 (now 4)
  • mosquitto
  • influxdb
  • squeezeserver
  • and how they interact.

THX

Hi Markus,

you have to create different containers with fixed IPs, I’ve used debian 11 containers.
then simply install the services via apt inside the containers.

For further information on howto connect them, there are several tutorials and infos on the forum and the websites of the mentioned services. Sorry but I don’t have the time to write you a detailed tutorial.

In Openhab you have to configure the services with the external IP and port that point to the service you want to connect to. Some appllications need a user and password config too.

lxc / lxd tutorials on YT
openhab install on linux
mosquitto install debian 11
influxdb install debian 11
squeezeserver install debian 11

Just a side note… if you’re not familar with using linux console maybe it’s not the best idea to start with LXC. But if you’re interested in learning new things try to use the tutorials above you certainly learn a lot about linux and it’s console by trying out by yourself. But there is absolutely no all-in-one solution to get this running.