Reboot on openHab 3

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.

The problem was that the zram implementation in openHABian didn’t work correctly when one used reboot as opposed to shutdown -r. That has since been resolved so both commands work correctly with zram now.

1 Like

Well I wouldn’t call it misconfigured. It’s the default, and for good reasons so.
Under normal operating conditions, the openhab user should not need to have access to system level privileges.
The OP shouldn’t be booting his server anyway.

Misconfigured for what the OP wants to accomplish.

Hello there! I’m moving to OH3 and at this point i’m copying rules from my OH2 environment. I have 2 rules (working on OH2) that launch a reboot of service/shoutdown the servoce of OH2,but won’t work on OH3.
My command is: sudo systemctl restart openhab.service
I’ve followed above steps to update sudoers etc,but won’t work.
Btw, raspi reboot/shutdown are working correctly. I run rule on openhabian image and the command has been executed with executeCommandLine.
Last,if i run from ssh the command sudo systemctl restart openhwb.service, it shows me an info and then restart the service correctly without any other input.
Any help from any guru will be appreciated a lot.

Thanks!

Show your rules to get more help.
You adapted your executeCommandLine syntax from OH2 to the syntax of OH3 ?
In case it does not work get the returned string from executeCommandLine and print it to loginfo to check what the output message / error message is.

thx i’ve solved it adding a new path to sudoers file :wink:

1 Like