[SOLVED] Shutting down Raspberry Pi which runs OpenHAB 2

Well, even if your pi won’t start anymore (let’s say, because you bricked one of the essential files), there is no need to start from scratch. You could use another GNU/Linux system (life CD, vm, another computer…), then mount the filesystem (very easy, because it’s on a SDcard :slight_smile: ) and repair the damage. Of course, you have to know, what you’ve damaged… :wink:

Thanks Udo, i have made a backup of my SD.

I’m really struggling to get this working :frowning: Please can someone nudge me in the right direction?

I’ve read the docs regarding the fact that the user “openhab” needs to be able to run the shutdown comamand in order for this to work. I feel this is where I’m going wrong. As the following does not work:

sudo -u openhab reboot

Here are the steps I have taken which have been unsuccessful:

  1. Log into my Pi and add the following to /etc/sudoers.d/common_users
openhab ALL = NOPASSWD: /sbin/reboot, /sbin/shutdown
  1. Add the Exec Binding Add RegEx Transformation Service

  2. Added Thing in Paper UI:

2018-04-05%2014_03_51-Paper%20UI

.items

Switch Reboot "Reboot" { channel="exec:command:6dba3517:run" }

.sitemap

Switch item=Reboot mappings=[OFF="Off", ON="On"]

Any help would be much appreciated thanks.

Yes, this will not work, as it’s incorrect. :slight_smile:
You have to use

sudo -u openhab sudo reboot

This is: "execute the following commmand as user openhab: sudo reboot"
When using sudo the first time (as user openhab), this will result in a message, to respect the privacy of all users. as an alternative, you can change to a bash with login openhab:

sudo su openhab -s /bin/bash

As result you are logged in as user openhab, even if there is no password set and no login shell defined.
No you can perform

sudo reboot

and you will get the message about privacy:

sudo ls

Wir gehen davon aus, dass der lokale Systemadministrator Ihnen die
Regeln erklärt hat.  Normalerweise läuft es auf drei Regeln hinaus:

    #1) Respektieren Sie die Privatsphäre anderer.
    #2) Denken Sie nach, bevor Sie tippen.
    #3) Mit großer Macht kommt große Verantwortung.

[sudo] Passwort für openhab:

(sorry, only localized message here…)

Be aware that the path to reboot is /sbin/reboot, not /bin/reboot

1 Like

Woohoo, it is working now. I noticed as I left it at a 60 second interval by mistake and my Pi kept restarting. :grin:

Thanks for your help :+1:

Thanks for this. Working like a charm, sortoff. Problem is that after I used it, it keeps on shutting down.

From what I could see it seems the switch is initialized from Null to On thus triggering the script again.

I’ve added autoupdate=“false” to the switch item but this doesn’t seem to have helped.

Will initializing the switch within the startup rules prevent this?

Did you persist the item?

I haven’t added anything in a persistence file.

Added the entry in things, items and sitemap as per your suggestion. Cut and pasted them. Just changed the bin to sbin

Are you using exec1 or exec2?

Looks like

binding-exec - 2.4.0
Exec Binding
This is the binding to execute arbitrary shell commands
Author: Karel Goderis

Hi Curtis,
I have the same issues with restarting loop.
How you changed the interval?

@Udo_Hartmann i have made the same mistake again

openhabian is not anymore a sudoer

su root do not work because i do not have the password. blank password do not work

Please help me

i am so upset. twice the same error. last time

See post 9 above. [SOLVED] Shutting down Raspberry Pi which runs OpenHAB 2

Mount the SD card on some other Linux system and repair the sudoer’s file or add openhabian back to the sudoer group.

Only make changes to the sudoer’s files using visudo.

Thanks, i do not have mac or linux computer

Could i make it from an android phone?

is there a way to mount it on windows?

Then it might be easiest to just start over from scratch and restore a backup.

You probably can’t do anything from an Android phone. You might be able to install a Linux VM on your Windows Machine using VirtualBox or the like. You could create a Live CD or USB drive and boot your Windows machine into Linux as another option.

Finally, ParagonSoft makes an EXT2 file system reader that will let Windows read the SD card, but you really need access to visudo to edit the sudoers file so I don’t recommend that approach.

Thanks a lot you are saving me a lot of time
An idea maybe, Can I plug my SD in the usb to my aiy voice kit raspberry?

Yes but only if you have a USB adapter for the SD card. You can’t remove the existing SD card that the AIY uses to boot and put the broken on in.

sure,

it’s working . i can edit it.

but i have a lost the default sudoers file of the openhabian image

You will need to research what a sudoer’s file is supposed to look like. Then copy the suoder’s file from your AIY. That will probably be enough. If not, you need to add an entry for user openhabian.

i have followed your advice. i restored a back up

thank you