Openhab3 shutting down system

  • Platform information:
    • Hardware: Intel NUC
    • OS: Linux Debian 10
    • openHAB version: 3.3.0

I want to shutdown the NUC via a rule when a certain condition is met.
I looked at executiveCommandLine. I spent many hours looking at examples/formats but get no join trying to use it.
Openhab is running in Docker.

Is there another means I can try to shutdown the system without using EXEC binding?

Test for your condition on the outside of the container meaning on the host and shut it down from there.

There’s your problem. The whole point of containers like Docker is to isolate services from the host and from each other. If a container can just shut down the host, that container wouldn’t be providing much isolation.

I really get frustrated with users jumping on the Docker band wagon thinking all it is is a new way to install software. It’s much more than that and it’s much more involved than most people think.

It might be possible to run the container in privileged mode and run OH as user root (since the container doesn’t have sudo) and maybe it could work, though I doubt it. By design and philosophy a container shouldn’t be able to shutdown the host.

And if you are going to do that, you may as well not be running as an installed application because you have neutered pretty much all the protections that a container is supposed to provide.

As @Wolfgang_S hints at, you’re best off running something outside the container that perhaps OH can talk to (maybe send an MQTT message) to shutdown the host.

If at all. OH and its host should be running 24x7.
There’s very very few good reasons to automatically shutdown the OH host, and even less from inside OH. Most of the time this is broken by design, and I have not yet seen an attempt at this that does more good than harm.

Hi Rich.

Thank you for your reply

And so there we have it
as you stated
the intention of Docker is to have some form of isolation to the host

I didn’t think about this.
I didn’t go out and use Docker for the numerous benefits, but rather for the following:
I’ve been using OPENHAB2.5 for severals years now and mastered it well I’d like to think.
This been running on Openhabian with Pi 3/4.
However, what prompted the Docker thingy was that I had this NUC doing nothing and I pursued the new OPENHAB3.
This to me if something completely new and I had difficulty trying to create custom pages etc
not so intuitive.

So, by using the NUC and Docker, could I at any time run openhab2.5 and when time permitting, run openhab3.x and fiddle and then later revert back to openhab2.5

Ok, so above is the history.

I have moved in the meantime and so now reliant on little inverter/battery/solar.
Sometimes the battery too small to carry load of NUC and 2x USB file servers
and so for this purpose looking for solution to rather when the battery get to too low level, force the NUC to shutdown and not having a case of abrupt powerless to NUC.

Simple. Generate SSH key and SSH to the local host and execute your shutdown command. You may need to install OpenSSL/openssh into the docker, whatever is needed. Just do this using an init script for the docker.

Do a docker exec bash or sh to enter your docker environment and test the command/SSH first.

1 Like

I’d rather suggest you install a current Debian Linux and openHABian to your ‘bare metal’ NUC.
You can run that box in parallel to your ‘production’ RPi and link the 2 instances using the openhab remote binding.
Or install the NUC with OH 2.5, import your OH config, then move on to install OH3 on your RPi (assuming that’s your intented target HW).

Helpful for any sort of slow migration, and no Docker to needlessly complicate anything.

I beg to differ. In my opinion, Docker is wonderful. It keeps my system clean and makes upgrade / downgrade / backup / restore significantly simpler and easier. I would highly recommend it.

Caveat: I am running Docker on a Xeon server with 16GB - 64GB of RAM. I have never tried using Docker on a Raspberry Pi, so I don’t know if it’s even a good thing to do.

To run commands on your Docker host you can also add a cronjob that inspects a file or its contents and then if it exists conditionally run the command. Then you can mount the file (or its dir) in the Docker container and update it to communicate with the host without having to use SSH. :slight_smile:

On the host call the guest’s OH REST/API and make the decision to shutdown or not to shutdown.

But you understand what you are getting into, what containers are for and their purpose. Too many people do not and run into problems. I can’t tell you how many threads there are like this where a user didn’t understand what they were getting when using containers and wonder “Python is installed on my machine, why can’t executeCommandLine use it?” and the like.

Docker is great if you know what it is and how it’s supposed to be used. I use Docker to run just about everything myself. But if you think it’s just another way to install software, you’re going to have a hard time.

Containers require significantly more RAM than running bare metal. So on RPi 3 or below I strongly recommend against running OH in a container. On an RPi 4 with more RAM or other platforms, I’d only recommend using Docker if you spend a little bit of time learning about what it means to run something in a container.

Hi all.
Ok, I got it resolved.

Some feedback based on above remarks:

JimT : I started off with the idea of using a SSH function, but then I thought why if I was trying to SSH back into the same system, hence I started exploring the commandLine function.

wborn : Thanks, your idea of using cronjob is great
I actually went with this.
What I did, from a rule, when I get close to very low battery voltage, I would create a file using commandLine and “touch” bash command.
Then in cronjob, do I runa script to check if a file exists. This runs every minute, if file found, then scripts performs shutdown.

Just for final clarity:
I used the NUC and running it as NAS using OMV over Debian.
Due to the nice built-in DOCKER function, did I use this for all my DOCKER needs.
I now run about 5x DOCKER applications.

1 Like