How to set the userdata to a different folder?

Hi,

I want to move the userdata folder from the internal eMMC to the external USB SSD. This should be an easy task, but I am unable to figure this out where to specify the OpenHAB folders.

I am using the openhab3 Arch Linux package from the AUR. There is a file /etc/default/openhab3 where I can set custom java options. But anything I put there is not being applied to the final karaf command.

For example I tried:

EXTRA_JAVA_OPTS="-Dopenhab.userdata=/srv/storage/openhab3 -Dkaraf.base=/srv/storage/openhab3 -Dkaraf.data=/srv/storage/openhab3"

and the full command line is still with all the defaults:

/usr/lib/jvm/java-11-openjdk/bin/java -XX:-UsePerfData -Dopenhab.home=/usr/share/openhab3 -Dopenhab.conf=/etc/openhab3 -Dopenhab.runtime=/usr/share/openhab3/runtime -Dopenhab.userdata=/var/lib/openhab3 -Dopenhab.logdir=/var/log/openhab3 -Dfelix.cm.dir=/var/lib/openhab3/config -Djava.library.path=/var/lib/openhab3/tmp/lib -Djetty.host=0.0.0.0 -Djetty.http.compliance=RFC2616 -Dnashorn.args=--no-deprecation-warning -Dorg.apache.cxf.osgi.http.transport.disable=true -Dorg.ops4j.pax.web.listening.addresses=0.0.0.0 -Dorg.osgi.service.http.port=8080 -Dorg.osgi.service.http.port.secure=8443 -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Dopenhab.userdata=/srv/storage/openhab3 -Dkaraf.base=/srv/storage/openhab3 -Dkaraf.data=/srv/storage/openhab3 --add-reads=java.xml=java.logging --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED --patch-module java.base=/usr/share/openhab3/runtime/lib/endorsed/org.apache.karaf.specs.locator-4.3.4.jar --patch-module java.xml=/usr/share/openhab3/runtime/lib/endorsed/org.apache.karaf.specs.java.xml-4.3.4.jar --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.naming/javax.naming.spi=ALL-UNNAMED --add-opens java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-exports=java.base/sun.net.www.protocol.file=ALL-UNNAMED --add-exports=java.base/sun.net.www.protocol.ftp=ALL-UNNAMED --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED --add-exports=java.base/sun.net.www.content.text=ALL-UNNAMED --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED --add-exports=java.rmi/sun.rmi.registry=ALL-UNNAMED --add-exports=java.security.sasl/com.sun.security.sasl=ALL-UNNAMED -Dkaraf.instances=/var/lib/openhab3/tmp/instances -Dkaraf.home=/usr/share/openhab3/runtime -Dkaraf.base=/var/lib/openhab3 -Dkaraf.data=/var/lib/openhab3 -Dkaraf.etc=/var/lib/openhab3/etc -Dkaraf.log=/var/log/openhab3 -Dkaraf.restart.jvm.supported=true -Djava.io.tmpdir=/var/lib/openhab3/tmp -Djava.util.logging.config.file=/var/lib/openhab3/etc/java.util.logging.properties -Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true -classpath /usr/share/openhab3/runtime/lib/boot/org.apache.karaf.diagnostic.boot-4.3.4.jar:/usr/share/openhab3/runtime/lib/boot/org.apache.karaf.jaas.boot-4.3.4.jar:/usr/share/openhab3/runtime/lib/boot/org.apache.karaf.main-4.3.4.jar:/usr/share/openhab3/runtime/lib/boot/org.apache.karaf.specs.activator-4.3.4.jar:/usr/share/openhab3/runtime/lib/boot/osgi.core-7.0.0.jar:/usr/share/openhab3/runtime/lib/jdk9plus/istack-commons-runtime-3.0.10.jar:/usr/share/openhab3/runtime/lib/jdk9plus/jakarta.xml.bind-api-2.3.3.jar:/usr/share/openhab3/runtime/lib/jdk9plus/javax.annotation-api-1.3.2.jar:/usr/share/openhab3/runtime/lib/jdk9plus/jaxb-runtime-2.3.3.jar:/usr/share/openhab3/runtime/lib/jdk9plus/org.apache.servicemix.specs.activation-api-1.2.1-1.2.1_3.jar:/usr/share/openhab3/runtime/lib/jdk9plus/txw2-2.3.3.jar org.apache.karaf.main.Main

How can I set a different path for the userdata?

  • Platform information:
    • Hardware: OdroidC4 / 4GB / eMMC / USB-mSATA-SSD
    • OS: arch linux
    • Java Runtime Environment: OpenJDK Java 11 (1.0.13.u8-1)
    • openHAB version: 3.2.0-1

Did you try to set

OPENHAB_USERDATA=/Your/Path/To/openhab3

in the default file of your distribution ( /etc/default/openhab3 ) ?

There is a bug in the AUR package. The file /etc/default/openhab3 is passed as EnvronmentFile option in the openhab3.service systemd file, but this is not passed to the karaf_wrapper.sh later on. So the /etc/default/openhab3 is currently useless.

[Unit]
Description=The openHAB 3 Home Automation Bus Solution
Documentation=http://docs.openhab.org
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=openhab3
Group=openhab3
WorkingDirectory=/usr/share/openhab3
EnvironmentFile=/etc/default/openhab3
ExecStart=/usr/share/openhab3/karaf_wrapper.sh server
ExecStop=/usr/share/openhab3/karaf_wrapper.sh stop
Restart=on-failure

[Install]
WantedBy=multi-user.target

I found the PKGBUILD patches the defaults in /usr/share/openhab3/runtime/bin/oh_dir_layout and this is the result:

#!/bin/sh

# DIRNAME is the directory of karaf, setenv, etc.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH

export OPENHAB_HOME=`cd "$DIRNAME/../.."; pwd`

if [ -z ${OPENHAB_CONF} ]; then
    export OPENHAB_CONF="/etc/openhab3"
fi

if [ -z ${OPENHAB_RUNTIME} ]; then
    export OPENHAB_RUNTIME="${OPENHAB_HOME}/runtime"
fi

if [ -z ${OPENHAB_USERDATA} ]; then
    export OPENHAB_USERDATA="/var/lib/openhab3"
fi

if [ -z ${OPENHAB_LOGDIR} ]; then
    export OPENHAB_LOGDIR="/var/log/openhab3"
fi

if [ -z ${OPENHAB_BACKUPS} ]; then
    export OPENHAB_BACKUPS="${OPENHAB_HOME}/backups"
fi

# Make sure the tmp folder exists as Karaf requires it
if [ ! -d "${OPENHAB_USERDATA}/tmp" ]; then
    mkdir "${OPENHAB_USERDATA}/tmp"
fi

export KARAF_DATA="${OPENHAB_USERDATA}"
export KARAF_BASE="${OPENHAB_USERDATA}"
export KARAF_ETC="${OPENHAB_USERDATA}/etc"

So now I need to reverse the patch and build a new package and/or set the environment variables like I need.

Why not do it the easy way and create a symbolic link from your USB to the userdata folder used by OH by default?

1 Like

A symbolic link would also work, but not satisfying …

I was completely mistaken how the systemd environment variables work. They do get passed into the process environment started by ExecStart. So it is really as simple as defining OPENHAB_USERDATA=/srv/storage/openhab3 in /etc/default/openhab3 and it works. This is also how it is done in openhabian. Everything can be controlled with the environment variables.

I remember reading something different in the systemd.service manual page and also read some posts where it was explained that the variables do not get passed. Anyway, I am glad it works that easy …