Clean cache and tmp from UI

Hello,

I have made a file (sudo /etc/openhab2/scripts/clearTmpCacheRestart.sh) and made it executable.

Here is code

#!/bin/bash

sudo service openhab2 stop

sudo rm -rf /var/lib/openhab2/cache/*

sudo rm -rf /var/lib/openhab2/tmp/*

If i start like a button from openhab (exec binding) then only this first string “sudo service openhab2 stop” executed and OH stops. Cache and tmp does not clean.

If I start this file from console it works fine!

What have i done wrong?

Thanks a lot!

When you run systemctl stop openhab2 then OH is stopped and nothing OH related will work until you start it again.

If you want to use a script for cleaning the cache then execute it as different user (some one other than openhab) and place it in a different directory (somewhere out side of OH).

BTW: you can clean the cache with sudo openhab-cli clean-cache does the same as the lines posted above. Like before, make sure you stop OH first.:wink:

I must start it also from another user? Sorry for dummy questions, i’m not so good in linux(((
If so, then maybe there already one user in Openhabian? Or maybe another easier way to clean cache and tmp from ui?

Thanks a lot!

You cannot clean the cache and temp whilst openHAB is running. So doing from the UI makes no sense.

For example make a cron to clean in next minute and then stop or something like this…
The must be a solution)))

There isn’t. openHAB MUST be stopped BEFORE cleaning the cache.

Of course it must be, i have noting against it, therefore i wrote - For example make a cron to clean in next minute and then stop or something like this…

Or another way - can it be made a cleaning of cache after reboot and before OH started?

BZW: after cleaning of cache OH works more smoothly and faster. Maybe it would good, if cleaning will be made automatically every XX days?

You could write a shell script doing this for you.
Stop OH
Clean cache and temp
Start OH

And trigger the script with cron every once in a while

I have, it is in first message)))
Here is a question how can i start it. With native OH cron (i suppose in this case will be the same as i start it from ui) or with linux cron fron another user?

That’s the one
The other can’t work, because OH will be stopped and the job with it.

understood! Thanks a lot!
So i need to create new one or there is already one, that i can use (if so witch one)?
I use OH in raspberry pi3 plus, OH 2.4 with preisntalled image from OH site.

You’ll have to get the correct rights to execute the script
and for cron scheduling see:

1 Like

As many others I have the same issue with sendMail in OpenHab. It is version 3.2.0 in my case.

2022-01-29 16:56:57.574 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-1' failed: 'sendMail' is not a member of 'org.openhab.core.thing.binding.ThingActions'; line 47, column 5, length 81 in test

In my case I made a lot of restarts both with and without cleaning the cache but did not get it working. At the same time the actual thing is green and show number of unread emails which I consider as thing is working.
Luckily I have integration with HomeAssitant which have much more stable IMAP integration. HA’s IMAP integration can also parse the emails content.
As for OH - developers, please take a look at this issue. Obviously it is some bug in the binding if so many people has troubles.