Reboot on openHab 3

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.

Yes that worked.

Thank you @rpwong and @rlkoshak for your great help!

Maybe you can add to your guide adding the reboot as well:

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

I’ve done just that. I wanted to make sure it solved your problem before making the edit.

If I recall correctly, when Debian Buster came out, it was unclear which commands would work in both Buster and Jessie. I had written this note:

EDIT: The code below has been updated to delete /sbin/reboot and add /sbin/shutdown and /sbin/systemctl, which should enable this tutorial to work with both the Debian Jessie and the newest Debian Buster operating systems. However, I have not personally tested/confirmed that it works on Debian Buster. See the discussion comments for more information, and please provide feedback if it does/doesn’t work for you.

However, I didn’t update the rule to match. Now that we know sbin/reboot works in Buster, it’s easiest to just add that back.