Multiple restarts after cleaning the cache

Hi guys,

It’s a general thing about the OpenHAB 2 system. I use it on an ubuntu virtual machine on multiple Raspberry Pi’s so it’s always the same.

If you have caching problems you could do following for restarting the MQTT-Broker:

sudo systemctl stop mosquitto.service
# Delete the mosquitto.db containing all the stored message data in the persistence. By default, located in /var/lib/mosquitto/mosquitto.db
sudo rm /var/lib/mosquitto/mosquitto.db
# Restart the mosquitto service
sudo systemctl start mosquitto.service
sudo systemctl restart mosquitto.service

And following for restarting OH:

sudo systemctl stop openhab2.service
# if openhabian is installed
sudo openhab-cli clean-cache
# if openhabian is not installed
sudo rm -rf /var/lib/openhab2/cache/*
sudo rm -rf /var/lib/openhab2/tmp/*
sudo systemctl start openhab2.service

Well, i think it’s not really new for you. But that’s of course not the point I want to discuss.

Most of you will find out that this does not work reliably. Sometimes you will miss the sitemaps and sometimes you will miss the items and so on. It sucks. The solution is to restart the openhab2.service again and again and again and again.

It would be nice if there was a way to determine via bash script if the items, sitemaps etc. could be loaded. If not, then you repeat the restart until everything could be loaded. So a bash script that cleans the cache would be very helpful.

I have currently solved it by restarting all my OpenHAB systems and then adding a delay of 15 seconds and restarting one more time. In most cases, it seems that two restarts are needed to fix the caching problem.

Would be happy if there are good suggestions here on how to solve this more elegantly and reliably.

If I address not only OpenHAB but also MQTT, then from experience that there the cache can also be full. Therefore I give another useful tip: If the cache should be full, also sometimes changes are not taken over. Say in /etc/openhab2/services/mqtt-eventbus.config the configuration may be correct, but a change in /var/lib/openhab2/config/org/openhab/mqtt-eventbus.config was not saved. As a result, the MQTT configuration is no longer correct. There may be commandPublishTopic="", commandSubscribeTopic="" or statePublishTopic="" or stateSubscribeTopic="" or other errors that would lead to an infinite loop because. This would fill the cache over and over again, not only slowing the system down insanely and making it barely debuggable. One must first find that then conifugarion changes were not effective. A frequent restart then also brings nothing more.

Back to topic: A more reliable solution could be helpful. Thanks in advance.

The best solution is not to restart openHAB.
The second best solution is not to destroy the cache.
It’s not really clear why you are doing this? “Cache Full”?

Because OH will repeat my last command. It’s in the cache.

You should make your delay longer. If you wait long enough a single restart seems to be sufficient.

Also, clearing the cache is something that is done far too frequently. It is only useful when seeing errors concerning the installation/removal of add-ons and apparent corruption in an add-on.

I agree, what does “cache can be full” mean? Are you using ZRAM with openHABian and running out of file space? That’s the only thing I can think of that this could possibly mean. And in that case the solution is to give the ZRAM file systems more space.

Do you mean mqtt-eventbus.cfg? There are not config files in the conf folder. Also note that that is a 1.x binding configuration.

Assuming you are not running out of disk space, this is a different problem entirely and clearing the cache is like swinging an ax to open an envelope. It’ll work but is likely to do way more damage than necessary.

The fix here is to figure out why you are running out of disk space. And if you are not running out of disk space, “filling up the cache” is not a thing. It’s not the cause of your problems.

Frankly, there is already a more reliable solution. OH 3 doesn’t have these problems (unless your root cause if running out of disk space in which case that’s your more reliable solution).

That’s not what the cache does. All that’s in the cache is the jar/kar files and other such downloaded stuff that openHAB and it’s bindings have dowloaded to install on your OH instance. The cache has nothing to do with config files or processing commands or anything like that. Open up the folder and take a look around. You’ll see this is the case.

But, when you clear the cache you

  • free up some disk space
  • force openHAB to download and reinstall all the add-ons