Bug since OH4: Why are the default.sitemap and *.things files not loaded on startup? (empty sitemap list)

Since upgrade from OH3 to OH4 (4.0.1 release), I get 404 Not found on the default sitemap, then on refresh I get “returned an empty sitemap list” (android app+web).
I tried restarting OH and rebooting, but it doesn’t help.

What does indeed work is to modify the sitemap when OH is running, then it suddenly loads and becomes available, until the next restart then it’s again unavailable. This is repeatable.

The 404 error on refresh generates this in the logs: Received HTTP GET request at 'https://192.168.2.130:8443/rest/' for the unknown sitemap 'default'.

Clues, how to fix this?

The logs contain this:

(I don’t know what ‘tmp_default.items’ is. I don’t see such a file in /items/)

2023-07-30 19:28:38.780 [INFO ] [org.openhab.core.Activator                        ] - Starting openHAB 4.0.1 (build Release Build)
2023-07-30 19:28:40.602 [INFO ] [org.openhab.core.internal.i18n.I18nProviderImpl   ] - Time zone set to 'Europe/Stockholm'.
2023-07-30 19:28:40.626 [INFO ] [org.openhab.core.internal.i18n.I18nProviderImpl   ] - Location set to XXX
2023-07-30 19:28:40.629 [INFO ] [org.openhab.core.internal.i18n.I18nProviderImpl   ] - Locale set to 'en_GB'.
2023-07-30 19:28:40.701 [WARN ] [org.apache.cxf.transport.servlet.ServletController] - Can't find the request for http://openhab:8080/rest/sitemaps/events/subscribe's Observer 
2023-07-30 19:28:43.045 [WARN ] [org.apache.cxf.transport.servlet.ServletController] - Can't find the request for http://openhab:8080/rest/events/states's Observer 
2023-07-30 19:28:48.662 [WARN ] [org.apache.cxf.transport.servlet.ServletController] - Can't find the request for http://openhab.local:8080/rest/items/ThreeDPrinter/state's Observer 
...
2023-07-30 19:28:55.947 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'default.items'
2023-07-30 19:28:56.169 [WARN ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Configuration model 'tmp_default.items' is either empty or cannot be parsed correctly!
2023-07-30 19:28:57.326 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'Network.items'
2023-07-30 19:28:57.426 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'Ir.items'
2023-07-30 19:29:04.564 [INFO ] [org.openhab.core.model.lsp.internal.ModelServer   ] - Started Language Server Protocol (LSP) service on port 5007
2023-07-30 19:29:05.090 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'Wakeup.rules'
2023-07-30 19:29:10.527 [WARN ] [org.apache.cxf.transport.servlet.ServletController] - Can't find the request for http://openhab:8080/rest/sitemaps/events/subscribe's Observer 
2023-07-30 19:29:10.533 [WARN ] [org.apache.cxf.transport.servlet.ServletController] - Can't find the request for http://openhab:8080/rest/sitemaps/events/subscribe's Observer 
2023-07-30 19:29:10.540 [WARN ] [org.apache.cxf.transport.servlet.ServletController] - Can't find the request for http://openhab:8080/rest/events/states/95ff3243-fbff-43fa-963f-d21a97468632's Observer 
...
2023-07-30 19:32:16.484 [INFO ] [nhab.core.io.rest.sitemap.internal.SitemapResource] - Received HTTP GET request at 'https://192.168.2.130:8443/rest/' for the unknown sitemap 'default'.
... (after modifying the default.sitemap)
2023-07-30 19:36:46.162 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'default.sitemap'

Additionally, the *.things files are also not loaded on startup. The device is uninitialized until i save the file with OH already running, then it loads:

2023-08-03 21:24:11.962 [INFO ] [enhab.core.model.core.internal.ModelRepositoryImpl] - Loading model 'tasmota.things'
2023-08-03 21:24:12.180 [INFO ] [openhab.event.ThingStatusInfoChangedEvent         ] - Thing 'mqtt:topic:tasmota:tasmota1' changed from UNINITIALIZED to INITIALIZING
2023-08-03 21:24:12.198 [INFO ] [openhab.event.ThingStatusInfoChangedEvent         ] - Thing 'mqtt:topic:tasmota:tasmota1' changed from INITIALIZING to ONLINE
1 Like

Are you running docker or a “real” server ?
Are your items/things in the local server storage ?
What OS?

The message about tmp_default.items is probably a hint.

This is Openhabian 4.0.1 release / Bullseye on RPi 4, a real server. The files are local in /etc/openhab.

I know ZRAM is in use. If it’s relevant, here is the config /etc/ztab, which I uncommented one line, because I need /persistence to live across any uncontrolled power losses.

# swap  alg     mem_limit       disk_size       swap_priority   page-cluster    swappiness
swap    lz4     200M            600M            75              0               90

# dir   alg     mem_limit       disk_size       target_dir              bind_dir
#dir     zstd    150M            375M            /var/lib/openhab/persistence    /persistence.bind

# log   alg     mem_limit       disk_size       target_dir              bind_dir                oldlog_dir
log     lzo     150M            500M            /var/log                /log.bind

So you are on a very common installation and many many users should encounter it. Very strange.

On a RPI3, all my config files load properly but I am not with openhabian, so we are not strictly in the same configuration.

In the unlikely event that someone else has the same issue, I built this script that triggers load of the files as a workaround.

An exec item runs it, triggered by a System startup event in Init.rules. That way, there is only about a minute of delay during startup before it’s back to normal.

/home/openhabian/nudge_files.sh

#!/bin/bash

process_files() {
    dir_path=$1
    if [ ! -d "$dir_path" ]; then
        echo "Directory $dir_path does not exist."
        return 1
    fi

    # Renames each file by appending .tmp and then renames it back to original
    for file in "$dir_path"/*; do
        echo "Processing file: $file"
        mv "$file" "$file.tmp"
        mv "$file.tmp" "${file}"
    done
}

process_files "/etc/openhab/sitemaps"
process_files "/etc/openhab/things"

misc/exec.whitelist

/home/openhabian/nudge_files.sh

Thing: exec:command:nudge-files
This is defined in the UI, since otherwise it might not load. Here is from the Code tab:

UID: exec:command:nudge-files
label: "Command: Nudge files"
thingTypeUID: exec:command
configuration:
  transform: REGEX((.*))
  interval: 0
  autorun: true
  command: /home/openhabian/nudge_files.sh
  timeout: 3

Then I linked the “Running” Switch to a new item Nudge_files in the GUI.

Init.rules

rule "Nudge files to force load sitemaps and things files"
when
    System started
then
    logWarn("Nudge files", "Nudging files to force load sitemaps and things files")
    Nudge_files.sendCommand(ON)
end
1 Like

Try clearing the cache and use the openhabian 2x menu option to fix permissions but other than that I wouldn’t know.
Enable maximum debug logging level on org.openhab then try finding anything in the log of the startup that gives you any other hint. If I was to guess I’d believe in some syntactically broken .thing file or maybe some inconsistency with UI vs files based config.

I had the exact same issue after upgrading from OH3 to OH4.0.1.
I use the docker version from docker hub and upgraded by changing the version in the docker-compose file. Can confirm that this lead to sitemaps and things files not being loaded on startup.

Clearing the cache solved the issue for good.

1 Like

Same issue here, run openhab in docker, not all things configuration are loaded after restarting. Have tried to delete cache and tmp in user folder without luck. I have 117 things and 50% chance it only loads 47 of them.

Ok that seems to have solved it on my RPi.
First of all, stopping OH and running sudo openhab-cli clean-cache did not help.
However, stopping OH, then running the following worked. Now all .sitemap and .things files load (update: sometimes).

sudo rm -rf /var/lib/openhab/cache/*
sudo rm -rf /var/lib/openhab/tmp/*

Isn’t openhab-cli clean-cache supposed to do just that?

In this old post there seemed to be a distinction between openHABian and Docker:

I’m not sure if this still applies, and why, but from your description it seems so.

I spoke to soon. I don’t get it. I just did a reboot, and the issue is back. Then did OH restart, and the sitemaps and things load again… Seems like a lottery, like @somy suggested.

Hi @wezzix : not sure if it works with docker installation but I’d like to try your workaround. Can you also post things and items configuration as well as Init.rules? One question: how do you make sure this thing is always loaded? Many thanks in advance!

I updated my post with the workaround. The thing is always loaded, because it’s defined in the GUI.

1 Like

Hi @wezzix : thanks for the workaround, I can confirm it also works with Docker installation. I’m still puzzled why this happens though, however in log I find zero trace.

Same problem here (Windows 10 on a miniPC).
I have realized that if the PC reboot, for example after an upgrade, sitemap doesn’t load, and also problems with some bindings.
Shuting down OpenHAB, clearing cache and tmp folders arrange the problem, but only until next reboot.

Ruben

same problem here… Update OH3.4.4 to OH4.0.2. After reboot the system sometimes the files are not loaded. with the workaround script does it work…

cleaning cache does not help :frowning:

I tried a little more, the “reload” script does not work for me. After a reboot I always have to restart the Openhab service after about 5 minutes. After that everything runs error free and the files are loaded completely.

is there any experience here how to fix this?

Have the same problem, running OH in Docker on a VM (openhab:4.0.3-alpine). Items and things files seem to load fine, but sitemaps stay empty. Is this a timing issue? Any idea which direction to look for solving this?

I’m having the same problem. Sitemap does not load and even worse, also the .persist files do not load. So all my persistance services get bloated with the data from all the items!

Cleaning the cache seems to work for one start, but when I reboot OH after that the files are not loaded again.

Any idea what could cause this problem?