[SOLVED] Openhab Docker or not?

Indeed, and systemd needs to run as PID 1 else systemctl spits errors. But I think I’m getting there.

Container != Virtual Machine. That Debian image has just enough of the OS to run a single process in the foreground. That is how containers are mean to be used: one process per container.

It’s actually a lot of work and not at all easy to get a container to run more than one process because a lot of the supporting system daemons like systems are not available.

1 Like

Thank you for your suggestions. As the RPi 4 runs hotter than I would like, I spun up a VM to dockerize Openhab and other stuff.

It is taking longer than I expected, mainly because I would like to decouple Openhab and python, so need to rework all my exec binding.

You could look into LXC or LXD containers. Those give you more of a ‘VM like’ experience and still give you the quick startup times of a container because they share the kernel of the host. You can create snapshots as well so you can easily revert back.

Many moons ago I was using Xen on Ubuntu Server 6.06 LTS (because it supported PCI forwarding) and later KVM to run VMs. I then learned about and switched to LXC containers because they are much lighter than VMs. Then Docker came along.
I plan to reinstall my server next week (Ubuntu Server 14.04 LTS is EOL since April) and intend to use a number of LXD containers and run Docker, Kubernetes and OKD (OpenShift) in them. Not sure yet if that is going to work. If not, I can always spin up a KVM VM as a last resort.

Anyway, this is all a bit off-topic of course.

It would be nice to read about your setup and experience you made, when you are done.
A Setup bases on LXD/LXC, Docker, Kubernetes and OKD sounds interesting.

If you got the time maybe create a post about this setup :slight_smile:

Why decouple? Use HABApp and get the best of both worlds!

Perhaps some of us want things more closely coupled with OH like Jython. I know the differences of Python 2 vs 3 but it adds complexity to depend on an external, independently developed application layer.

1 Like

You do have the option of bringing them even closer together using Jython. Look into JSR223 Jython rules.

1 Like

That’s why I am asking him “why decouple” He clearly has the use case of different python scripts (probably with python libraries) he can’t run with JSR223. So I am suggesting to keep it closely coupled.

t.b.h JSR223 is way more complicated. I don’t like to hijack this thread so it would be nice if you come over to the HABApp thread and we’ll get a discussion going?

With the helper libraries it is no more complicated than Rules DSL any more.

1 Like

Thank you everyone for your ideas.

I have looked into this option before, but since openhab was not in a container before, it was much simpler to use CPython. With containers, Jython seems to be a good option and will definitely look into that again.

Have you had a chance to try it? If I pip install a package, would it store in userdata folder inside openhab, or it’s in a separate place (like /usr/local/jypthon etc)?

The scripts I wrote will most likely work on Jython. The reason I choose Cpython was “just in case” the library I want to use don’t exist on Jython. I do like the idea that everything in the container runs Java underneath, heck I even converted some of my python scripts to Java classes in order to dockerize my setup. The only concerns now is Jython 3.X seems to be in development for a while.

That’s a very interesting idea. I have something similar in my setup where I have a wsgi site interacting with Openhab rest API. Let me explore this more.

One limitation is you can’t pip install libraries to make them available. You can however download the libraries and put them in the conf/automation/lib/python folder.

I think most of us are eagerly awaiting when we can move to a newer Java where GraalVM will be available and we don’t have to rely on Jython coming out with a 3 version.

Interesting. Is that a limitation for using Jython in Openhab? or Jython can’t use pip at all? I read somewhere that Jython does support ensurepip, or at the very least, you can easysetup pip for Jython.

Yes, this would be awesome!

Thanks,
Joe

For simple use cases this might be true. But if you try rule inheritance, scheduling function calls, rule creation on the fly, rule parametrization through yml files etc. it gets ugly rather quickly.
Maybe you can try it out and we’ll discuss your experiences ? I’d be really happy about it.

To get back to topic:
@goodfore:
It’s super easy to spin up an HABApp container alongside an Openhab container.
Maybe give it a try - migrating your python script should be effortless.
Use a python IDE and you get syntax highlighting. You might even like it :wink:

That is luckily not correct :slight_smile: You can use pip when you use the full jython-installer.jar.

Assuming Jython is installed in /openhab/conf/automation/jython you can exec bash in the running container.

Then go to and execute /openhab/conf/automation/jython/bin/jython -m pip install <package(s) to install>

For example to install the python-dateutil package:

root@marcel-desktop:/openhab/conf/automation/jython/Lib/site-packages# /openhab/conf/automation/jython/bin/jython -m pip install python-dateutil
Downloading/unpacking python-dateutil
  Downloading python_dateutil-2.8.0-py2.py3-none-any.whl (226kB): 226kB downloaded
Downloading/unpacking six>=1.5 (from python-dateutil)
  Downloading six-1.12.0-py2.py3-none-any.whl
Installing collected packages: python-dateutil, six
Successfully installed python-dateutil six
Cleaning up...
root@marcel-desktop:/openhab/conf/automation/jython/Lib/site-packages# ls
 certifi		       dateutil		    _markerlib		     python_dateutil-2.8.0.dist-info   setuptools			  six.py
 certifi-2019.6.16.dist-info   easy_install.py	    pip			     README			       setuptools-14.3.2.dev0.dist-info   urllib3
 chardet		       idna		    pip-1.6.dev1.dist-info   requests			      'six$py.class'			  urllib3-1.25.3.dist-info
 chardet-3.0.4.dist-info       idna-2.8.dist-info   pkg_resources	     requests-2.22.0.dist-info	       six-1.12.0.dist-info
root@marcel-desktop:/openhab/conf/automation/jython/Lib/site-packages# 

I haven’t tried actually using them, but the installation of packages using pip seems to work fine.

2 Likes

Interesting. Is that a limitation for using Jython in Openhab? or Jython can’t use pip at all? I read somewhere that Jython does support ensurepip, or at the very least, you can easysetup pip for Jython.

The answer is beyond my expertise.

Spaceman_Spiff:

For simple use cases this might be true. But if you try rule inheritance, scheduling function calls, rule creation on the fly, rule parametrization through yml files etc. it gets ugly rather quickly.
Maybe you can try it out and we’ll discuss your experiences ? I’d be really happy about it.

Well, none of those things are possible in Rules DSL and none of those are things I would expect even the typical OH user to ever do. So it’s kind of a false comparison.

  • rule inheritance: for the “average” user moving from Rules DSL, they would be expected to use Rule Templates rather than inheritance. Inheritance as a concept is already too complicated for the average user.
  • scheduling function calls: Creating timers using OH Timers or Python timers is equally as easy as is done in Rules DSL
  • rule creation on the fly: I’ve not done this myself yet but all indications are this too is very easy. And you can disable Rules programatically as well so instead of needing an (if some Item is of state X) in a Rule, you can just disable the Rule.
  • Rules DSL also works in Python IDEs, I use VSCode with the most popular Python extension.

Spaceman_Spiff:

Maybe you can try it out and we’ll discuss your experiences ? I’d be really happy about it.

I’m unlikely to try it out because my main focus is on supporting new and non-technical users. As such, even my experiments with JSR223 Jython Rules is a stepping stone to UI created Rules (i.e. Rules that get stored in the JSONDB). When the new UIs get released with the graphical rule builder this is how most new/non-technical users will be developing their rules so that is where I need to have expertise and knowledge. I can and will continue to tell people about your HABApp but for me it would be a dead end.

marcel_erkel:

but the installation of packages using pip seems to work fine.

Cool. I remember seeing Scott post a reply to a thread that it wasn’t possible. I’ve not the experience or expertise to verify that and I may be completely miss remembering the post.

I’m with you - HABApp is not for non-technical users.
It’s an automation solution for users who want to write rules in python (3).

Ah - is there also something with auto-complete for functions and type hints?
This was not possible when I was playing around with jsr223. I had to inspect every java object through a rule and then make calls accordingly.

That’s a shame but I understand. :slight_smile:

I believe so but honestly, I’ve lately been doing most of my coding over ssh using vim because the VNC server on my desktop VM isn’t working right now. I’m pretty sure that, for example, when I type in DateTime.now(). I get all the Joda DateTime methods in a list.

It doesn’t have Item name awareness though which is a big difference from Rules DSL.

I thought I’d step in here for a moment and be the naysayer…

I find Docker really hard to deal with. Everything is at least one level removed from where it’s running, and I’ve found building and maintaining containers to be a huge hassle. It’s like building a ship in a bottle instead of just making a model.

At work, we have huge servers, and we need to move things from server to server quickly. Docker helps there, and is worth both the minor overhead (compared to our huge servers) and the effort of maintaining the containers.

For OH, especially on a dedicated system like an RPI, I don’t see it as worth the effort. It just makes everything harder and makes diagnosing problems that much more difficult.

I would suggest you spend time more on a build tool like Ansible, and on having good backups than struggling to get OH to run in Docker.

But, others here seem to find it easy and manageable, so maybe I’m a luddite or missing some docker-savvy and doing things the hard way. It wouldn’t be the first time. :slight_smile:

But for a small, dedicated host, I don’t see how Docker is much of a win.

User Ansible to manage your Docker images and containers. I personally find Dinner really ready to deal with but with one exception, I only use unmodified official images. The one I build myself, Calibre, is because there is no official container for that.

Now I will say, there are programs that I wouldn’t touch on Docker at home (I’m looking at you Alfresco) but for everything else is been really simple and I don’t run into any conflicts on ports, libraries, files, or anything like that.

Most of the things you site are mostly problems for people building images. And that use indeed more challenging. But once built, it’s super easy for the users of there image, and that’s part of the point. Let the experts deal with all the new of dealing with dependencies and such, just give be an image that works.

And then, part of what I think Markus is after, you have something you can much more easily user in automated testing and to give developers a single Bob l boob that just works.

I agree, but how many people, even those running on RPis are truly running on a dedicated host. Almost everyone is running a host of services in that host.