Reboot on openHab 3

Platform information:

  • Hardware: Rasp pi 4
  • OS: openhabian 3.0.1

Hi
I Want to perform a daily reboot to the rasp pi as I did in OpenHab 2.5.
But it seems that the command not doing anything.
Any idea to solve it?

This is the rule

rule "Reboot openHAB"
when
    Item Flag_System received command "Reboot"
then
    logInfo("Flag_System", "Rebooting openHAB")
    executeCommandLine("sudo","reboot")
end

The log is writing successfully but no reboot.
Same with triggering the Flag_System via the sitemap.

Logs:

2021-03-31 16:40:58.114 [INFO ] [penhab.core.model.script.Flag_System] - Rebooting openHAB
2021-03-31 16:40:58.098 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Flag_System' received command Reboot
2021-03-31 16:40:58.110 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Flag_System' changed from NULL to Reboot

Thanks,
Inmar

Why would you think that would be needed? If it requires a daily reboot there is an issue that should be resolved before it causes further headache IMHO,

What have you tried?

How to ask a good question / Help Us Help You - Tutorials & Examples - openHAB Community

You right
In the past I did needed a daily reboot…
Now on OpenHab 3 I just want the option to reboot from remote.
So I have item in sitemap to change the Flag_System, the command is triggered but the reboot is not.

openHABian image is just Raspi OS which is just a flavor of Debian Linux.

This question may be better answered on a Raspberry Pi or Linux forum. Here we focus on the cross-platform openHAB system.

But I want to triggered the reboot from the “rules”, so it is related to OH, isn’t it?

Capture the output of the script and log it. I bet you will find an error there telling you exactly what’s wrong.

It’s most likely choking on the sudo part depending on the permissions you’ve set up. Depending on how you upgraded from 2.5 to 3 you might have lost whatever modifications you must have made to /etc/sudoers that permits the system to run that command with no password. But as Rich said, the best way to know for sure is get the output from the executeCommandLine and see.

I’m assuming you used the guide that I wrote awhile back, since the rule looks like it was copied from there.

As @JustinG notes, did you set up the sudo permissions again? I tested the guide steps when I moved to OH3, and everything works for me.

This is not permissions issue as I tested the permissions with by

sudo -u openhab /bin/bash
sudo shutdown -r

As @rpwong suggested and it worked.

I added print of the output:

    var String output = executeCommandLine("sudo","reboot")
    logInfo("Flag_System", "executeCommandLine output " + output)

And got “null”

Output:

2021-03-31 20:58:37.100 [INFO ] [penhab.core.model.script.Flag_System] - executeCommandLine output null

As documented, you must supply a Duration as the first argument to executeCommandLine in order to cause it to wait for the command to finish and capture the command’s output.

Thank you

I got this output:

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

That message comes up the first time a user runs a sudo command and requires you to press “y” to acknowledge the message. Probably the easiest thing to do is open a terminal and run

sudo -u openhab /bin/bash

to get a shell as user openhab. The run

sudo ls

That message will appear and present you with a y/n prompt. From that point the message will not appear again and your executeCommandLine should work.

I run it and it asks for the password of openhab.
What is the default password? I didnt changed it (it is not openhabian and not habopen)

It’s strange that the warning message didn’t come up when they ran the shutdown command from terminal.

As far as I’m aware, the openhab user does not have a password.

image

I dont know the password :frowning:

sudoers is missconfigured. It needs to be updated to allow the openhab user to execute sudo command without a password.

How do I do that?

If they followed the guide, would that be due to ls not being one of the specified commands?

# Allow openhab user to execute shutdown, poweroff, and systemctl commands
openhab   ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/poweroff, /sbin/systemctl

Yes, that’s a good point. Those three commands should work without password according to your guide.

However, note that reboot is not one of the commands.

Yep, that might be the problem. Looks like I changed the command in my system to:

executeCommandLine("sudo", "shutdown", "-r", "now")

But I didn’t update the guide accordingly.

@Inmar, can you test this command to see if it works?

Alternatively, you can just add /sbin/reboot to the sudoers file.