Instructions for openHAB on FreeNAS?

Hi,

Is there any way (except Docker) for openhab3 on Freenas?

Frontail as a deamon. Who has a service startup script file working for iocage?

I haven’t started testing OH3 on my TrueNAS Core (aka FreeNAS) yet, but anyone who does succeed, please post here, it would be much appreciated.

I will just wait for the ports version, hope netchild sees that.

Hello ngalfas,

I try to get openHAB running on TrueNas too, but I’m struggling with the user rights or IDs … because I’m a newbe too. What I have discovered ist that the user- and group-ids inside of the jail are differend from the IDs of the NAS. So the NAS-IDs starts with 1000 and the openhab IDs in the jail are 235. So I tried to change them to become equal … well … but … I didn’t managed it.
In your post you said that this is a “tricky thing” … could you please explain, what I have to to, so solve this problem? If possible in a way that could be understand by a 6 years old child … :wink:

Thanks, best regards and … a happy new year
Stef

Hi Stef. This is a classic question for FreeNAS jails.
There is no need to invent the wheel for me to explain.
This is the BEST post expaining in detail this procedure.

This post is mandatory reading for future readers having similar issues and need to understand what needs to be done and WHY we need to do it.

In our case the easiest step is this

**SOLUTION 1 - USER WRITEABLE**
* Add a user in the FreeNAS WebUI with a matching UID as the plugin's default user.
* Change ownership of the data dataset/folders to the newly added user.

Since your jail user is openhab:openhab 235:235 you just need to create the same username and SET 235 manually on user and group creation pages on FreeNAS. First create the group and then the user.
Don’t leave the deafault 1000 user ID that FreeNAS suggests. You can change it right there! And you must.

So, delete your current TrueNAS openhab user (not the jail user!!!) and the TrueNAS openhab group.
Then you can create the TrueNAS openhab 235 group.
Then create the TrueNAS 235 openhab user.

And make the next steps. I will also edit my post above to be more informative.

Hello Nick, thanks for help. I first tried to change the openhab uid and group with the pw groupmod and usermod commandsbut with less success. So after reading your hint, I just deleted the openhab user and group within TrueNas an recreate them an the problems with the permissions disapear …

Now I copied my configuration (openhab_conf) from the PI to the TrueNas directories. Something happens … but not all. It seams the my hue-devices are connected, but my LCN-Devices are not available.

Is the the world not as easy as copiing the configuration-data to migrate from the Raspberry PI to TrueNas?

If someone has an idear, what I have to do to keep the LCN running gain?

Thanks and best regards
Stef

after such a copy, you must do the last step to be sure of file permissions

Do these inside the jail.

# chown -R openhab:openhab /usr/local/etc/openhab2
# chown -R openhab:openhab /var/log/openhab2
# chown -R openhab:openhab /var/db/openhab2/userdata
# chown -R openhab:openhab /var/run/openhab2
# chmod -R 755 /usr/local/etc/openhab2
# chmod -R 755 /var/log/openhab2
# chmod -R 755 /var/db/openhab2/userdata

I checked the permissions and ownership an everythink looks fine.

I have tried a second way, by making a backup of the PI-configuration with

> sudo openhab-cli backup
after that I copied the backup-file to the jail /var/db/openhab2/backup and changed the ownership top openhab:openhab. Than I start the jail. Finaly I tried to restore the backup with
> openhab-cli restore /var/db/openhab2/backup/<backup-file>.zip
but I got an error-message that told me that the command

openhab-cli

is unknown. Are there so many differences between openhabian and openhab for FreeBSD?

Another behavier I regconized is that the openHAB 2 Log Viewer will not be accessible. The workaround for this is to open the correspondig log-file from the shared directories. There I couldn’t see any message that shows that the LCN service will start.

Anyone any idears?
Thanks an best regards
Stef

I had an openhabian installation on a Pi so i did the migration as you. And my steps are these on my post #17.
There are many differences if you compare the openhabian and FreeBSD installation, mainly the directories used by the application.
That’s why i posted them.

I just copied the configuration folder to the new installation and installed all necessary bindings etc from scratch.

The log viewer is frontail. Yes this is not ‘supported’. We do it as a workaround manually but even i have to start it … manually :slight_smile:

I don’t know the LCN binding to help you for that. I hope your jail is ok with networking.

Oh, try this command on your jail.

# sysrc -f /etc/rc.conf openhab2_java_opts="-Djava.net.preferIPv4Stack=true"

It will help if your FreeNAS installation has IPv6 enabled…

Hello Nick,

the sysrc-line you posted is the same as I have inside my /etc/rc.conf-file.

It seems that I have the lcn-stuff runing, but it won’t run aout of the box by copying the lcn.cfg file. I had manualy initialize the binding by adding it as thing. After that I could the that openhab connects to the interface an the state changed to online … :wink:

Now I start thinking about the performance of the jails and the NAS-Hardware. Why? Well the messages in log appears much slower than on the rasperbery PI (3B). So my current NAS-hardware is an old AMD E350 processor (with 16GByte) witch should deliver more power than the PI … should. I think about upgrading the system, but I’m not shure whoe “huge” a TrueNAS-Hardware/processor should be, when the main functions of the NAS are only file-server and openHAB? Has anyone expirences in this direction? An other point is that the NAS should consume as little power as possible. Are there any idears?

Thanks and best regards
Stef

I tested a 12.1 iocage jail for manual OH3 installation.

I installed OpenJDK11

# pkg install openjdk11

I unzipped the OH3.1-snapshot to a newly created directory (ie. /usr/local/libexec/openhab3)

# chmod -R 755 /usr/local/libexec/openhab3
# cd /usr/local/libexec/openhab3
# ./start.sh

And that’s all, i can see it running.
What needs to be done is either a proper port or maybe a TrueNAS plugin scripted installation for user creation and service script.

Great news. There is a new port for FreeBSD for OH3.

This will be a different package name!
https://www.freshports.org/misc/openhab

1 Like

Frontail setup inside OH3 jail.

Here are my notes on setting up frontail on a fresh OH3 jail installation (12.2).

# pkg install npm
# npm i frontail -g
# pkg install wget
# wget -O /usr/local/lib/node_modules/frontail/preset/openhab.json https://raw.githubusercontent.com/openhab/openhabian/858c791101e4aa9dc348feed9a41247ed53c70f5/includes/frontail-preset.json 
# wget -O /usr/local/lib/node_modules/frontail/web/assets/styles/openhab.css https://raw.githubusercontent.com/openhab/openhabian/858c791101e4aa9dc348feed9a41247ed53c70f5/includes/frontail-theme.css
# touch /usr/local/etc/rc.d/frontail
# chmod 0755 /usr/local/etc/rc.d/frontail

The contents of file /usr/local/etc/rc.d/frontail

#!/bin/sh
# PROVIDE: frontail
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
# frontail_enable (bool): Set to NO by default. Set it to YES to enable frontail.
#

. /etc/rc.subr

name=frontail
rcvar=frontail_enable

load_rc_config $name
: ${frontail_enable:="NO"}
: ${frontail_python:="/usr/local/bin/python3.8"}

pidfile=${frontail_pidfile:-"/var/run/frontail.pid"}

export PATH="${PATH}:/usr/local/sbin:/usr/local/bin"
export PYTHON="${frontail_python}"

command=/usr/local/bin/frontail
command_args="-d --ui-highlight --ui-highlight-preset /usr/local/lib/node_modules/frontail/preset/openhab.json -t openhab -n 200 /var/log/openhab/openhab.log /var/log/openhab/events.log"

run_rc_command "$1"

Last command is

# sysrc frontail_enable=yes

When jail restarts it will load frontail on http://JAIL_IPADDRESS:9001


I am adding this here, because i can’t add another reply to this topic :slight_smile:

I was having a serious problem when i tried to upgrade from 3.1 → 3.2

After pkg upgrade a note on freshports page (FreshPorts -- misc/openhab: Vendor and technology agnostic open source smart-home software) said

These upgrade notes are taken from /usr/ports/UPDATING

  • 2021-06-28
    Affects: users of misc/openhab
    Author: netchild@FreeBSD.org
    Reason: You need to run
    sed -i -e ‘s:^karaf.framework.equinox=.:karaf.framework.equinox=mvn:org.eclipse.platform/org.eclipse.osgi/3.16.200: ; s:^karaf.framework.felix=.:karaf.framework.felix=mvn:org.apache.felix/org.apache.felix.framework/6.0.4:’ /var/db/openhab/userdata/etc/config.properties
    to update the version numbers of some components in a config file.

After that, when i tried to start OH service, i got this error

Launching the openHAB runtime…
Could not resolve mvn:org.eclipse.platform/org.eclipse.osgi/3.16.200

So something was wrong with that. Googling revealed that by now there was a newer version of that (ports - FreeBSD ports tree)

-libexec/openhab/runtime/system/org/eclipse/platform/org.eclipse.osgi/3.16.200/org.eclipse.osgi-3.16.200.jar
+libexec/openhab/runtime/system/org/eclipse/platform/org.eclipse.osgi/3.16.300/org.eclipse.osgi-3.16.300.jar

So, the correct command is

sed -i -e 's:^karaf.framework.equinox=.*:karaf.framework.equinox=mvn\:org.eclipse.platform/org.eclipse.osgi/3.16.300: ; s:^karaf.framework.felix=.*:karaf.framework.felix=mvn\:org.apache.felix/org.apache.felix.framework/6.0.4:' /var/db/openhab/userdata/etc/config.properties

And this makes things right, service runs just fine for OH 3.2


Note after upgrading to OH3.3

Today (October 2022) i upgraded my iocage instance to FreeBSD release 13.1

I also upgraded OH 3.2 → 3.3

I noticed the OH service was not starting.
Error was

[org.apache.karaf.main.Main] - Could not launch framework java.lang.RuntimeException: Could not resolve mvn:org.eclipse.platform/org.eclipse.osgi/3.16.300

Although i searched a lot, seems nobody else has reported something like this. Anyway, i checked the availble version of this
https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.osgi

I tried all available versions after the last i used (3.16.300) and i got lucky to find the new one to be 3.17.200

So, for FreeBSD 13.1 and OH3.3 the correct command after installation is

sed -i -e ‘s:^karaf.framework.equinox=.:karaf.framework.equinox=mvn:org.eclipse.platform/org.eclipse.osgi/3.17.200: ; s:^karaf.framework.felix=.:karaf.framework.felix=mvn:org.apache.felix/org.apache.felix.framework/6.0.4:’ /var/db/openhab/userdata/etc/config.properties

After that is works fine.

2 Likes

Hello,

Where openhab is storing changes that was made in the webinterface?
I run Freebsd 13.1, openhab 3.3 in a jail.
I cannot find any change under
/usr/local/etc/openhab or
/var/db/openhab/userdata or
/usr/local/libexec/openhab
After reboot all changes are lost.
I guess there is a permission problem to write the configs?

Thanks a lot.

Thanks for this. I was able to fix my FreeBSD installation with the help of the details in your post.

1 Like

Hello,

FreeBSD OPENHAB backup script requires 2 variables.

OPENHAB_USERDATA and OPENHAB_CONF
For sure userdata can be found under /var/db/openhab/userdata .
But is conf to find under /var/db/openhab/userdata/config ? I mean its the same path.

Is there anybody who knows? Thanks a lot.

Do you have a running openhab instance on that OS ?
Then login to the karaf console and do:

env | grep -i openhab

Beside other entries you should see something like ( example output is from a Pi installation ) :

String          openhab.conf    /etc/openhab
String          openhab.userdata /var/lib/openhab

Hallo Wolfgang,

In a fresh FreeBSD Installation the variables are not set.
But I found the path to set:

 setenv OPENHAB_USERDATA /var/db/openhab/userdata
 setenv OPENHAB_CONF /usr/local/etc/openhab

setenv because Iam using teh csh.

With bash it would be

   export OPENHAB_USERDATA=/var/db/openhab/userdata
   export OPENHAB_CONF=/usr/local/etc/openhab

Then the backup script is running fine.