1. Intro
This tutorial is based on an apt-get installation of OH2 in Linux and is for advanced/manual configuration of OpenHab 2 and for troubleshooting purposes. The normal way of working with OpenHab 2 configurations is via the Paper UI and the config files in /etc/openhab2.
2. Basics
OpenHab 2 is based on the Eclipse SmartHome framework and is fully written in Java. It uses the Apache Karaf (a lightweight and modular container, powered by OSGi) to store many information, including all the configurations (items, bindings, sitemaps, etc).
Karaf remembers the configs for the bindings that you installed and started by storing them in your userdata directory (/var/lib/openhab2
) in a mapDB database format (?) and/or the /usr/share/openhab2/runtime/karaf/etc
directory.
3. File Based Configurations
In some cases, you may need to modify the configuration files within your /etc/openhab2/
folder in order to manually work with bindings, items, things, etc. These config files are acting as read-only and OpenHab 2 copies the info into it’s internal database/directories and you can edit them there via various UIs. You may not be able to access the stored info directly with text editing tools.
Example:
In order to configure the KNX Binding, you need to modify the file: /etc/openhab2/services/knx.cfg
After you store the configuration in the knx.cfg file, OpenHab will copy the info and maintain it in its internal mapDB/dirs.
Any changes that you may do later on in the knx.cfg file will be re-read and the info will be again stored in the OH2 mapDB/dirs, overwriting the existing parameters.
You could actually delete the /etc/openhab2/services/knx.cfg
after OH2 has loaded up the KNX Binding configuration and all would work fine since OH2 will read the Binding config from it’s already stored info. This is not recommended since you should keep your config files in place for future reference.
4. Working with OH2 stored configs
In order to display, change, and/or delete already stored configurations within the internal OH2 mapDB/Dirs, you can use the Apache Karaf Console:
sudo ssh openhab@localhost -p 8101
with password: habopen
You will be presented with the Karaf console prompt:
__ _____ ____
____ ____ ___ ____ / / / / | / __ )
/ __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __ |
/ /_/ / /_/ / __/ / / / __ / ___ |/ /_/ /
\____/ .___/\___/_/ /_/_/ /_/_/ |_/_____/
/_/ 2.0.0-SNAPSHOT
Build #558
Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.
openhab>
Some useful Karaf console commands:
a) Show all existing configs: config:list
b) Show a specific config for a binding: config:list "(service.pid=org.openhab.knx)"
c) Show all bindings: feature:list
d) Show the versions of installed bindings: bundle:list
e) Delete an existing config: config:delete org.openhab.knx
f) Delete only one property from an existing config: config:property-delete -p org.openhab.knx localIp
g) Set a property for an existing config: config:property-set -p org.openhab.knx localIp 172.16.13.101
Warning: Changes made in the configs via the Karaf console will not be recorded in your /etc/openhab2/ config files and these files will be re-read by OH2 at startup, overwriting the OH2 stored config parameters.
5. Backup & Restore of your OH2 configs
5.1 Backup
systemctl stop openhab2
TIMESTAMP=`date +%Y%m%d_%H%M%S`;
mkdir /backup
mkdir /backup/openhab2-backup-$TIMESTAMP
cp -arv /etc/openhab2 /backup/openhab2-backup-$TIMESTAMP/conf
cp -arv /var/lib/openhab2 /backup/openhab2-backup-$TIMESTAMP/userdata
systemctl start openhab2
5.2 Restore
systemctl stop openhab2
cp -arv /backup/openhab2-backup-YYYMMDD_HHMMSS/conf/* /etc/openhab2/
cp -arv /backup/openhab2-backup-YYYMMDD_HHMMSS/userdata/* /var/lib/openhab2/
systemctl start openhab2
BR,
Dim
References:
i) Recommended way to backup/restore OH2 configurations and things?
ii) What is effect of -Dosgi.clean in karaf?
iii) Migration from OH 1.x to OH 2 Tutorial
iv) http://karaf.apache.org/manual/latest/#_shell_console_basics