Issue with JSR223 Jython scripting

I’m running OpenHAB 2.2 stable on Ubuntu on a (mini) PC. I recently decided to port my existing DSL rules to JSR223 scripting. First I decided I wanted to use ECMAscript since I’m more familiar with Javascript and since it’s enabled by default but I quickly realized there are more sample scripts in Jython/Python and apparently more users favor Python over ECMAscript. Having said that, I’m running into an issue where after I restart OpenHAB, some libraries/modules apparently haven’t been loaded yet, causing errors in the startup sequence op OpenHAB. It also prevents my scripts/rules from being initialized altogether after a fresh restart. Whenever I force a reload of a certain script by ‘touching’ the script file, all goes well…

This is the error I keep getting during the startup of OpenHAB.

Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/test.py': NameError: name 'SimpleRule' is not defined in <script> at line number 4

I created a very simple test script that has no other dependencies other than the ‘RuleSimple’ and ‘RuleSupport’ preset for testing purposes.

scriptExtension.importPreset("RuleSimple")
scriptExtension.importPreset("RuleSupport")

class MyRule(SimpleRule):
    def __init__(self):
        self.triggers = [
             Trigger("MyTrigger", "core.ItemStateUpdateTrigger", 
                    Configuration({ "itemName": "TestString1"}))
        ]
        
    def execute(self, module, input):
        events.postUpdate("TestString2", "some data")

automationManager.addRule(MyRule())

I’ve seen a few users posting similar problems to this community, but I haven’t seen a single solution been posted yet. I even tried to upgrade to the OpenHAB-2.3 nightly build but aside from the fact that it did not resolve this particular issue, it also introduced some errors with my existing DSL rule scripts so I was quick to revert back to 2.2 stable.

Can anyone shed some light on this issue for me or help me find a workaround? A workaround (so it seems) would be to run a shell script that ‘touches’ the .py script files after startup to force a refresh, but this seems like a rarther dirty solution to me…

Thanks!

I might have found the solution myself…

On the GitHub page (https://github.com/eclipse/smarthome/wiki/Scripted-Rule-Support) is says this…

From http://www.jython.org/downloads.html download jython-standalone-x.y.z.jar to the directory: /usr/share/openhab2/runtime/lib/boot/.
Restart openhab2: service openhab2 restart

I did not use the standalone version (but rather the installed version). I could also remove the changes I made to /etc/default/openhab2 config since placing the .jar in the runtime/lib/boot directory made OpenHAB pickup the .jar file automatically.

Too soon… my problem still persists unfortunately…

Edit: I did found out that if I disable all my existing DSL rules/scripts that were also loading, this problem didn’t occur as much as before suggesting that it has to do with loading certain modules in the background simultaneously. As I mentiond in my previous post - a temporary workaround would be to run the ‘rules_refresh.sh’ script after the ‘System started’ event fires to refresh al existing rules and scripts and force a reload.

I am having the same issues trying to install the ideAlarm (https://github.com/OH-Jython-Scripters/ideAlarm). I have tried the standalone version as well as the installer with the same results.
Any help & thoughts would be greatly appreciated