I’m still having issues with rules being loaded/running twice. Cron jobs execute twice in many cases, which seems to be because the rules are loaded twice - I can see this when I edit/save a rules file, as the model is refreshed twice in the logs.
It’s been suggested this is because of errors in a rules file, or particular formatting characters, but I still have the problem if I delete all the content in the rule, e.g. :
// Refresh CPU utilisation every 30 mins, after 59 seconds
rule "Update CPU utilisation"
when
Time cron "50 0/30 * * * ?"
then
var String output1
var String output2
var String output3
end
Is this a common problem, or something weird with my system? I’m using the release version of OH2.0, but I’ve had this ever since I started with OH2 four months ago.
What editor are you using? I encountered one case with a user where their editor was saving a swap file with the same extension as the file (e.g. it would save a .myrulesfile.rules as you edit myrulesfile.rules). Thus you end up with two copies of your rules file being loaded and active at the same time (I don’t remember the editor that did this, it wasn’t vi, vim, pico, or nano).
I edit with Atom. It looks like when it saves a file, openHAB registers it having been edited twice (although there is only one file created). Nano doesn’t do this, and neither does geany. It looks like others have experienced this with Atom in the past.
Surprising if this would cause rules to run twice, given that it just seems to be registered by openHAB as two saves of the same file. But if you think the issues are linked then perhaps I have to stop using Atom, which would be a shame…
I bet that Atom uses a swap file that ends in .rules as opposed to other editors that change the extension (e.g. vim uses .swp). If that is the case then what is happening is openHAB is actually loading two different files, your “real” .rules file and the temporary file created by Atom. But even if it is triggering two file events for every save what might be happening is that OH starts to read the file then gets the second save causing it to load the same file in another thread. As a result the file ends up being loaded twice which probably results in two copies of the rules living in OH.
How irritating - I really like Atom. I tried Sublime Text 3 instead. That had exactly the same problem, but there’s an option to “save via writing to an alternate file, then change its name to the original file”. I switched this to “true” and Sublime Text seems to work fine with OH.
I’m not sure if this is related to me saving the files through CIFS/Samba…
When I edited the file with ‘nano’ I also got the problem, but seems to only happen once after I’ve done a save in the eclipse editor. The second attempt with nano produced only one load.
(Running a simple “touch zwave.items” only made it load once regardless)…
Something that may be related is that my files all live on a NAS and are NFS mounted on my Rpi OH2 server. If I edit these files on a machine other than the OH2 server it doesn’t pick up that they’ve changed and reload them, despite the fact that the last modified timestamp has been updated.
I didn’t have this issue when I was running OH1 so something has changed in the way it detects config file changes.
Indeed something changed. Before OH 1 would poll for updates. That lead to a number of problems. OH 2 uses file events I think to detect changes to files and I suspect NFS and CIFS mounted volumes do not provide these events.
I’ve noticed something similar when trying to tail -f a log file from another machine through a CIFS mount. It won’t follow on the other machine.
This is odd. If you are on the SNAPSHOT, file an issue on the eclipse smarthome repo. If not, you can try upgrading to the snapshot and see if it is still a problem.