sudo reboot via SSH - possible?
Closed this issue · 6 comments
Hello,
Can we use this plugin to send a standard SSH command to reboot the server that Homebridge runs on?
If so, how should it be formatted please? Many thanks.
Yes, you can; read about sudoedit (8)
to learn how
.
The tldr is:
- You want to be able to run
sudo reboot
without entering a password. - As it seems the homebridge installation takes the liberty to give some sudo permissions to the homebridge user, it's just required to append
, /usr/sbin/reboot
to the list of commands that can be executed by the user withNOPASSWD
found in the/etc/sudoers
file.
Hello again @laserscout
So I have added the line to sudoers as suggested:
homebridge ALL=(ALL) NOPASSWD:SETENV: /sbin/shutdown, /usr/bin/npm, /usr/sbin/reboot
and this to config.json:
"name": "reboot raspi",
"command": "sudo reboot",
"delay": "1000",
"execAfterDelay": false
Not rebooting so far.
Is there a way I need to format the command in this CMD trigger plugin to make it work?
Am I missing something obvious? Many thanks!
Could you run which reboot
so that we can verify the path to the reboot command?
And try to use its full path both in the sudoers file and in the switch configuration.
Yes, that fixed it. Many thanks @laserscout !
ran which reboot
and got /sbin/reboot
changed the line in sudoers accordingly and it started working
both commands: sudo /sbin/reboot
and just sudo reboot
work now.
Does it matter which command I use and will anything like for example apt updates change the sudoers file?
I ask since this functionality is mission critical as this raspi will run automations by itself in
an off-grid cabin during all winter.. ;)
Truly appreciate your help with this!
Nothing should change your addition in the sudoers file; except perhaps an upgrade of Homebridge itself, but that would be bad design. on homebridge's part.
On the other hand, might I suggest that you do not upgrade, or reboot, a mission critical device.
Thanks for your comments. I agree and will not (in fact can not) touch or update anything remotely.
However the Raspi controls a number of relays via wifi and very occasionally, it will not find one or more of the relays
after the wifi wakes up after a low power situation. A reboot of the raspi has fixed that every time so far.
So at least I now will have that option via your plugin in the home app which is immensely useful.
Many thanks again!