Beginner's guide to an openHABian reboot/shutdown switch

I don’t, you did. I didn’t say to debug rules, did I ?
I mean to debug the complete system, OH and its modules to interface with your device hardware that is.
Mostly that’s about identifying the OH component that has a memory leak (rules by themselves usually don’t have except under rare conditions because the Java runtime environment takes care of rules’ memory management).
Or about identifiying the event of whatsoever type that is the initial trigger to a chain reaction to finally result in symptoms that you are seeing.
And while not bugs of yours, they aren’t out of your control either. Tedious and time consuming to track down, yes. But not out of range.

It may be amongst my objectives to debug other people’s code, but I don’t have unlimited time to devote to something that already consumes far too much of it. And that hardly addresses possible problems in embedded software. In the meantime, I need automatic reboots.

In fact, it’s not your job to do the debugging :slight_smile: but regular frequent rebooting isn’t a solution at all.

In question of regular reboots… there are tons of Systems out there which don’t.

IIS was rebooted almost weekly, because it crashed… Apache2 didn’t.
It’s not unusual to have web servers that had no reboot since a year or so (only GNU/Linux or freeBSD, though), because the kernel can be patched online. The message reads “Please consider rebooting”, not “please reboot immediately”.

And if making updates or security fixes, the reboot is only to ensure that all software running is up to date, not because some parts crashed, and not to pre-empt a crash.

I’d well say that to debug your own system - not OH as software in general but the OS you deployed and the specific configuration, i.e. combination of bindings and 3rd party integrations you are using - to an extent such that you can identify a component to misbehave or at least the very specific conditions a problem happens under is any user’s very own job.
That’s including a description of what was tried and tested, documenting findings and to open a Github issue to make devs aware of it (if applicable) and support them with additional information and eventually testing.
Remember OH is OSS. Anyone to benefit from free software should be willing to give back as much as possible. That IMHO includes going that extra debugging mile yourself and not wait for or expect anyone else (dev, forum helper or anyone) to do that for you. Those volunteers have even less time to devote to any individual user’s problems rather than to their genuine job in the OH context.

1 Like

Thanks for clarifying, at that point I do agree. I’m no english native, so maybe I misunderstood:

:wink:

I didn’t sign a contract to debug other people’s code. I’ll look into it further if and when I have time, but in the meantime, I need automatic reboots.

Following this guide i can’t seem to get it to reboot.

    val results = executeCommandLine(Duration.ofSeconds(1),"reboot")
    logInfo("Flag_System", "executeCommandLine output " + results)

I get the following response and no reboot : executeCommandLine output Failed to set wall message, ignoring: Interactive authentication required.

I was getting a null response, but have removed the ‘sudo’ as that does not seem to be on the system. Sorry my linux knowledge is very limited. Running x86 openHABian on version 3.4.1. Any help would be greatly appreciated.

Thanks.

If it’s openHABian than sudo is definitely on the system and it is definitely required to run a command like reboot.

the error is saying “interactive authentication required” which means either sudo or reboot is asking a question and requiring you to answer it. The first time a user runs sudo there is a dialog that you need to accept by typing “yes” . Run the command from the command line, but remember that OH runs as user openhab, not your login user. So you first need to become that user.

sudo -u openhab
sudo reboot
1 Like

Maybe this is the issue, as when I type sudo it returns ‘command not found’. Looking over my notes from a few years back it looks like I installed Debian and then using git downloaded the openhabian-setup.sh to install etc.

Do you think installing sudo be the first step to get this working? thanks

It’s a catch-22. You can’t install anything unless you are root and you can’t run a command as root without sudo. So either your path is messed up and /usr/bin isn’t in your path, or sudo is not installed in which case you need to rebuild this machine from scratch. You can’t do anything meaningful without sudo.

It had to be there at some point because openHABian requires it to be there too, so the problem is likely your path which openHABian should have configured properly too. So over all this is a relatively sick machine.

1 Like

Ok thanks. Ahhh! don’t have time to rebuild this sick machine now and it runs a LOT of stuff in the house. So looks like a rebuild is one of them jobs when i have more time!

I’ll do an image backup for now and see if I can install/reconfigure sudo. Thanks for the info.

You can tell if it’s just a path problem by trying to run the full command using the full path.

/usr/bin/sudo

It had to be there at some point.

If it’s just a path problem, you probably just need to edit a config file. You’ll want to make sure that /usr/bin is in the PATH defined by profile.

And you probably want to use the full paths anyway in the executeCommandLine.

1 Like

I checked /usr/bin/sudo and it was not there. I have now installed sudo and added sudo back to the executeCommandLine and it’s working!

Not sure why sudo was not there, my linux knowledge is minimal but I’m sure it’s not something I would have removed. I normally log in as root, so could I have installed openHABian-setup.sh via the root account? Anyway, it’s working now, thanks for all your help.

How without sudo? This is a Debian OS?

Sudo is now installed after typing ‘apt get install sudo’.

Yes, running Debian 10 buster, then installed openhab with the openHABian sh. Was unable to use the openHABian image as it’s a x86 machine

I shouldn’t have let you do that. Your login user must be root or something. And if that’s the case, you are running as root therefore you don’t need to use sudo perhaps?

Ultimately, if you had to install sudo in the first place this is a very non-standard installation.configuration so it’s going to be very challenging to support in the future and on this forum.

1 Like

Ok thanks for your help. I’ll rebuild it when I get the time.

Hi there,

My openhab 4.0.3 is running on an raspberry pi 4.

i want to try to build a restart button with this howto.
It works fine, the items and the sitemap do what they have to to, so far.

But i have an problem with the execute command within the rule:

here is my rule which is fired:


rule "Restart OpenHab Server"
	when
		Item Restart_confirm received command
	then
		switch (receivedCommand) 
        {
			case ON :   
                { 
 //                 logInfo ("Restart", Restart Server - Sent from UI ", "\n") 
                    logInfo("System.rules", "Openhab Restart Server")
                    Restart_Shutdown.postUpdate(3) 
                    Restart_confirm.postUpdate(OFF) 
                    executeCommandLine("sudo", "reboot", 10000) 
                        
                        }
			case OFF : { Restart_Shutdown.postUpdate("3") }	
    		}
        
	end

and here is the error in the log:

Script execution of rule with UID 'System-1' failed: An error occurred during the script execution: array element type mismatch in System

in my oppinion the executeCommandLine is not working.
Has the syntax changed?

Can siómeone give me a hint?

Thanks in advance

Jan

Yes it has. Look for the post of @JimT in the Solutions section of this forum. He made a small tutorial about this command. Cannot look for it myself right now.

Since when ? Yes it has.

That is as easy as googling for: “site:openhab.org executecommandline”

First entry are points to Actions | openHAB
which also contains Actions | openHAB